Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization#10
Closed
jonathansantilli wants to merge 1 commit into
Closed
Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization#10jonathansantilli wants to merge 1 commit into
jonathansantilli wants to merge 1 commit into
Conversation
… 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/jonathansantilli/codegate/security/code-scanning/2
In general, to avoid incomplete URL substring sanitization when checking for allowed domains, you must compare the parsed hostname against an explicit, well-formed whitelist. To allow a base domain and any of its subdomains, you should accept either an exact match to the base domain, or a hostname that ends with
.+ base domain. This prevents unwanted hosts likeevilgitlab.comorgitlab.com.evil.comfrom matching.For this specific code, the intent of
isLikelyGitSourceis to detect URLs that point to common Git hosting providers. We can replace the threeendsWithchecks with a small helper that tests for “hostname is exactly X or has X as a suffix after a dot”. Since we must not change imports or assume extra context, we can implement this helper locally in the same file, just aboveisLikelyGitSource, and then call it three times. This preserves existing functionality (detects base domains and subdomains such asapi.github.com) while eliminating the possibility thatfoo-github.comorgithub.com.evil.netincorrectly match.Concretely:
hasHostSuffix(hostname: string, baseDomain: string): booleanhelper that:trueifhostname === baseDomainorhostname.endsWith("." + baseDomain).returnexpression inisLikelyGitSource(lines 585–589) to call this helper instead of directly usingendsWith("...").No external libraries are needed; the
URLtype and string operations are already available.Suggested fixes powered by Copilot Autofix. Review carefully before merging.