Skip to content

Commit 9ab294a

Browse files
test: enhance SIZE_REPORTER_SCRIPT validation
- Use regex to ensure postMessage uses specific origin instead of substring check - Avoid CodeQL false positive for incomplete URL substring sanitization
1 parent 867500b commit 9ab294a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/unit/api/test_proxy.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Tests URL validation, security checks, and HTML injection.
55
"""
66

7+
import re
78
from unittest.mock import AsyncMock, patch
89

910
import httpx
@@ -256,7 +257,13 @@ class TestSizeReporterScript:
256257
def test_script_uses_specific_origin(self):
257258
"""Script should use specific origin, not wildcard."""
258259
assert "'*'" not in SIZE_REPORTER_SCRIPT
259-
assert "https://pyplots.ai" in SIZE_REPORTER_SCRIPT
260+
# Use regex to verify postMessage uses specific origin, not substring check
261+
# This avoids CodeQL's "incomplete URL substring sanitization" false positive
262+
# Pattern matches: }, 'https://pyplots.ai') - the end of the postMessage call
263+
pattern = r"\},\s*'https://pyplots\.ai'\)"
264+
assert re.search(pattern, SIZE_REPORTER_SCRIPT), (
265+
"postMessage must use specific origin 'https://pyplots.ai', not '*'"
266+
)
260267

261268
def test_script_sends_pyplots_size_message(self):
262269
"""Script should send pyplots-size message type."""

0 commit comments

Comments
 (0)