Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#11
Closed
jonathansantilli wants to merge 1 commit into
Closed
Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#11jonathansantilli 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/1
In general, to fix incomplete URL host checks, avoid substring or suffix checks like
.includes()or.endsWith()on the raw hostname. Instead, compare the parsed hostname either for exact equality with a set of allowed hosts, or implement an explicit rule that only allows the target domain and its subdomains, where the subdomain constraint is enforced by checking that the hostname is either exactly the domain or ends with"." + domain.In this specific case, we want to retain the logic that considers well-known Git hosting domains as “likely git sources” but avoid accepting arbitrary hosts that merely end with e.g.
"github.com". The best approach is to replace each.endsWith("<domain>")check with a helper that returns true only if the hostname is exactly<domain>or is a subdomain of it (i.e.,host === "github.com"orhost.endsWith(".github.com")). This still treatsapi.github.cometc. as Git sources, but rejectsgithub.com.evil.comandnotgithub.com. We can implement this as a small local helper function insideisLikelyGitSourceso as not to affect other code and avoid changing imports.Concretely:
isLikelyGitSource, introduce ahostlocal derived fromparsedUrl.hostname.toLowerCase().host === "github.com" || host.endsWith(".github.com"), and similarly for the other domains.parsedUrl.hostname.endsWith("...")expressions with these stricter checks.No additional methods or external libraries are needed; all changes stay within
src/layer2-static/detectors/plugin-manifest.tsand within the shown snippet.Suggested fixes powered by Copilot Autofix. Review carefully before merging.