Repository navigation
security: XSS corpus, bounded uploads and runtime API audit for the dashboard (#118) - #189
Merged
Merged
Conversation
…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
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.
Leaderboard update
aaas72 now has 22 points (rank #2). 3 more to reach Bronze. |
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.
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.mdwrite-up (6).What I found and fixed
.txt,.json,.md, ...) had no limit at all.MAX_UPLOAD_BYTES(25 MB). The copy stops at the cap. The middleware refusesContent-Lengthover the cap (413), or a missing length (411), before Starlette spools the multipart body to a temp file..pdf/.docx/.pptxname 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 gets415before a parser runs, so a DOCX renamed.pptxis refused too.docext.pynoted.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).zipfilenever inflates a member past its declared size, so the central directory is a real bound.fuzz/fuzz_docext.py, with the new type check added to the harness, crashed:zipfile.ZipFile()raisesNotImplementedError(notBadZipFile) for an unsupported "version needed to extract".fuzz/corpus/docext/crash-zip-unsupported-version.docx.bin, generated bymake_seed_corpus.py. A route test checks that it gets415, not500. A second 60 s run: 65,371 inputs, no crash, peak RSS 90 MB.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.hmac.compare_digest. A test enumeratesruntime_api.routerso a future route is covered automatically, and sends 8 badAuthorizationvariants to each route._require_secure_transportcomparedbind_hostagainst a literal set, so--host [::1],LOCALHOSTorlocalhost.were treated as non-loopback and keys over HTTP were refused.web.security.is_loopback. 3 of the new tests fail onmain.--allow-insecure-runtimewas documented as "disables the check".Hostcheck and rate limits still apply.securityLevel: "strict") and Jinja autoescape held for every payload.XSS regression corpus (
tests/test_web/test_xss_corpus.py)56 payloads: raw
<script>,<img onerror>, SVGonload/<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,clickhandlers, a%%{init: {"securityLevel": "loose"}}%%directive, and</pre>breakouts.Each payload runs:
render_report_htmlon its own and inside a finding detail block, which must produce nothing executable;update_sast_findingsand renders/runs/{uuid},/activities/sast/findings, the F1 detail page,/activities/sastand/. 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 orhttp(s).Mutation check: with raw HTML re-enabled and
_strip_outbound_markupremoved, 100 of the 227 tests fail. With Jinja autoescape turned off, 50 of the page tests fail.Not changed (noted in
SECURITY.md)docext.pydescribes. The fuzz harness asserts each input finishes in 30 s.Content-Dispositionto set.Testing
pytest: 2262 passed, 1 skipped. The 4 failures are the Mermaid architecture-page tests, which also fail onmainwithoutsecfoo vendor mermaid.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 existing0.0.0.0constant insecurity.py).python fuzz/fuzz_docext.py WORK fuzz/corpus/docext -max_total_time=60 -timeout=30 -rss_limit_mb=2048with Atheris, as above.