From d613cc180141100c6bfb9de0b4e64bdf0dbb7a0e Mon Sep 17 00:00:00 2001 From: Regalijan Date: Thu, 12 Mar 2026 02:58:02 -0400 Subject: [PATCH] Fix envelope header parsing --- functions/api/st.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/functions/api/st.ts b/functions/api/st.ts index 87b33c9..584e808 100644 --- a/functions/api/st.ts +++ b/functions/api/st.ts @@ -1,13 +1,19 @@ import { jsonError } from "../common.js"; export async function onRequestPost(context: RequestContext) { - const dsn = context.request.headers.get("dsn"); + const clonedRequest = context.request.clone(); + const header = (await context.request.text()).split("\n").at(0); - if (!dsn || dsn !== context.env.DSN) return jsonError("Bad or no DSN", 400); + if (!header) return jsonError("Failed to parse envelope header", 500); + + const { dsn } = JSON.parse(header); + + if (context.env.DSN !== dsn) return jsonError("Bad or no DSN", 400); const sentryUrl = new URL(dsn); + await fetch(`https://${sentryUrl.host}/api${sentryUrl.pathname}/envelope`, { - body: context.request.body, + body: clonedRequest.body, headers: { "content-type": "application/x-sentry-envelope", "x-forwarded-for": context.request.headers.get(