Skip to content

Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization#10

Closed
jonathansantilli wants to merge 1 commit into
mainfrom
alert-autofix-2
Closed

Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization#10
jonathansantilli wants to merge 1 commit into
mainfrom
alert-autofix-2

Conversation

@jonathansantilli
Copy link
Copy Markdown
Owner

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 like evilgitlab.com or gitlab.com.evil.com from matching.

For this specific code, the intent of isLikelyGitSource is to detect URLs that point to common Git hosting providers. We can replace the three endsWith checks 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 above isLikelyGitSource, and then call it three times. This preserves existing functionality (detects base domains and subdomains such as api.github.com) while eliminating the possibility that foo-github.com or github.com.evil.net incorrectly match.

Concretely:

  • Add a hasHostSuffix(hostname: string, baseDomain: string): boolean helper that:
    • Lowercases both inputs.
    • Returns true if hostname === baseDomain or hostname.endsWith("." + baseDomain).
  • Change the return expression in isLikelyGitSource (lines 585–589) to call this helper instead of directly using endsWith("...").

No external libraries are needed; the URL type and string operations are already available.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jonathansantilli jonathansantilli marked this pull request as ready for review March 7, 2026 20:40
@jonathansantilli jonathansantilli deleted the alert-autofix-2 branch March 7, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant