Potential fix for code scanning alert no. 124: Incomplete URL substring sanitization#402
Merged
Potential fix for code scanning alert no. 124: Incomplete URL substring sanitization#402
Conversation
…ng sanitization 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/Fasttify/fasttify/security/code-scanning/124
In general, the problem should be fixed by parsing the URL and inspecting its
hostname(and optionally itspathname) instead of checking substrings on the raw URL string. For host checks, usenew URL(oldLink.href).hostnameand compare it exactly against a list of allowed or disallowed hostnames. For path checks, examineurl.pathnamerather than the full href. This eliminates cases where the keyword appears in query strings, fragments, or as part of another domain.In this file, the best targeted fix is:
oldLink.hrefinto aURLobject at the beginning of thelinks.forEachcallback.oldLink.href.includes('fonts.googleapis.com')andoldLink.href.includes('fonts.gstatic.com')checks with hostname comparisons on thatURLobject.!oldLink.href.includes('/stores/')with a check on thepathnamefield of the parsed URL (!url.pathname.includes('/stores/')), which maintains existing behavior while avoiding substring checks on the full URL string.pathfilter, which can still reasonably operate on the href as a string (it’s a dev-only path filter; if desired, it could also be made more precise by usingurl.pathname, but that’s not necessary to address the flagged issue).No new libraries are needed; the built-in
URLclass is already available in the browser environment. The change is localized withinhotSwapCSSinsrc/app/[store]/src/components/DevAutoReloadScript.tsx.Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Note
Low Risk
Dev-only change that tightens URL parsing/filtering for stylesheet hot-reload; low risk but could prevent some CSS links from being hot-swapped if URLs are malformed or unexpected.
Overview
Tightens the dev HMR CSS hot-swap logic in
DevAutoReloadScriptby parsing each stylesheethrefwithURLand filtering via exacthostnameandpathnamechecks instead of substring matching.Adds a safe fallback to skip hot-swapping when a stylesheet URL can’t be parsed, addressing the “incomplete URL substring sanitization” code scanning finding while keeping the rest of the reload behavior the same.
Written by Cursor Bugbot for commit 38c3977. This will update automatically on new commits. Configure here.