|
1 | | -import {canProxyRequest, getProxyStorefrontHeaders, injectCdnProxy, patchRenderingResponse} from './proxy.js' |
| 1 | +import { |
| 2 | + canProxyRequest, |
| 3 | + getProxyStorefrontHeaders, |
| 4 | + injectCdnProxy, |
| 5 | + patchRenderingResponse, |
| 6 | + proxyStorefrontRequest, |
| 7 | +} from './proxy.js' |
2 | 8 | import {describe, test, expect} from 'vitest' |
3 | 9 | import {createEvent} from 'h3' |
4 | 10 | import {IncomingMessage, ServerResponse} from 'node:http' |
@@ -338,4 +344,18 @@ describe('dev proxy', () => { |
338 | 344 | expect(canProxyRequest(event)).toBeTruthy() |
339 | 345 | }) |
340 | 346 | }) |
| 347 | + describe('proxyStorefrontRequest', () => { |
| 348 | + test('should reject hostname mismatch and throw error for non-CDN paths (SSRF protection)', async () => { |
| 349 | + const event = createH3Event('GET', '//evil.com/some-path') |
| 350 | + await expect(proxyStorefrontRequest(event, ctx)).rejects.toThrow( |
| 351 | + 'Request failed: Hostname mismatch. Expected host: my-store.myshopify.com. Resulting URL hostname: evil.com', |
| 352 | + ) |
| 353 | + }) |
| 354 | + test('should reject hostname mismatch and throw error for CDN paths (SSRF protection)', async () => { |
| 355 | + const event = createH3Event('GET', '/ext/cdn//evil.com/some-path') |
| 356 | + await expect(proxyStorefrontRequest(event, ctx)).rejects.toThrow( |
| 357 | + 'Request failed: Hostname mismatch. Expected host: cdn.shopify.com. Resulting URL hostname: evil.com', |
| 358 | + ) |
| 359 | + }) |
| 360 | + }) |
341 | 361 | }) |
0 commit comments