Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: honojs/node-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.0
Choose a base ref
...
head repository: honojs/node-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.1
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 21, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dd9b9a9 View commit details
  2. v1.4.1

    yusukebe committed Jan 21, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    69dd54a View commit details
Showing with 28 additions and 2 deletions.
  1. +1 −1 package.json
  2. +8 −1 src/request.ts
  3. +1 −0 test/assets/secret.txt
  4. +13 −0 test/request.test.ts
  5. +5 −0 test/serve-static.test.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hono/node-server",
"version": "1.4.0",
"version": "1.4.1",
"description": "Node.js Adapter for Hono",
"main": "dist/index.js",
"types": "dist/index.d.ts",
9 changes: 8 additions & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

import type { IncomingMessage } from 'node:http'
import type { Http2ServerRequest } from 'node:http2'
import { resolve } from 'node:path'
import { Readable } from 'node:stream'

const newRequestFromIncoming = (
@@ -41,7 +42,13 @@ const requestPrototype: Record<string | symbol, any> = {
},

get url() {
return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`
let path = this[incomingKey]['path']
if (!path) {
const originalPath = this[incomingKey].url
path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath
this[incomingKey]['path'] = path
}
return `http://${this[incomingKey].headers.host}${path}`
},

[getRequestCache]() {
1 change: 1 addition & 0 deletions test/assets/secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret
13 changes: 13 additions & 0 deletions test/request.test.ts
Original file line number Diff line number Diff line change
@@ -17,4 +17,17 @@ describe('Request', () => {
expect(req.url).toBe('http://localhost/')
expect(req.headers.get('host')).toBe('localhost')
})

it('Should resolve double dots in URL', async () => {
const req = newRequest({
headers: {
host: 'localhost',
},
url: '/static/../foo.txt',
} as IncomingMessage)
expect(req).toBeInstanceOf(global.Request)
expect(req.url).toBe('http://localhost/foo.txt')
// Check if cached value is returned correctly
expect(req.url).toBe('http://localhost/foo.txt')
})
})
5 changes: 5 additions & 0 deletions test/serve-static.test.ts
Original file line number Diff line number Diff line change
@@ -129,4 +129,9 @@ describe('Serve Static Middleware', () => {
'./not-found/on-not-found/foo.txt is not found, request to /on-not-found/foo.txt'
)
})

it('Should handle double dots in URL', async () => {
const res = await request(server).get('/static/../secret.txt')
expect(res.status).toBe(404)
})
})