fix: harden CORS by rejecting missing Origin header#904
Conversation
|
heyy @utksh1 |
utksh1
left a comment
There was a problem hiding this comment.
This PR needs to be narrowed before review/merge.
The title says CORS hardening, but the diff also carries old ZAP scanner/plugin changes plus frontend package/package-lock changes and settings test churn. That makes the security review surface much larger than the CORS fix and risks merging unrelated behavior.
Please rebase or recreate this as a focused CORS PR containing only the backend CORS/middleware behavior and the directly related tests. Move dependency/audit/frontend/plugin changes to separate PRs.
b13a386 to
c2f1971
Compare
…own origins - HardenCORSMiddleware now checks Origin against allowed origins list - Requests without Origin are passed through (not CORS) - Requests with known/allowed origins pass through - Only requests with disallowed origins get 403
|
heyy @utksh1 |
utksh1
left a comment
There was a problem hiding this comment.
Rechecking after the latest CORS commit: this is still blocked.
The patch still needs to be narrowed to the CORS behavior and direct tests. Please remove unrelated plugin/ZAP, frontend dependency, settings UI, and audit-policy churn so the CORS security change can be reviewed on its own.
✦ Description
Harden CORS by rejecting requests missing the Origin header instead of implicitly allowing them in development. Previously the CORS handler allowed (!origin && !isProd) which trusted requests with no Origin header during development and could expose the development API when the server is reachable on a local network.
The update ensures that only explicitly allowed origins are accepted, improving backend security and preventing unintended cross-origin access during development.
Fixes #740
⟡ Type of Change
✦ Checklist
⟡ Screenshots / Screen Recordings (Required for UI changes)
N/A — backend security fix, no UI changes.
Description
Root Cause
The previous CORS origin handler accepted requests without an Origin header in non-production environments, which could unintentionally expose the development API to local network access or malformed requests.
Changes Made
backend/secuscan/request_middleware.pyto addHardenCORSMiddleware.backend/secuscan/main.py.testing/backend/integration/test_cors.py.Testing Performed
Result
PASS — 4 tests passed successfully.
Type of change
Checklist:
Additional Notes