Skip to content

Hardening: safer CORS config + localhost bind defaults#2767

Open
TheodorNEngoy wants to merge 2 commits intoIBM:mainfrom
TheodorNEngoy:codex/hardening-cors-bind
Open

Hardening: safer CORS config + localhost bind defaults#2767
TheodorNEngoy wants to merge 2 commits intoIBM:mainfrom
TheodorNEngoy:codex/hardening-cors-bind

Conversation

@TheodorNEngoy
Copy link

This hardens the LangChain agent runtime defaults to avoid two common security footguns for network-exposed MCP-adjacent servers:

  • CORS: stop combining CORS_ORIGINS=* with credentials. The app now reads CORS_ORIGINS/CORS_CREDENTIALS and forces credentials off when CORS_ORIGINS=* (with a warning), since wildcard+credentials is unsafe.
  • Bind host: default local dev runs to 127.0.0.1 instead of 0.0.0.0 in Makefile and start_agent.py (still configurable via HOST/PORT). The container Dockerfile remains --host 0.0.0.0.

Also updates .env.example to reflect safer defaults (CORS disabled by default; loopback bind by default).

Rationale: reduces accidental remote exposure + credentialed cross-origin access while keeping intentional remote deployments opt-in.

Signed-off-by: Theodor N. Engøy <theodornengoy@Mac.home>
@TheodorNEngoy TheodorNEngoy force-pushed the codex/hardening-cors-bind branch from 722d4c0 to 2850c4a Compare February 8, 2026 18:36
@crivetimihai crivetimihai self-assigned this Feb 9, 2026
@crivetimihai crivetimihai added this to the Release 1.0.0-RC1 milestone Feb 9, 2026
@crivetimihai
Copy link
Member

Thanks for this hardening PR, @TheodorNEngoy! Solid security improvements:

  • Catching the wildcard CORS + credentials anti-pattern and logging a warning is exactly right.
  • Defaulting to localhost binding and CORS-disabled is good principle of least privilege.

A couple of minor suggestions:

  1. DRY the port parsing: _env_int is defined in app.py but the same logic is manually reimplemented in start_agent.py (lines 116-120). Consider sharing the helper.
  2. Makefile hardcodes host: The run/dev targets use literal --host 127.0.0.1, so HOST=0.0.0.0 make run won't work as expected. Using --host $${HOST:-127.0.0.1} would be more consistent.

Neither is a blocker. LGTM!

Signed-off-by: Theodor N. Engøy <theodornengoy@eduroam-193-157-246-146.wlan.uio.no>
@TheodorNEngoy
Copy link
Author

Thanks! Addressed both nits:

  • DRY port parsing: factored env helpers into agent_runtimes/langchain_agent/env_utils.py and start_agent.py now uses shared _env_int().
  • Makefile HOST override: run/dev now use --host 65847{HOST:-127.0.0.1} and --port 65847{PORT:-8000} so HOST=0.0.0.0 make run behaves as expected.

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.

3 participants