Skip to content

fix(cors): enforce explicit allowed_origins in production and restrict methods/headers (#24) - #80

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/cors-production-guard-and-methods-24
Open

fix(cors): enforce explicit allowed_origins in production and restrict methods/headers (#24)#80
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/cors-production-guard-and-methods-24

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 3, 2026

Copy link
Copy Markdown

Summary

Resolves #24 by:

  1. Adding a production-readiness check in Config::from_env(): when APP_ENV is production/prod, startup fails with bail! if ALLOWED_ORIGINS is unset, empty, or contains '*'.
  2. Narrowing AllowMethods in build_cors_layer from AllowMethods::any() to explicit API methods: GET, POST, OPTIONS.
  3. Narrowing AllowHeaders from AllowHeaders::any() to explicit necessary headers: Authorization, Content-Type, Accept, and X-Request-Id.
  4. Adding max_age(Duration::from_secs(3600)) for preflight caching.
  5. Adding unit tests for wildcard and explicit origins in src/middleware/cors.rs.

Fixes #24.

…t methods/headers (StellarSend#24)

- Require explicit non-wildcard ALLOWED_ORIGINS when APP_ENV=production in Config::from_env
- Restrict AllowMethods to GET, POST, OPTIONS
- Restrict AllowHeaders to Authorization, Content-Type, Accept, X-Request-Id
- Set max_age for preflight caching
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 layer defaults to fully open (any origin/method/header) with no production guard

1 participant