~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Browsers: CORS on every path but OAuth's, as the reference answers

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:xrpc-cors

Apps in a browser, such as bsky.app on the web, can now call the server: every answer allows any origin, and an OPTIONS preflight answers 204, as the reference's do. Before, the browser blocked every call, and bsky.app's sign-in said "Unable to contact your service".

Claude Opus 5.5 · high

What changes

Spec. spec/PDS.md gains "Browsers": on every path but OAuth's (whose cross-origin answers OAUTH.md and OAUTH-MCP.md already give):

  • Every answer, of any status, carries Access-Control-Allow-Origin: *.

  • Any OPTIONS is a preflight: 204, no body, with these headers:

    • Allow-Origin: *;
    • Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE;
    • Allow-Headers echoing Access-Control-Request-Headers;
    • Max-Age: 86400;
    • Vary: Access-Control-Request-Headers.

    It reaches no method, so it costs no rate limit and is not forwarded.

All of this matches what the reference was seen to answer.

Harness. checks/cors.mjs, the cors step:

  • Requests a browser app makes, answered 200, 4xx and 404, with an Origin and without.
  • Preflights on methods served, a method not served, _health, a path that is no NSID and a path outside /xrpc/, with and without Access-Control-Request-Method and Access-Control-Request-Headers.
  • Each compared with the reference: the status, every Access-Control-* header, whether a preflight's Vary names Access-Control-Request-Headers, and whether its body is empty.

Server. cors.rs, a layer on the router, so preflights are still logged and counted under their route; OAuth's paths pass through to their own CORS.

Why

The spec said nothing about CORS outside OAuth, so the harness never asked. Native apps, the CLI and MCP clients don't need it, but every web app does. A layer on the router, rather than in each handler, covers paths served and not served alike, as the reference's does.

How it was checked

  • Before the server change, the new check fails at once: the reference answers a preflight 204 with the CORS headers, the server 400 with none.
  • Planted bug: the preflight not echoing Access-Control-Request-Headers. The check fails at step 2. Put back.
  • compare.mjs --steps 60 --seed 31 --only cors agrees, and the OAuth endpoints' own OPTIONS answers still do; just quick passes here.
  • just gates is left to the pull's gates workflow.

Shortcomings

  • bsky.app also needs the account's DID resolvable through plc.directory and an AppView configured. A server on a private PLC, as the staging one is, still won't work in bsky.app.
Approved

This adds a router-level CORS layer (cors.rs). OAuth paths pass through to their own CORS. Any OPTIONS gets a 204 preflight with the listed headers. Every other answer gets Access-Control-Allow-Origin: *. The pull also adds the "Browsers" section to spec/PDS.md and a cors harness step that compares status, all Access-Control-* headers, Vary and body emptiness against the reference.

  • Spec and code agree. The spec's header values, the "no rate limit, no RateLimit-*, not forwarded" claim and the OAuth path list all match the layer.
  • Harness. The check compares against the reference and loosens nothing. It is added to the step list with a weight.
  • Source rules. No source or crates from the reference or an SDK are used.
  • conformance.yaml. The pull doesn't touch it.
  • README. It has no mention of CORS. If it lists what the server answers, one line on browser access would fit. I wouldn't hold the pull for that.
  • Checks. The gates run was still running when I looked, so I couldn't read a result.
Merged as e184912