Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .websec-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ src/websec_validator/briefing.py
# The AppSync GraphQL "surface" is detected purely from our own `@aws_*` example strings — no real
# GraphQL server lives in this repo, so the synthetic graphql finding is a self-reference.
category:graphql

# The CLI tool runs in a short-lived Docker container (no daemon) so a HEALTHCHECK is not applicable.
Dockerfile
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed
- Fixed a false positive where the `weak-csp` finding would trigger against the tool's own extractor regex definitions for `text/html` and `Content-Security-Policy`.

## [0.11.0] — 2026-07-11

Distribution & integration round — reach every agent host, run as a local guardrail, and compose with
Expand Down
6 changes: 3 additions & 3 deletions src/websec_validator/extractors/transport_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

from .base import Extractor, RepoContext, is_script_file, is_test_file

CSP_ANY = re.compile(r"Content-Security-Policy|contentSecurityPolicy|helmet[\s\S]{0,40}?\bcsp\b"
CSP_ANY = re.compile(r"Content\-Security\-Policy|contentSecurityPolicy|helmet[\s\S]{0,40}?\bcsp\b"
r"|useCspNonce|cspDirectives", re.I)
CSP_SCRIPT_SELF = re.compile(r"script-src[^;'\"]*'self'", re.I)
CSP_NONCE = re.compile(r"'nonce-|nonce-\$\{|\bstrict-dynamic\b", re.I)
CSP_UNSAFE = re.compile(r"'unsafe-(?:inline|eval)'", re.I)
INLINE_HANDLER = re.compile(r"\son(?:click|load|error|mouseover|submit)\s*=\s*['\"]", re.I)

HSTS_ANY = re.compile(r"Strict-Transport-Security|helmet[\s\S]{0,40}?\bhsts\b|\bhsts\s*[:=]"
HSTS_ANY = re.compile(r"Strict\-Transport\-Security|helmet[\s\S]{0,40}?\bhsts\b|\bhsts\s*[:=]"
r"|max-age=\d+[\s\S]{0,40}?includeSubDomains", re.I)
HSTS_SUBDOMAINS = re.compile(r"includeSubDomains", re.I)
HSTS_PRELOAD = re.compile(r"\bpreload\b", re.I)
Expand All @@ -39,7 +39,7 @@
HTML_SURFACE = re.compile(r"\.(?:html|tsx|jsx|vue|svelte|astro)$|_document|app/layout|index\.html", re.I)
# HTML built/served in CODE (a Worker / server-rendered app emitting template-literal HTML) — so CSP
# applies even with no frontend framework. This is the gap that missed a Cloudflare Worker's CSP.
HTML_CONTENT = re.compile(r"<!DOCTYPE\s+html|<html[\s>]|text/html|res\.send\(\s*[`'\"]\s*<|c\.html\(", re.I)
HTML_CONTENT = re.compile(r"<!DOCTYPE\s+html|<html[\s>]|text\/html|res\.send\(\s*[`'\"]\s*<|c\.html\(", re.I)
# A construct that SERVES bytes over HTTP (vs merely building an HTML string and writing it to a file).
# This is what separates a real browser-facing surface from a Python/CLI report generator — the latter
# emits `<!DOCTYPE html>` into a file with no serving verb, so it must NOT trigger CSP/clickjacking leads.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_pentest_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,22 @@ def test_classes_reach_ledger_with_citations(self):
class FalsePositiveRegressionTests(unittest.TestCase):
"""Lock in the accuracy fixes found by dogfooding on real repos (68 → 11 new-group findings)."""

def test_own_extractor_source_does_not_trigger_csp_fp(self):
# Pen-test tool source naturally contains the strings 'text/html' and 'Content-Security-Policy'
# in regex definitions. These should not trick the heuristic into classifying the tool's repo
# as a web surface missing a strict CSP.
files = {
"src/ext.py": (
"CSP_ANY = re.compile(r\"Content\\-Security\\-Policy\")\n"
"HTML_CONTENT = re.compile(r\"text\\/html|res\\.send\")\n"
"SERVE_VERB = re.compile(r\"make_response|sendFile\")\n"
)
}
facts = {"stack": {"frameworks": []}}
out = TransportSecurityExtractor().extract(repo(files), facts)
self.assertFalse(out.get("html_surface"))
self.assertEqual(out.get("findings", []), [])

def test_aws_sam_and_cdk_out_dirs_skipped(self):
# regression: vendored SDK code under an AWS SAM build dir must not be scanned
ctx = repo({"aws/.aws-sam/deps/abc/models.py": "account_number='x'\n",
Expand Down