Repository navigation
security: dashboard refuses cross-site writes and foreign Host headers (#118) - #160
Merged
Merged
Conversation
secfoo serve has no login and binds 127.0.0.1, so the threat is the user's own browser. Verified against a live server before this change: a cross-site form POST created an assessment (the same works for launching a paid agent run or deleting a case file), and a request with Host: rebind.evil.example was served the full dashboard (DNS rebinding). - Unsafe methods must come from the dashboard's own origin: Origin, Sec-Fetch-Site or (failing both) Referer naming another origin -> 403. Clients that send none (curl, scripts) are unaffected; the key- authenticated runtime ingest API is exempt from this check. - Host must be a loopback name or the --host; anything else -> 400. --allow-host NAME adds a forwarding/proxy name; a wildcard bind accepts any. - Security headers on every response, including a CSP with script-src 'self' and frame-ancestors 'none'. Checked in headless Chrome: no violations on six pages and Mermaid still renders (a deliberately broken policy produces 28 violations, so the check works). - serve warns when --host is not loopback. Part of #118. Co-Authored-By: Claude Opus 5.5 <[email protected]>
vsn411
added a commit
that referenced
this pull request
Nov 21, 2026
…ashboard (#118) (#189) * security: XSS corpus, bounded uploads and runtime API audit for the dashboard The rest of #118 after #160 (cross-site writes, DNS rebinding, headers). - XSS regression corpus: 56 payloads through render_report_html and through the run, SAST and secret-scanning pages that show report data; a page must not gain any script, frame, form, image, inline handler or non-http(s) URL compared with the same page built from harmless text. - Uploads: every attachment kind is capped at MAX_UPLOAD_BYTES, the copy stops at the cap, and the middleware refuses a larger Content-Length (413) or a missing one (411) before Starlette spools the body. A PDF/DOCX/PPTX whose bytes are not that format gets 415 before any parser runs. DOCX/PPTX archives that expand past 200 MB or hold more than 5,000 members are not parsed. - Fuzzing docext for 60 s with the new type check found that zipfile raises NotImplementedError for an unsupported version; fixed, and the reproducer is in fuzz/corpus/docext. - Runtime API: a test enumerates every /api/runtime route and requires 401 without a valid key; the stored key hash is compared with hmac.compare_digest; "[::1]", "LOCALHOST" and "localhost." binds count as loopback for the TLS check; --allow-insecure-runtime is documented as lifting only that check. - SECURITY.md: "Local dashboard threat model". Closes #118 * test(web): XSS page comparison with the Mermaid bundle vendored CI has mermaid.min.js vendored, so pages showing a diagram load the Mermaid scripts and the poisoned Mermaid payloads gained two dashboard script tags over a diagram-free baseline. The baseline now has a harmless diagram, the fixture renders as if the bundle is vendored (the riskier case), and a page fails only if it gains something over the baseline. --------- Co-authored-by: aitechnology <[email protected]>
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.
Part of #118 (CSRF, DNS rebinding). Found during end-to-end testing before go-live, and confirmed against a live
secfoo servebuilt frommain:/assessments(same for/assessments/{id}/runs, which starts a paid agent run,/delete, finding review)303, assessment created403, nothing writtenHost: rebind.evil.example→ 127.0.0.1400X-Frame-OptionsWhat changed
New
src/secfoo/web/security.pyadds one middleware, installed as the outermost layer:Origin(includingnull) orSec-Fetch-Sitenames another origin gets403; so does one with only aReferernaming another origin./api/runtime/is exempt: it is authenticated by anAuthorizationheader, which a cross-site page cannot set without a CORS preflight the app never grants.Hostmust belocalhost,127.0.0.1,[::1]or--host; anything else gets400.secfoo serve --allow-host NAME, repeatable, for port-forwarding or proxy names. The error message says so.--host 0.0.0.0accepts any name, but still refuses cross-site writes.Content-Security-Policy(default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; … frame-ancestors 'none'),X-Frame-Options: DENY,nosniff,Referrer-Policy: same-origin, COOP/CORPsame-origin.style-srcneeds'unsafe-inline'because Mermaid writes<style>into its SVGs. No script is inline:test_no_inline_scripts.pyalready enforces that.secfoo servewarns when--hostis not loopback (no login).SECURITY.mddocuments all of the above.Verification
tests/test_web/test_dashboard_security.py, 28 tests:127.0.0.1.evil.example, empty Host, …), IPv6/uppercase/trailing-dot loopback, bind host, wildcard,--allow-host/,/assessments,/assessments/new,/agents,/activities/sastand a run report containing a Mermaid diagram.script-src 'none'the same check reports 28 violations, so it does detect breakage.tests/conftest.pyallows Starlette TestClient's defaultHost: testserverfor the rest of the suite. The new tests turn that off.Still open in #118 for contributors: the systematic XSS corpus for report content. A 22-payload spot check through
render_report_htmlfound nothing executable.🤖 Generated with Claude Code