Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#177
Closed
neatudarius wants to merge 4 commits into
Closed
Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#177neatudarius wants to merge 4 commits into
neatudarius wants to merge 4 commits into
Conversation
… sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
✅ Deploy Preview for bemanproject ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Resolve conflicts by taking main for pre-commit and HomepageFeatures (already fixed in #179). Retain CodeQL fix: parse URLs and allowlist YouTube hostnames instead of substring matching. Co-authored-by: Cursor <cursoragent@cursor.com>
2 tasks
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/bemanproject/website/security/code-scanning/1
In general, to fix incomplete URL substring sanitization, you should parse the URL with a standard URL parser and then compare the
hostname(orhost) against an explicit set of allowed domains (and, if needed, their well‑defined subdomain patterns), instead of checking for substrings anywhere in the URL string.For this specific code, the best fix without changing intended functionality is to (1) parse the
urlargument using the built‑inURLclass, (2) inspecthostnameto see whether it is one of the known YouTube hosts (youtube.com,www.youtube.com,m.youtube.com,youtu.be, etc.), and (3) only returntruefromshouldTransformwhen the hostname matches one of these allowed values. We should also ensure thatgetHTMLderives thevideoIdbased on the same hostname logic, so that it correctly handles bothyoutube.comandyoutu.beURLs and is robust against malformed inputs. To avoid breaking behavior, we will preserve the existing embed generation but make theshouldTransformcheck more precise. Concretely, insidesrc/components/youtube-transformer.js, we will replace the substring logic inshouldTransformwith atry { new URL(url) } catchblock, extracthostname, and compare it against anallowedHostsarray. We will also align theyoutu.becheck ingetHTMLto use parsed hostname (urlObj.hostname === "youtu.be") rather than the previous naiveincludescheck, ensuring consistency. No extra imports are needed asURLis part of the Node.js / browser standard library.Suggested fixes powered by Copilot Autofix. Review carefully before merging.