Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"why-is-node-running": "^3.2.2"
},
"dependencies": {
"@fastify/reply-from": "^12.6.2",
"@fastify/reply-from": "^12.8.1",
"fast-querystring": "^1.1.2",
"fastify-plugin": "^6.0.0",
"ws": "^8.18.3"
Expand Down
11 changes: 6 additions & 5 deletions test/http-prefix-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ test('HTTP paths cannot escape rewritePrefix', async t => {
t.assert.strictEqual(regular.statusCode, 200)
t.assert.strictEqual(regular.body, 'internal:/internal/foo')

// @fastify/reply-from rejects decoded backslashes in the destination path
// since v12.8.1, so a percent-encoded backslash is no longer forwarded.
const encodedBackslash = await request(port, '/pub/foo%5Cbar')
t.assert.strictEqual(encodedBackslash.statusCode, 200)
t.assert.strictEqual(encodedBackslash.body, 'internal:/internal/foo%5Cbar')
t.assert.strictEqual(encodedBackslash.statusCode, 400)
})

test('HTTP paths are validated against a dynamic upstream once per request', async t => {
Expand Down Expand Up @@ -166,10 +167,10 @@ test('reply.fromParameters cannot escape rewritePrefix', async t => {
t.assert.strictEqual(regular.statusCode, 200)
t.assert.strictEqual(regular.body, 'internal:/internal/foo')

// Negative control: a percent-encoded backslash used as benign path data must still proxy.
// @fastify/reply-from rejects decoded backslashes in the destination path
// since v12.8.1, so a percent-encoded backslash is no longer forwarded.
const encodedBackslash = await request(port, '/pub/foo%5Cbar')
t.assert.strictEqual(encodedBackslash.statusCode, 200)
t.assert.strictEqual(encodedBackslash.body, 'internal:/internal/foo%5Cbar')
t.assert.strictEqual(encodedBackslash.statusCode, 400)
})

test('HTTP request with a falsy dynamic upstream falls back to the default validation host', async t => {
Expand Down
13 changes: 8 additions & 5 deletions test/ws-prefix-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function proxyServer (t, backendURL, backendPath, proxyOptions, wrapperOpt
}
}

async function processRequest (t, frontendURL, path, expected) {
async function processRequest (t, frontendURL, path, expected, httpExpected = expected) {
const url = new URL(path, frontendURL)
const wsUrl = url.href.replace('http:', 'ws:')
const ws = new WebSocket(wsUrl)
Expand Down Expand Up @@ -114,10 +114,10 @@ async function processRequest (t, frontendURL, path, expected) {
}

t.assert.strictEqual(wsResult, expected)
t.assert.strictEqual(gotResult, expected)
t.assert.strictEqual(gotResult, httpExpected)
}

async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions }, expected, ...paths) {
async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions, httpExpected }, expected, ...paths) {
test(info, async function (t) {
const backend = Fastify({ logger: { level } })
const resources = { frontend: null }
Expand Down Expand Up @@ -149,7 +149,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions },
resources.frontend = frontend

for (const path of paths) {
await processRequest(t, frontendURL, path, expected(path))
await processRequest(t, frontendURL, path, expected(path), httpExpected ? httpExpected(path) : expected(path))
}
})
}
Expand Down Expand Up @@ -221,7 +221,10 @@ handleProxy(
'percent-encoded backslashes remain path data',
{
backendPath: '/internal',
proxyOptions: { websocket: true, prefix: '/pub' }
proxyOptions: { websocket: true, prefix: '/pub' },
// Plain HTTP requests go through @fastify/reply-from, which rejects
// decoded backslashes in the destination path since v12.8.1.
httpExpected: () => 'error'
},
() => '/internal/foo%5C..bar',
'/pub/foo%5C..bar'
Expand Down
Loading