Skip to content

Harden CORS by enforcing explicit origin allowlist - #5

Open
heliosran wants to merge 1 commit into
mainfrom
codex/update-cors-settings-for-security
Open

Harden CORS by enforcing explicit origin allowlist#5
heliosran wants to merge 1 commit into
mainfrom
codex/update-cors-settings-for-security

Conversation

@heliosran

Copy link
Copy Markdown
Owner

Motivation

  • Prevent using a wildcard origin together with credentials and reduce the CORS attack surface by requiring explicit allowlisting of trusted origins.

Description

  • Replace wildcard origin: "*" CORS behavior with an explicit allowlist driven by the ALLOWED_ORIGINS environment variable and exact-origin matching in src/index.ts.
  • Only return Access-Control-Allow-Credentials: true when the request Origin is explicitly allowlisted and set minimal preflight surface: allowed methods POST, GET, OPTIONS and headers Content-Type, Authorization.
  • Add ALLOWED_ORIGINS?: string to the Env type in src/types.ts and document the configuration in README.md and .dev.vars.example.
  • Add unit tests (test/index.spec.ts) covering preflight and regular-response CORS headers for allowed and disallowed origins, and update vitest.config.mts to use wrangler.toml for the test pool.

Testing

  • Ran TypeScript check with npm run tsc and it succeeded.
  • Ran linter with npm run lint and it succeeded.
  • Ran tests with npm run test -- --run; the initial test run surfaced a missing wrangler.jsonc config (failure), then after updating the vitest config to point to wrangler.toml the test suite passed: 4 tests (all passed).

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant