Skip to content

Commit a564fc1

Browse files
v1rtlclaude
andcommitted
test: add malformed port test for x-forwarded-host
Add test that covers the Number.isNaN(port) branch in request.ts when x-forwarded-host header contains a non-numeric port value. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7b4c3ac commit a564fc1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/core/request.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,21 @@ describe('Request properties', () => {
561561
'hostname: forwarded.example.com'
562562
)
563563
})
564+
it('should throw error when x-forwarded-host has malformed port', async () => {
565+
const { fetch, app } = InitAppAndTest(
566+
(req, res) => {
567+
res.send(`hostname: ${req.hostname}, port: ${req.port}`)
568+
},
569+
'/',
570+
'GET',
571+
options
572+
)
573+
app.set('trust proxy', ['127.0.0.1', '::1', '::ffff:127.0.0.1'])
574+
575+
// Malformed port (non-numeric) should trigger error
576+
const response = await fetch('/', { headers: { 'x-forwarded-host': 'example.com:abc' } })
577+
expect(response.status).toBe(500)
578+
})
564579
it('should return undefined hostname when :authority header is an array', async () => {
565580
const { getRequestHeader }: typeof req = await vi.importActual('../../packages/req/src')
566581
vi.mocked(req.getRequestHeader).mockImplementation((r) => {

0 commit comments

Comments
 (0)