-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correctly allow redirects to external URLs #5005
Conversation
📊 Benchmark resultsComparing with 1e5f8b0 Package size: 222 MB(no change)
Legend
|
@@ -70,7 +70,7 @@ const proxyToExternalUrl = function ({ dest, destURL, req, res }) { | |||
pathRewrite: () => destURL, | |||
...(Buffer.isBuffer(req.originalBody) && { buffer: toReadableStream(req.originalBody) }), | |||
}) | |||
return handler(req, res, {}) | |||
return handler(req, res, () => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only noticed this because a request was not matching and http-proxy-rewrite was actually calling next
(the third parameter)
next is not a function
@@ -185,7 +185,7 @@ const serveRedirect = async function ({ match, options, proxy, req, res }) { | |||
|
|||
const staticFile = await getStatic(decodeURIComponent(reqUrl.pathname), options.publicFolder) | |||
if (staticFile) { | |||
req.url = encodeURIComponent(staticFile) + reqUrl.search | |||
req.url = encodeURI(staticFile) + reqUrl.search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes a problem where static URLs are escaped to %2Findex.html
. This was introduced in #2665 but even now after changing the to escapeUri
the tests still work.
body: 'param=value', | ||
followRedirect: false, | ||
}), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just replaced with got instead of custom HTTP request.
t.is(response3, '<html><h1>not-foo') | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are all duplicates and are actually also in 500.command.dev.test.js
checked by comparing the two files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
The commit message is of type fix
& mentions fix
again in the commit body. It can just be fix: redirects to external URLs
Everything else LGTM.
About the commit message, it is true that the commit message on its own sounds weird with the double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Nice catch on the duplicate tests. Weird that they were in the repo for so long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* fix: fix redirects to external URLs * chore: fix nit from review Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
🎉 Thanks for submitting a pull request! 🎉
Summary
#4109 change the behavior so that every redirect to an external URL was actually executed as a rewrite. The tests only checked the response body which is identical no matter if redirect or rewrite.
This is now fixed and the tests adapted to actually check if a redirect is happening.
Fixes #2710
Fixes #1242