diff --git a/package.json b/package.json index 1f42424..f3c89b1 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/http-prefix-rewrite.js b/test/http-prefix-rewrite.js index cdc682a..295c67b 100644 --- a/test/http-prefix-rewrite.js +++ b/test/http-prefix-rewrite.js @@ -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 => { @@ -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 => { diff --git a/test/ws-prefix-rewrite.js b/test/ws-prefix-rewrite.js index 31de2d4..839ef74 100644 --- a/test/ws-prefix-rewrite.js +++ b/test/ws-prefix-rewrite.js @@ -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) @@ -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 } @@ -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)) } }) } @@ -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'