Repository navigation
Harden CORS: default to same-origin allowlist, guard cross-origin POSTs - #406
Open
danishkumar26 wants to merge 1 commit into
Open
danishkumar26 wants to merge 1 commit into
danishkumar26 wants to merge 1 commit into
Conversation
Fixes msoedov#334: allow_origins=['*'] granted every web origin access to the unauthenticated, state-changing /scan, /scan-csv, /stop and /verify endpoints, which can exfiltrate operator secrets injected into HTTP specs. - setup_cors now reads AGENTIC_SECURITY_CORS_ORIGINS / [server] cors_allow_origins, defaulting to [] (same-origin only), and warns if '*' is explicitly configured. - New OriginGuardMiddleware rejects cross-origin state-changing requests (403) when the Origin header is not allowlisted; same-origin clients and non-browser tools (no Origin header) are unaffected. Adds unit tests for the CORS allowlist and the Origin guard; all pass, ruff/format clean.
danishkumar26
commented
Nov 30, 2026
danishkumar26
left a comment
Author
There was a problem hiding this comment.
Review: Harden CORS: default to same-origin allowlist, guard cross-origin POSTs
Strengths:
- setup_cors now defaults to allow_origins=[] (same-origin only) instead of the wildcard ["*"], with opt-in via AGENTIC_SECURITY_CORS_ORIGINS or [server] cors_allow_origins in agentic_security.toml; the env var takes precedence.
- New OriginGuardMiddleware returns 403 for cross-origin browser requests to state-changing endpoints, covering simple POSTs that bypass CORS preflight; same-origin clients and callers sending no Origin header are unaffected.
- Tests added for allowlist resolution (env/toml/default), the wildcard warning, and OriginGuard behavior.
Issues: none Critical or Important.
Minor (note for later, no code changes required):
- SAFE_METHODS includes TRACE, so cross-origin TRACE requests pass the origin guard. Exclude TRACE unless it is explicitly needed.
- DEFAULT_CONFIG_PATH is relative ("agentic_security.toml"); resolution depends on the working directory at import/startup time. Consider a project-relative absolute path.
Assessment: ready to merge; no blocking issues.
This branch has not been deployed
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.
Fixes #334:
allow_origins=["*"]granted every web origin access to the unauthenticated, state-changing/scan,/scan-csv,/stopand/verifyendpoints, which can exfiltrate operator secrets injected into HTTP specs.Changes
setup_corsnow readsAGENTIC_SECURITY_CORS_ORIGINS/[server] cors_allow_origins, defaulting to[](same-origin only), and warns if"*"is explicitly configured.OriginGuardMiddlewarerejects cross-origin state-changing requests with 403 when theOriginheader is not allowlisted. Same-origin clients and non-browser tools (noOriginheader) are unaffected.Why
CORS controls whether a browser can read a cross-origin response, but simple POSTs (
/stop,/scan-csv) are still sent without a preflight. Combined with the wildcard, any page the operator visits while the scanner runs could drive these endpoints and, via/verify, read the response — including secrets substituted into the spec body.Testing
/stopgets 403, no-Origin POST/stopstill returns 200.