Skip to content

Commit 5216117

Browse files
authored
fix(request-id): validation accepts = (#4478)
1 parent 253ec28 commit 5216117

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/middleware/request-id/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ describe('Request ID Middleware', () => {
2929
expect(await res.text()).toBe('hono-is-hot')
3030
})
3131

32+
it('Should return custom request id with all valid characters', async () => {
33+
const validRequestId = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_='
34+
const res = await app.request('http://localhost/requestId', {
35+
headers: {
36+
'X-Request-Id': validRequestId,
37+
},
38+
})
39+
expect(res).not.toBeNull()
40+
expect(res.status).toBe(200)
41+
expect(res.headers.get('X-Request-Id')).toBe(validRequestId)
42+
expect(await res.text()).toBe(validRequestId)
43+
})
44+
3245
it('Should return random request id without using request header', async () => {
3346
const res = await app.request('http://localhost/requestId', {
3447
headers: {

src/middleware/request-id/request-id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const requestId = ({
4646
return async function requestId(c, next) {
4747
// If `headerName` is empty string, req.header will return the object
4848
let reqId = headerName ? c.req.header(headerName) : undefined
49-
if (!reqId || reqId.length > limitLength || /[^\w\-]/.test(reqId)) {
49+
if (!reqId || reqId.length > limitLength || /[^\w\-=]/.test(reqId)) {
5050
reqId = generator(c)
5151
}
5252

0 commit comments

Comments
 (0)