Skip to content

fix: make HTTP mode safer by default (localhost bind + origin checks + clear auth errors)#77

Open
Shubhdeep12 wants to merge 2 commits intoresend:mainfrom
Shubhdeep12:fix/http-origin-bind
Open

fix: make HTTP mode safer by default (localhost bind + origin checks + clear auth errors)#77
Shubhdeep12 wants to merge 2 commits intoresend:mainfrom
Shubhdeep12:fix/http-origin-bind

Conversation

@Shubhdeep12
Copy link
Contributor

changes:

  • http server now binds to 127.0.0.1 by default (not all network interfaces).
  • Added an Origin allowlist for browser requests to /mcp.
  • Added proper CORS preflight support for allowed origins.
  • Standardized auth/security errors:
    • 401 when Bearer token is missing/invalid
    • 403 when Origin is not allowed
  • Added config options:
    • CLI: --host, --origins
    • ENV: MCP_HOST, MCP_ALLOWED_ORIGINS

- Added configuration options for HTTP bind host and comma-separated origin allowlist.
- Updated README to reflect new options and usage examples.
- Modified server initialization to handle new parameters for host and allowed origins.
- Implemented CORS handling to enforce origin restrictions on requests.
- Enhanced error handling for unauthorized and forbidden requests.
- Removed redundant isString function and replaced it with a type guard in the allowed origins normalization process.
- Enhanced type safety by ensuring only non-null strings are included in the allowed origins set.
@Shubhdeep12
Copy link
Contributor Author

i think its nice to have this check, wdyt @drish ?

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.

1 participant