Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cors-authorization-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@getcirrus/pds": patch
---

Allow the `Authorization` header in cross-origin requests. Browser clients sending a bearer token were previously blocked at CORS preflight in Firefox and Safari.
2 changes: 1 addition & 1 deletion packages/pds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ app.use(
cors({
origin: "*",
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allowHeaders: ["*"],
// Note: No allowHeaders; using "*" wildcard doesn't cover Authorization, so let Hono reflect the requested headers instead
exposeHeaders: ["Content-Type"],
maxAge: 86400,
}),
Expand Down
25 changes: 25 additions & 0 deletions packages/pds/test/cors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { env, worker } from "./helpers";

describe("CORS preflight", () => {
it("reflects the Authorization header back in Access-Control-Allow-Headers", async () => {
const response = await worker.fetch(
new Request(
`http://pds.test/xrpc/com.atproto.server.getSession`,
{
method: "OPTIONS",
headers: {
Origin: "https://example.com",
"Access-Control-Request-Method": "GET",
"Access-Control-Request-Headers": "authorization",
},
},
),
env,
);

expect(response.headers.get("Access-Control-Allow-Headers")).toContain(
"authorization",
);
});
});