@alteran/astro 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alteran/astro",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Astro integration for running a Cloudflare-hosted Bluesky PDS with Alteran.",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,9 +16,9 @@ export const prerender = false;
16
16
  export async function POST({ locals, request }: APIContext) {
17
17
  const { env } = locals.runtime;
18
18
 
19
- // Enforce DPoP with nonce; if missing or stale, return use_dpop_nonce
19
+ // Enforce DPoP binding, but do not require a nonce on the initial PAR request.
20
20
  try {
21
- const ver = await verifyDpop(env, request, { consumeJti: false });
21
+ const ver = await verifyDpop(env, request, { consumeJti: false, requireNonce: false });
22
22
 
23
23
  // Parse form-encoded body
24
24
  const bodyText = await request.text();
@@ -12,7 +12,7 @@ export const prerender = false;
12
12
  export async function POST({ locals, request }: APIContext) {
13
13
  const { env } = locals.runtime;
14
14
  try {
15
- const dpop = await verifyDpop(env, request, { consumeJti: false });
15
+ const dpop = await verifyDpop(env, request, { consumeJti: false, requireNonce: false });
16
16
  const form = new URLSearchParams(await request.text());
17
17
  const token = form.get('token') || '';
18
18
  const client_id = form.get('client_id') || '';
@@ -25,7 +25,7 @@ export async function POST({ locals, request }: APIContext) {
25
25
  const { env } = locals.runtime;
26
26
 
27
27
  try {
28
- const ver = await verifyDpop(env, request, { consumeJti: false });
28
+ const ver = await verifyDpop(env, request, { consumeJti: false, requireNonce: false });
29
29
  const form = new URLSearchParams(await request.text());
30
30
  const grant_type = form.get('grant_type') || '';
31
31
  const issuer = publicPdsOrigin(env, request);
@@ -140,20 +140,27 @@ export function createPdsFetchHandler(options?: CreatePdsFetchHandlerOptions): P
140
140
  }
141
141
 
142
142
  const astroFetch = await getAstroFetch(options);
143
- const response = await astroFetch(normalizeXrpcRequestForAstro(request), resolvedEnv as any, ctx);
143
+ const response = await astroFetch(normalizePdsRequestForAstro(request), resolvedEnv as any, ctx);
144
144
  return response as unknown as WorkersResponse;
145
145
  };
146
146
  }
147
147
 
148
- export function normalizeXrpcRequestForAstro(request: WorkersRequest): WorkersRequest {
148
+ const OAUTH_BACKCHANNEL_PATHS = new Set([
149
+ '/oauth/par',
150
+ '/oauth/token',
151
+ '/oauth/revoke',
152
+ ]);
153
+
154
+ export function normalizePdsRequestForAstro(request: WorkersRequest): WorkersRequest {
149
155
  const url = new URL(request.url);
150
- if (!url.pathname.startsWith('/xrpc/')) {
156
+ if (!url.pathname.startsWith('/xrpc/') && !OAUTH_BACKCHANNEL_PATHS.has(url.pathname)) {
151
157
  return request;
152
158
  }
153
159
 
154
160
  // Astro's SSR origin-check middleware rejects unsafe requests when Origin is
155
- // absent or cross-origin. XRPC is a bearer-token API, not cookie/form auth,
156
- // and atproto clients legitimately send bodyless POSTs from native runtimes.
161
+ // absent or cross-origin. XRPC and OAuth backchannel endpoints are token-bound
162
+ // APIs, not cookie/form auth, and atproto clients legitimately send them from
163
+ // native runtimes or separate origins. Browser consent POSTs stay protected.
157
164
  if (request.headers.get('origin') === url.origin) {
158
165
  return request;
159
166
  }
@@ -167,6 +174,8 @@ export function normalizeXrpcRequestForAstro(request: WorkersRequest): WorkersRe
167
174
  return new Request(request as any, { headers: headerRecord }) as unknown as WorkersRequest;
168
175
  }
169
176
 
177
+ export const normalizeXrpcRequestForAstro = normalizePdsRequestForAstro;
178
+
170
179
  type AstroFetchHandler = (
171
180
  request: WorkersRequest,
172
181
  env: Env,