Repository navigation
sec(web): harden local dashboard against CSRF, DNS rebinding, and XSS - #139
Closed
kushaldave002 wants to merge 3 commits into
Closed
kushaldave002 wants to merge 3 commits into
kushaldave002 wants to merge 3 commits into
Conversation
- Protect state-changing dashboard routes with CrossSiteProtectionMiddleware validating Origin, Sec-Fetch-Site, and Referer - Restrict accepted hostnames to loopback addresses using TrustedHostMiddleware to prevent DNS rebinding - Add security hardening headers including Content-Security-Policy (CSP), X-Frame-Options: DENY, X-Content-Type-Options: nosniff, and Referrer-Policy: strict-origin-when-cross-origin - Validate file uploads against permitted document extensions and enforce maximum upload size chunk-by-chunk during streaming - Serve attachment downloads as application/octet-stream with Content-Disposition: attachment - Harden runtime API key verification with candidate lookup and constant-time hmac.compare_digest - Add fuzzing tests and property tests with Atheris and Hypothesis for document text extraction - Document local dashboard threat model in SECURITY.md
…re filesystem access
Collaborator
|
Thanks for taking on the dashboard hardening, @kushaldave002. The middleware structure is good, Blocking
Should fix
Happy to review the next version. |
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.
Summary
Hardens the local
secfoo servedashboard against CSRF, DNS rebinding, XSS, and related web-based attack vectors targeting local services (as tracked in #118).Key Hardening Measures
CSRF & Cross-Site Origin Validation (
CrossSiteProtectionMiddleware):Origin,Sec-Fetch-Site: cross-site, andRefererheaders on all state-changing endpoints (POST,PUT,PATCH,DELETE).403 Forbiddenwhile allowing local CLI/curl non-browser requests that lack cross-site browser headers.POST /assessmentsPOST /assessments/bulk-statusPOST /assessments/{assessment_id}/runsPOST /assessments/{assessment_id}/attachmentsPOST /assessments/{assessment_id}/deletePOST /activities/sast/findings/{fingerprint}/reviewDNS Rebinding Defense (
TrustedHostMiddleware):Hostheaders to loopback hostnames (localhost,127.0.0.1,[::1],testserver, and the explicitly configuredbind_host). Unrecognized hosts are rejected with400 Bad Request.Security Headers (
SecurityHeadersMiddleware):script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net ...,style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net ...,frame-ancestors 'none',object-src 'none').X-Frame-Options: DENY,X-Content-Type-Options: nosniff, andReferrer-Policy: strict-origin-when-cross-origin.File Upload Restrictions & Streamed Limits:
.pdf,.docx,.pptx,.md,.html,.htm,.txt,.json,.yaml,.yml,.csv).MAX_UPLOAD_BYTES(50MB), preventing memory/disk exhaustion and cleaning up partial files on breach.Safe Attachment Downloads:
GET /assessments/{assessment_id}/attachments/{attachment_id}/downloadendpoint.Content-Type: application/octet-stream,Content-Disposition: attachment; filename="...", andX-Content-Type-Options: nosniff.Constant-Time Runtime API Key Verification:
key_prefixcandidate query andhmac.compare_digestto prevent timing side channels.--allow-insecure-runtimeis passed.Fuzzing & Threat Model Documentation:
fuzz/fuzz_docext.pyand Hypothesis property-based fuzz tests intests/test_docext.py.SECURITY.mdwith a detailed "Local dashboard threat model" section.tests/test_web/test_dashboard_security.py(26 tests).Closes #118