Repository navigation
feat(cors): add SDK CORS handling with preflight support (#1322) - #1372
Merged
Kingsman-99 merged 2 commits intoNov 23, 2026
Merged
Kingsman-99 merged 2 commits into
Kingsman-99 merged 2 commits into
Conversation
|
@Phantomcall Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Closed
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add SDK CORS handling (#1322)
Summary
Adds a transport-agnostic
CorsHandlerso@stellar-split/sdkconsumers can serve browser requests safely. Itresolves origins (including async allow-list predicates), answers preflight requests, applies credential-safe header
rules, supports custom headers and tracks decisions with bounded, payload-free events.
What changed
src/cors.tsCorsHandler.handle(request)evaluates a minimal{ method, origin, headers }request and returns{ allowed, isPreflight, headers, reason }that any HTTP layer can apply.*), explicit string, allow-list array,true(reflect any origin), or an async predicate function.isOriginAllowed()exposes the same rule for reuse.OPTIONS+Access-Control-Request-Method, validates the requested method and headers case-insensitively, and emitsAccess-Control-Allow-Methods,Access-Control-Allow-HeadersandAccess-Control-Max-Age.Access-Control-Allow-Origin: *together withAccess-Control-Allow-Credentials: true; the concrete origin is reflected instead andVary: Originis always set on browser responses.allowedHeadersandexposedHeaders(Access-Control-Expose-Headers), plus default SDK trace headers.stats()counts requests, preflights, approvals and denials;eventsTrail()keeps a bounded record of decisions including denial reasons;reset()clears state.src/index.tsfor the handler and all public types.test/cors.test.ts(11 tests) covering wildcard/fixed/predicate origins, missing origins, credential safety on actual and preflight requests, custom methods/headers/max-age, unsupported methods/headers, stats and bounded tracking.Acceptance criteria addressed
OPTIONSrequests are validated and answered with method/header/max-age headers.Vary: Originis set.Testing
npm run lintwas already failing before this change because of pre-existing syntax errors/merge-conflict markers in unrelated files; this change adds no new TypeScript errors.Backwards compatibility
Additive only; no existing module or API is modified.
closes #1322