Skip to content

security: XSS corpus, bounded uploads and runtime API audit for the dashboard (#118) - #189

Merged
vsn411 merged 4 commits into
secfoo-com:mainfrom
aaas72:security/118-dashboard
Nov 21, 2026
Merged

vsn411 merged 4 commits into
secfoo-com:mainfrom
aaas72:security/118-dashboard

Conversation

@aaas72

@aaas72 aaas72 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Closes #118

#160 already covered parts 1 and 3 of the issue (cross-site writes, DNS rebinding, security headers). This PR does the rest: the runtime API audit (2), the XSS corpus (4), upload handling (5) and the SECURITY.md write-up (6).

What I found and fixed

Area Found Fix
Uploads Only PDF/DOCX/PPTX were size-capped, and only after the whole body had been written to disk. Any other kind (.txt, .json, .md, ...) had no limit at all. Every kind is capped at MAX_UPLOAD_BYTES (25 MB). The copy stops at the cap. The middleware refuses Content-Length over the cap (413), or a missing length (411), before Starlette spools the multipart body to a temp file.
Uploads Any bytes with a .pdf/.docx/.pptx name went to pypdf / python-docx / python-pptx. docext.content_matches_extension(): a PDF header, or an OOXML archive that has its main part. Anything else gets 415 before a parser runs, so a DOCX renamed .pptx is refused too.
Uploads Zip-bomb-shaped DOCX/PPTX were the residual risk docext.py noted. check_archive_bounds(): more than 200 MB expanded or 5,000 members means the archive is not parsed (the upload is kept, as before for unreadable files). zipfile never inflates a member past its declared size, so the central directory is a real bound.
Fuzzing 60 s of fuzz/fuzz_docext.py, with the new type check added to the harness, crashed: zipfile.ZipFile() raises NotImplementedError (not BadZipFile) for an unsupported "version needed to extract". The predicate treats any exception as "not that format". Reproducer: fuzz/corpus/docext/crash-zip-unsupported-version.docx.bin, generated by make_seed_corpus.py. A route test checks that it gets 415, not 500. A second 60 s run: 65,371 inputs, no crash, peak RSS 90 MB.
Runtime API Every route goes through caller(), so all of them already required a key. The key is looked up by its SHA-256 in SQL. That leaks nothing useful (it is the hash of a 256-bit random token), but the compare was not constant-time by construction. The stored hash is now checked with hmac.compare_digest. A test enumerates runtime_api.router so a future route is covered automatically, and sends 8 bad Authorization variants to each route.
Runtime API _require_secure_transport compared bind_host against a literal set, so --host [::1], LOCALHOST or localhost. were treated as non-loopback and keys over HTTP were refused. Uses web.security.is_loopback. 3 of the new tests fail on main.
Runtime API --allow-insecure-runtime was documented as "disables the check". Documented and tested: it lifts only the TLS check. Keys, the Host check and rate limits still apply.
Report rendering Nothing executable got through. The renderer (raw HTML disabled, link scheme allowlist, images stripped, Mermaid source escaped, securityLevel: "strict") and Jinja autoescape held for every payload. Regression corpus, below.

XSS regression corpus (tests/test_web/test_xss_corpus.py)

56 payloads: raw <script>, <img onerror>, SVG onload / <script>, iframe (src, srcdoc), object, style, meta refresh, base, form, MathML; Markdown images (remote, javascript:, data:image/svg+xml, reference); javascript: links in 11 spellings (case, entities, hex entities, tab, newline, NUL, percent, reference, autolink, ...); vbscript:, data:, file:, protocol-relative and credentialed links; link-title and URL quote breakouts; entities and HTML in headings, plus breakouts of the [High] badge rewrite; table-cell badges; diff blocks; fence info strings; and Mermaid blocks with HTML labels, click handlers, a %%{init: {"securityLevel": "loose"}}%% directive, and </pre> breakouts.

Each payload runs:

  1. through render_report_html on its own and inside a finding detail block, which must produce nothing executable;
  2. through the real pages that show report data. The NodeGoat SAST report with the payload as F1's title, location, construct and detail text goes through update_sast_findings and renders /runs/{uuid}, /activities/sast/findings, the F1 detail page, /activities/sast and /. The secret-scanning sample goes the same way into the list, the dashboard and every finding detail page. Each page is compared with the same page built from harmless text and must not gain any script, frame, object, form, image, base/meta/link, inline handler, srcdoc, or URL attribute that is not a same-origin path or http(s).

Mutation check: with raw HTML re-enabled and _strip_outbound_markup removed, 100 of the 227 tests fail. With Jinja autoescape turned off, 50 of the page tests fail.

Not changed (noted in SECURITY.md)

  • Text extraction still runs in the request process. A pathological PDF can cost CPU time, and subprocess isolation is still the follow-up docext.py describes. The fuzz harness asserts each input finishes in 30 s.
  • Uploading a file with the same name as an existing attachment replaces the file on disk. I left that alone because it is not a cross-site or injection issue, and changing it would change the attachments model. I can open a separate issue if you'd like.
  • The dashboard has no route that serves uploads back, so there is no Content-Disposition to set.

Testing

  • pytest: 2262 passed, 1 skipped. The 4 failures are the Mermaid architecture-page tests, which also fail on main without secfoo vendor mermaid.
  • New: test_xss_corpus.py (227), test_upload_limits.py (24), test_runtime_auth.py (45).
  • ruff check: no new findings on the changed files. bandit -ll: no new findings (the one Medium is the existing 0.0.0.0 constant in security.py).
  • python fuzz/fuzz_docext.py WORK fuzz/corpus/docext -max_total_time=60 -timeout=30 -rss_limit_mb=2048 with Atheris, as above.

…ashboard

The rest of secfoo-com#118 after secfoo-com#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 secfoo-com#118
@aaas72
aaas72 requested a review from vsn411 as a code owner November 21, 2026 17:51
Comment thread src/secfoo/docext.py Fixed
aaas72 and others added 3 commits November 21, 2026 21:12
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.
CodeQL flagged the new bounded copy and type check (py/path-injection)
although the filename was already reduced to a basename and checked
against the attachment directory. Use os.path.normpath plus a prefix
check on the real directory, which the query treats as a barrier, and
keep the resolve() check for an existing symlink pointing out.
@vsn411
vsn411 merged commit 9abdc04 into secfoo-com:main Nov 21, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

aaas72 now has 22 points (rank #2). 3 more to reach Bronze.

Full leaderboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security review of the local dashboard: CSRF on state-changing routes, DNS rebinding, and an XSS regression suite

3 participants