Potential fix for code scanning alert no. 2: DOM text reinterpreted as HTML#3
Merged
Potential fix for code scanning alert no. 2: DOM text reinterpreted as HTML#3
Conversation
…s 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/ajm19826/ProxyTest/security/code-scanning/2
In general, the fix is to validate and constrain user-controlled URLs before using them in security-sensitive contexts such as
href. Specifically, only allow a whitelist of safe schemes (e.g.,http:andhttps:), and reject or ignore anything else. This ensures that even if a user typesjavascript:alert(1), that value will never end up inactiveTab.urland thus never in thehref.The best minimal fix here is to tighten the URL handling in
addNewTab(and optionally the initialurlquery param) so that onlyhttpandhttpsURLs can produce aProxyTab. We can do this without changing existing functionality for legitimate URLs: we still normalize inputs that don’t start withhttpby prefixinghttps://, parse withnew URL, and then add a scheme check that returns early if the protocol is nothttp:orhttps:. BecauseactiveTab.urlis always taken from theProxyTab.urlfield, this single validation point ensures that thehref={activeTab.url}sink only ever receives safe values.Concretely:
addNewTab, afterconst fullUrl = ...andnew URL(fullUrl);, add a protocol check likeif (!/^https?:$/i.test(parsed.protocol)) return;.useEffectthat handles theurlsearch parameter, since that also flows into aProxyTab.URLclass that is already in use.These changes are all within
client/pages/Proxy.tsxand only touch the URL creation logic, leaving rendering, tab management, and UI behaviour unchanged for valid http/https URLs.Suggested fixes powered by Copilot Autofix. Review carefully before merging.