diff options
author | 2023-04-04 15:48:28 +0200 | |
---|---|---|
committer | 2023-04-04 15:48:28 +0200 | |
commit | 4cc1bf61b832dba9aab1916b56f5260ceac2d97d (patch) | |
tree | 58da283fba308ca9b25653f03f14e8c0f39f3c8d /packages/integrations/node/test/bad-urls.test.js | |
parent | 1ec1df12641290ec8b3a417a6284fd8d752c02bf (diff) | |
download | astro-4cc1bf61b832dba9aab1916b56f5260ceac2d97d.tar.gz astro-4cc1bf61b832dba9aab1916b56f5260ceac2d97d.tar.zst astro-4cc1bf61b832dba9aab1916b56f5260ceac2d97d.zip |
fix(node): Fix malformed URLs crashing the server in certain cases (#6746)
Diffstat (limited to 'packages/integrations/node/test/bad-urls.test.js')
-rw-r--r-- | packages/integrations/node/test/bad-urls.test.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/integrations/node/test/bad-urls.test.js b/packages/integrations/node/test/bad-urls.test.js new file mode 100644 index 000000000..24a6e7747 --- /dev/null +++ b/packages/integrations/node/test/bad-urls.test.js @@ -0,0 +1,46 @@ +import { expect } from 'chai'; +import nodejs from '../dist/index.js'; +import { loadFixture } from './test-utils.js'; + +describe('API routes', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + let devPreview; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/bad-urls/', + output: 'server', + adapter: nodejs({ mode: 'standalone' }), + }); + await fixture.build(); + devPreview = await fixture.preview(); + }); + + after(async () => { + await devPreview.stop(); + }); + + it('Does not crash on bad urls', async () => { + const weirdURLs = [ + '/\\xfs.bxss.me%3Fastrojs.com/hello-world', + '/asdasdasd@ax_zX=.zxczasđ„%/Ășadasd000%/', + '%', + '%80', + '%c', + '%c0%80', + '%20foobar%', + ]; + + for (const weirdUrl of weirdURLs) { + const fetchResult = await fixture.fetch(weirdUrl); + expect([400, 500]).to.include( + fetchResult.status, + `${weirdUrl} returned something else than 400 or 500` + ); + } + const stillWork = await fixture.fetch('/'); + const text = await stillWork.text(); + expect(text).to.equal('<!DOCTYPE html>\nHello!'); + }); +}); |