Skip to content

feat(registry): configure CORS headers - #1545

Merged
ricardo-devis-agullo merged 2 commits into
masterfrom
feat/configurable-cors-security-headers
Aug 9, 2026
Merged

feat(registry): configure CORS headers#1545
ricardo-devis-agullo merged 2 commits into
masterfrom
feat/configurable-cors-security-headers

Conversation

@ricardo-devis-agullo

@ricardo-devis-agullo ricardo-devis-agullo commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add optional registry cors configuration for origin, credentials, allowed headers, and methods
  • preserve the existing CORS and X-Powered-By defaults exactly
  • validate invalid CORS configuration before registry startup
  • cover defaults and custom preflight behavior through the Express HTTP adapter boundary
  • preserve existing registry URLs and Accept contracts

Test plan

  • npm run build --workspace=oc
  • npx tsc --project packages/oc/tsconfig.types.json
  • npx mocha ./test/unit/registry-domain-options-sanitiser.js ./test/unit/registry-domain-validator.js ./test/unit/registry-middleware-cors.js from packages/oc (158 passing)
  • npm run test-silent --workspace=oc (982 passing)
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable CORS response headers to the registry while retaining existing defaults.

Changes:

  • Adds typed CORS configuration, normalization, and validation.
  • Applies configured headers through registry middleware.
  • Adds unit, HTTP adapter, and type coverage.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/oc/src/types.ts Defines CORS configuration types.
packages/oc/src/index.ts Exports public CORS types.
packages/oc/src/resources/index.ts Adds CORS validation messages.
packages/oc/src/registry/middleware/cors.ts Validates, normalizes, and applies CORS headers.
packages/oc/src/registry/domain/options-sanitiser.ts Normalizes registry CORS options.
packages/oc/src/registry/domain/validators/registry-configuration.ts Validates CORS configuration before startup.
packages/oc/test/unit/registry-middleware-cors.js Tests default and custom HTTP headers.
packages/oc/test/unit/registry-domain-validator.js Tests invalid CORS options.
packages/oc/test/unit/registry-domain-options-sanitiser.js Tests defaults and normalization.
packages/oc/test/types/registry-cors.ts Verifies public TypeScript usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

'Origin, X-Requested-With, Content-Type, Accept, traceparent'
);
res.set('Access-Control-Allow-Methods', 'GET, OPTIONS, PUT, POST');
res.set('Access-Control-Allow-Credentials', String(options.credentials));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 43295cb: Access-Control-Allow-Credentials is now emitted only when cors.credentials is true; the custom HTTP adapter test verifies the header is absent when disabled.

@ricardo-devis-agullo
ricardo-devis-agullo merged commit b283ca1 into master Aug 9, 2026
3 checks passed
@ricardo-devis-agullo
ricardo-devis-agullo deleted the feat/configurable-cors-security-headers branch August 9, 2026 19:34
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.

2 participants