Skip to content

Harden CORS: default to same-origin allowlist, guard cross-origin POSTs - #406

Open
danishkumar26 wants to merge 1 commit into
msoedov:mainfrom
danishkumar26:fix/cors-origin-allowlist
Open

danishkumar26 wants to merge 1 commit into
msoedov:mainfrom
danishkumar26:fix/cors-origin-allowlist

Conversation

@danishkumar26

@danishkumar26 danishkumar26 commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #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.

Changes

  • 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 with 403 when the Origin header is not allowlisted. Same-origin clients and non-browser tools (no Origin header) 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

  • Unit tests for the CORS allowlist and the Origin guard (12 tests, all pass).
  • Ruff check and format clean.
  • Verified end-to-end: foreign-origin preflight gets 400/no ACAO, foreign-origin POST /stop gets 403, no-Origin POST /stop still returns 200.

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 danishkumar26 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS: allow_origins=["*"] exposes unauthenticated /scan, /scan-csv, /stop, /verify to any web origin

1 participant