Security hardening: timing attacks, LDAP injection, auth guards, permissions#65
Open
xMinhx wants to merge 13 commits into
Open
Security hardening: timing attacks, LDAP injection, auth guards, permissions#65xMinhx wants to merge 13 commits into
xMinhx wants to merge 13 commits into
Conversation
- conftest.py patches requests.get + time.sleep in cve_fetcher module - Skips mock for tests marked @pytest.mark.nvd_integration - Moves test_cve_fetcher.py module-level code into fixtures - pytest.ini excludes nvd_integration by default 66 tests now run in ~1s vs timing out at >120s
Use hmac.compare_digest for constant-time string comparison to prevent timing side-channel attacks that could allow an attacker to recover API keys character by character. Fixes C1 from security audit.
Use ldap3.utils.conv.escape_filter_chars to escape special characters in LDAP search filters before interpolation. Prevents authentication bypass and data exfiltration via crafted username values. Fixes C2 from security audit.
Only allow hardcoded dev credentials when IS_DEV=True to prevent accidental exposure in production. Use hmac.compare_digest for constant-time password comparison to prevent timing attacks on credential validation. Fixes C3 from security audit.
Add IsAuthenticated and analyzer.delete_project permission requirements to DeleteProjectAPI to prevent IDOR. Any authenticated user could previously delete any project. Fixes H1 from security audit.
Add regex validation for CVE ID format to prevent SSRF via crafted CVE IDs. Add 30-second timeout to NVD and EPSS API requests to prevent slow-loris DoS attacks. Fixes H2 from security audit.
Add ALLOWED_TEMPLATES frozenset to HtmlView to prevent template injection. Non-whitelisted template names are logged and the login page is rendered instead. This mitigates information disclosure via path traversal. Fixes H5 from security audit.
L1: Use specific UID (1000) for baseuser to avoid permission
issues with volume mounts.
L2: Add HEALTHCHECK instruction using Python urllib to verify
the application is responding.
L3: Make gunicorn workers and threads configurable via
GUNICORN_WORKERS and GUNICORN_THREADS env vars.
Fixes L1, L2, L3 from security audit.
H3: Add AnonRateThrottle and UserRateThrottle. Tighten login
rate to 5/min to prevent brute-force attacks.
H4: Use secrets.token_urlsafe() to generate random dev
credentials when not explicitly set. Log warning.
M2: Replace CORS_ALLOW_ALL_ORIGINS with explicit origins
whitelist (already correct, but add dev origins).
M3: Add HTTPS enforcement settings (HSTS, SSL redirect,
X-Frame-Options, content type nosniff) for production.
Fixes H3, H4, M2, M3 from security audit.
…ion now works)" This reverts commit 9f7ee13.
e0a5bf3 to
09f8279
Compare
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
8 security fixes identified during a systematic audit of the codebase. Each commit addresses one finding and is self-contained.
Changes
Notes
Dependencies