Skip to content

Commit feae0ed

Browse files
committed
fix(core): Normalize allowedDsns like the envelope header's DSN, so one written with a secret key still matches
1 parent 994cab5 commit feae0ed

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎packages/core/src/utils/tunnel.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,12 @@ export function resolveAllowedDsns(
388388
allowedDsns: Array<string> | undefined,
389389
ownDsn: DsnComponents | undefined,
390390
): Array<string> {
391-
const dsns = new Set(allowedDsns);
392-
if (ownDsn) {
393-
dsns.add(dsnToString(ownDsn));
391+
// Normalized like the envelope header's DSN, which has no secret key.
392+
const dsns = new Set<string>();
393+
for (const components of [...(allowedDsns ?? []).map(dsn => makeDsn(dsn)), ownDsn]) {
394+
if (components) {
395+
dsns.add(dsnToString(components));
396+
}
394397
}
395398

396399
return [...dsns];

‎packages/core/test/lib/utils/tunnel.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,30 @@ describe('handleTunnelRequest', () => {
280280
expect(fetchMock).not.toHaveBeenCalled();
281281
});
282282

283-
it('returns 403 when the DSN string cannot be parsed into components', async () => {
283+
it('ignores an allowed DSN that cannot be parsed', async () => {
284284
const malformedDsn = 'not-a-valid-dsn';
285285

286286
const result = await handleTunnelRequest({
287287
request: makeEnvelopeRequest({ dsn: malformedDsn }),
288288
allowedDsns: [malformedDsn],
289289
});
290290

291-
expect(result).toBeInstanceOf(Response);
292-
expect(result.status).toBe(403);
293-
expect(await result.text()).toBe('Invalid DSN');
291+
expect(result.status).toBe(500);
294292
expect(fetchMock).not.toHaveBeenCalled();
295293
});
296294

295+
it('matches an allowed DSN written with a secret key, which the envelope header leaves out', async () => {
296+
fetchMock.mockResolvedValueOnce(new Response('ok', { status: 200 }));
297+
298+
const result = await handleTunnelRequest({
299+
request: makeEnvelopeRequest({ dsn: TEST_DSN }),
300+
allowedDsns: [TEST_DSN.replace('@', ':secret@')],
301+
});
302+
303+
expect(result.status).toBe(200);
304+
expect(fetchMock).toHaveBeenCalledOnce();
305+
});
306+
297307
it('forwards the envelope when multiple DSNs are configured', async () => {
298308
const otherDsn = 'https://other@example.com/9999';
299309
const upstreamResponse = new Response('ok', { status: 200 });

0 commit comments

Comments
 (0)