Modify Origin header validation in validateRequestHeaders (streamableHttp.ts and sse.ts) to allow requests without an Origin, as they are not relevant to server DNS rebinding protection. (#1205)

This commit is contained in:
Jacopo Cappellato 2025-12-02 10:56:09 +01:00 • committed by GitHub
commit 608360047d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2678,6 +2678,29 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
const body = await response.json();
expect(body.error.message).toBe('Invalid Origin header: http://evil.com');
});
it('should accept requests without origin headers', async () => {
const result = await createTestServerWithDnsProtection({
sessionIdGenerator: undefined,
allowedOrigins: ['http://localhost:3000', 'https://example.com'],
enableDnsRebindingProtection: true
});
server = result.server;
transport = result.transport;
baseUrl = result.baseUrl;
const response = await fetch(baseUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream'
},
body: JSON.stringify(TEST_MESSAGES.initialize)
});
// Should pass even with no Origin headers because requests that do not come from browsers may not have Origin and DNS rebinding attacks can only be performed via browsers
expect(response.status).toBe(200);
});
});
describe('enableDnsRebindingProtection option', () => {