-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: prerendering encodes url multiple times #3339
Conversation
to prevent encoding the redirect url multiple times
|
✔️ Deploy Preview for kit-demo canceled. 🔨 Explore the source changes: d77e6a0 🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61e3f29f54ea5200086837a5 |
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.
Thank you — comments inline. Please remember to add a changeset :)
log.warn(`${rendered.status} ${decoded_path} -> ${location}`); | ||
writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${encodeURI(location)}">`); | ||
writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${url.toString()}">`); |
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 should probably just be location
?
writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${url.toString()}">`); | |
writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${location}">`); |
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'm not sure why it was originally set to encodeURI
. I didn't want to break it so I first convert it to an URL
object.
Is it possible that a unencoded url reaches this part? I think yes, so we can't use location
here.
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.
Spelunking through the git history led me here: #256
I think we need to escape the string, so that this doesn't cause havoc...
location: "><script>alert('pwned')</script>
...but it seems like encodeURI
was probably the wrong choice.
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.
location: "><script>alert('pwned')</script>
This will no longer be a problem because it is an invalid URL. The code will throw an error
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 is a valid (unencoded) URL:
https://example.com/"><script>alert('pwned')</script>
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.
and with this implementation, this would output the url as:
"https://example.com/%22%3E%3Cscript%3Ealert('pwned')%3C/script%3E"
this is a deeply stupid consequence of the lack of an Lines 13 to 24 in 9de8094
|
I will address the comments in the next days! |
Thank you. I think we can do this more simply by just escaping the attribute — I've opened #3456, will close this |
Currently the
prerendering
of SvelteKit will take the url from a redirect and pass it to theencodeURI
function. This causes url parts e.g. query strings that are already encoded to be encoded a second time which may lead to incorrect urls.This PR fixes that issue. Redirect urls only get encoded a single time.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0