feat(registry): serve CORS headers for configured browser origins - #173
Merged
Conversation
…OPTIONS answers off-route
5 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.
Summary
Closes #172
The registry mounted no CORS middleware, so a browser dApp on another origin could send a request but never read the response. It now serves CORS headers for origins named in
CORS_ORIGINS, defaulting tohttp://localhost:3012.Changes
corsmounted ahead of the body parser and the OpenAPI validators, so their own 400s stay readable cross-origin rather than reaching the page as a network error.CORS_ORIGINS, comma-separated,*for any origin; an entry no browser could send is refused at boot, whether a near miss, a non-http(s)scheme or a wildcard pattern, and the accepted list is on the startup line.GET,HEAD,POST,OPTIONS,Content-Type) and is cacheable for 600s, so a factory call is one round trip.Acceptance criteria
204identically, because the validators passOPTIONSthrough untouched. The order is pinned by the two tests asserting a rejection carries the header.Test plan
Automated tests
246 registry unit tests in 11 files (was 205 in 10); 80 Daml scenarios; 18 e2e against a live participant on Canton 3.5.12. Lint, both typechecks,
check:depsandsmoke:registryall clean.Manual verification
Mutation batteries in a throwaway clone red every new assertion: the mount order (below the validators reds two tests, below
express.json()one, below the routers eight), each boot guard on its own, the absence ofcredentials, and the log line's omission of the origin. Against the compiledregistry/dist: an allowed origin is reflected, a disallowed one getsVary: Originand no header, the preflight returns204with the exact method list andMax-Age: 600, andCORS_ORIGINS=http://localhost:3012/refuses the boot naming the form to use.Breaking changes
No documented route changes its request or response schema. Three operational notes: every response now carries
Vary: Origin;OPTIONSon a path the service does not route answers204where it used to404; and an unset or emptyCORS_ORIGINSmeans the default, so there is no value that allows no origin at all.Checklist
Screenshots
None.