Potential fix for code scanning alert no. 12: DOM text reinterpreted as HTML #272
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/UseInterstellar/Interstellar-Astro/security/code-scanning/12
To fully address this vulnerability, the user-supplied URL (flowing from search input and settings) must be validated and sanitized such that only safe schemes like
https://orhttp://are allowed before being rendered as an iframesrc. There are two robust ways to do this:Validate user input as soon as it's received and before storing it into storage.
Before assigning to the iframe's
srcprop, ensure it's a valid HTTP(S) URL.The best place is before passing to
encodeProxyUrlin Browser.tsx (i.e., sanitize everytab.urlbefore passing to that function), so that even data from bookmarks or other flows cannot inject a malicious URL into the iframe. This check will ensure only valid HTTP(S) URLs (orabout:blank) are used.Implementation steps:
sanitizeUrlfunction (insrc/lib/tabs.ts), ensuring the input is "about:blank" or a safe HTTP(S) URL, or else default to "about:blank".sanitizeUrlin Browser.tsx, wrapping thetab.urlvalue on line 453 before passing it toencodeProxyUrl.URLconstructor for parsing, or a regex matching HTTP(S) URLs.Suggested fixes powered by Copilot Autofix. Review carefully before merging.