Skip to content

fix: DSN token precedence — prefer Bearer, parse URL-shaped dsn (fixes #1) - #3

Closed
yzzztech wants to merge 2 commits into
mainfrom
fix/dsn-token-precedence
Closed

fix: DSN token precedence — prefer Bearer, parse URL-shaped dsn (fixes #1)#3
yzzztech wants to merge 2 commits into
mainfrom
fix/dsn-token-precedence

Conversation

@yzzztech

Copy link
Copy Markdown
Owner

Fix: DSN token precedence — prefer Bearer, parse URL-shaped dsn

Fixes #1

Problem

When a client sends the full DSN URL (e.g. http://TOKEN@host:3456/api/ingest/PROJECT_ID) in the JSON body's dsn field — which the official Claude Code hook does — the full URL string shadows the Bearer token. The Prisma lookup fails because it searches for the full URL as if it were a token.

Result: all Claude Code events are silently dropped with 401 Invalid DSN token.

Fix

// Before: dsn || bearerToken
// After:  bearerToken || token_from_url || plain_dsn

let dsnFromUrl: string | undefined;
if (rawDsn?.includes("@")) {
  const match = rawDsn.match(/:\\/\\/([^@]+)@/);
  dsnFromUrl = match?.[1];
}
const dsnToken = bearerToken || dsnFromUrl || rawDsn;

Precedence

  1. Bearer header (strongest — explicit auth)
  2. Token extracted from DSN URL (http://TOKEN@host/...)
  3. Plain DSN token (backward compatible)

Tested

# Full DSN URL → works
DSN="http://TOKEN@localhost:3456/api/ingest/PROJECT"
curl -H "Content-Type: application/json" -d "{\"dsn\":\"$DSN\",\"batch\":[...]}" ...

# Plain token → still works (backward compat)
curl -H "Content-Type: application/json" -d "{\"dsn\":\"TOKEN\",\"batch\":[...]}" ...

# Bearer → still works
curl -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d "{\"batch\":[...]}" ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ingest endpoint silently rejects valid DSN tokens when full DSN URL is in body

1 participant