From d98694de91257f8a8572886f58840e4caa48bbf5 Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Mon, 20 Feb 2023 16:35:27 +0000 Subject: [PATCH] add auth to status deletion --- backend/src/middleware/main.ts | 93 ++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/backend/src/middleware/main.ts b/backend/src/middleware/main.ts index 441687a..b77cd74 100644 --- a/backend/src/middleware/main.ts +++ b/backend/src/middleware/main.ts @@ -45,11 +45,12 @@ export async function main(context: EventContext) { return new Response('', { headers }) } - const url = new URL(context.request.url) + const request = context.request + const url = new URL(request.url) + if ( url.pathname === '/oauth/token' || url.pathname === '/oauth/authorize' || // Cloudflare Access runs on /oauth/authorize - /^\/api\/v1\/statuses\/.*(?) { url.pathname.startsWith('/ap/') // all ActivityPub endpoints ) { return context.next() - } else { - try { - const authorization = context.request.headers.get('Authorization') || '' - const token = authorization.replace('Bearer ', '') + } - if (token === '') { - return errors.notAuthorized('missing authorization') - } + if (/^\/api\/v1\/statuses\/.*(?