-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): Fix malformed URLs crashing the server in certain cases (#…
- Loading branch information
1 parent
1ec1df1
commit 4cc1bf6
Showing
7 changed files
with
97 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/node': patch | ||
--- | ||
|
||
Fix malformed URLs crashing the server in certain cases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/node/test/fixtures/bad-urls/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/nodejs-badurls", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/node": "workspace:*" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/integrations/node/test/fixtures/bad-urls/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello! |
Oops, something went wrong.