Unverified Commit 6d98b4fb authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure invalid URLs respond with 400 correctly (#32092)

This ensures we catch any errors in `handleRequest` so that we can respond with a 400 for invalid requests. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/32075
Closes: https://github.com/vercel/next.js/pull/32080
parent 1c199a5e
import { platform, arch } from 'os' import { platform, arch } from 'os'
import { platformArchTriples } from '@napi-rs/triples' import { platformArchTriples } from '@napi-rs/triples'
import Log from '../output/log' import * as Log from '../output/log'
const ArchName = arch() const ArchName = arch()
const PlatformName = platform() const PlatformName = platform()
......
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* global browserName */ /* global browserName */
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import http from 'http'
import url from 'url' import url from 'url'
import { join } from 'path' import { join } from 'path'
import { import {
...@@ -27,6 +28,32 @@ async function checkInjected(browser) { ...@@ -27,6 +28,32 @@ async function checkInjected(browser) {
module.exports = (context) => { module.exports = (context) => {
describe('With Security Related Issues', () => { describe('With Security Related Issues', () => {
it('should handle invalid URL properly', async () => {
async function invalidRequest() {
return new Promise((resolve, reject) => {
const request = http.request(
{
hostname: `localhost`,
port: context.appPort,
path: `*`,
},
(response) => {
resolve(response.statusCode)
}
)
request.on('error', (err) => reject(err))
request.end()
})
}
try {
expect(await invalidRequest()).toBe(400)
expect(await invalidRequest()).toBe(400)
} catch (err) {
// eslint-disable-next-line
expect(err.code).toBe('ECONNREFUSED')
}
})
it('should only access files inside .next directory', async () => { it('should only access files inside .next directory', async () => {
const buildId = readFileSync(join(__dirname, '../.next/BUILD_ID'), 'utf8') const buildId = readFileSync(join(__dirname, '../.next/BUILD_ID'), 'utf8')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment