Skip to content

Commit 9a983ba

Browse files
Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
1 parent 8e1ddc6 commit 9a983ba

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

apps/web/src/utils/setupTurnstileCSPErrorFilter.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ export function setupTurnstileCSPErrorFilter(): void {
1616
/**
1717
* Checks if an error string or URI is related to Turnstile CSP violations
1818
*/
19+
function hasAllowedTurnstileHost(text: string): boolean {
20+
const allowedHosts = new Set(['challenges.cloudflare.com'])
21+
22+
// Split free-form text into tokens and parse URL-like values safely.
23+
const tokens = text.split(/\s+/)
24+
for (const token of tokens) {
25+
try {
26+
const parsed = new URL(token)
27+
if (allowedHosts.has(parsed.hostname.toLowerCase())) {
28+
return true
29+
}
30+
} catch {
31+
// Ignore non-URL tokens.
32+
}
33+
}
34+
35+
return false
36+
}
37+
1938
function isTurnstileCSPError(text: string): boolean {
2039
const lowerText = text.toLowerCase()
2140

@@ -29,7 +48,7 @@ export function setupTurnstileCSPErrorFilter(): void {
2948

3049
// Check for Turnstile-related identifiers
3150
const hasTurnstileIdentifier =
32-
lowerText.includes('challenges.cloudflare.com') ||
51+
hasAllowedTurnstileHost(text) ||
3352
lowerText.includes('cdn-cgi/challenge-platform') ||
3453
lowerText.includes('turnstile') ||
3554
lowerText.includes('normal?lang=auto') ||

0 commit comments

Comments
 (0)