Skip to content

Commit 63c2f1b

Browse files
Potential fix for code scanning alert no. 3: Incomplete URL substring sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent c8afb1c commit 63c2f1b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/layer2-static/detectors/plugin-manifest.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ function isDigestPinnedImage(value: string): boolean {
571571
return /@sha256:[0-9a-f]{64}$/iu.test(value.trim());
572572
}
573573

574+
function isHostOrSubdomain(hostname: string, baseDomain: string): boolean {
575+
const host = hostname.toLowerCase();
576+
const base = baseDomain.toLowerCase();
577+
return host === base || host.endsWith("." + base);
578+
}
579+
574580
function isLikelyGitSource(value: string, parsedUrl: URL | null): boolean {
575581
const trimmed = value.trim().toLowerCase();
576582
if (trimmed.startsWith("git+")) {
@@ -583,9 +589,9 @@ function isLikelyGitSource(value: string, parsedUrl: URL | null): boolean {
583589
return false;
584590
}
585591
return (
586-
parsedUrl.hostname.endsWith("github.com") ||
587-
parsedUrl.hostname.endsWith("gitlab.com") ||
588-
parsedUrl.hostname.endsWith("bitbucket.org")
592+
isHostOrSubdomain(parsedUrl.hostname, "github.com") ||
593+
isHostOrSubdomain(parsedUrl.hostname, "gitlab.com") ||
594+
isHostOrSubdomain(parsedUrl.hostname, "bitbucket.org")
589595
);
590596
}
591597

0 commit comments

Comments
 (0)