Potential fix for code scanning alert no. 44: DOM text reinterpreted as HTML#1668
Merged
Potential fix for code scanning alert no. 44: DOM text reinterpreted as HTML#1668
Conversation
…as HTML Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/E2OpenPlugins/e2openplugin-OpenWebif/security/code-scanning/44
To fix the issue, we need to make sure that the value extracted from
data-target(or, if not present, fromhref) is only ever interpreted as a CSS selector, and never as HTML. The most robust way is to usedocument.querySelectoror jQuery'sfind()method on a safe ancestor, as these only accept valid selectors and do not interpret HTML. Alternatively, we can validate thatselectoris a valid CSS selector (e.g., it starts with#or.and does not contain suspicious characters).In the context of Bootstrap, the safest fix is to ensure that the code never passes potentially unsafe user input directly to
$(). Instead, we should only treatselectoras a selector, not as HTML, and if it's invalid or missing, gracefully fall back. In practice, we can usedocument.querySelectoror restrict the selector to IDs by checking that it starts with#, or we can use$.findondocumentto ensure only a selector is used.The main change is in the
getParentfunction: replacevar $parent = selector && $(selector)with something likevar $parent = selector && $(document).find(selector), which avoids HTML interpretation.Suggested fixes powered by Copilot Autofix. Review carefully before merging.