Skip to content
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

Revert URL encoding or check if the URL is already encoded. #1484

Closed
jleach opened this issue Jun 14, 2023 · 0 comments · Fixed by #1485
Closed

Revert URL encoding or check if the URL is already encoded. #1484

jleach opened this issue Jun 14, 2023 · 0 comments · Fixed by #1485

Comments

@jleach
Copy link
Contributor

jleach commented Jun 14, 2023

I think the issue I fixed in #1479 which was to protect agains spaces or other forbidden characters in tailsLocation has an edge case that is just as problematic. The fn encodeURI will re-encode a URI if it fines a % in it already. This can result in erroneous results and may be more problematic. To fix we can either remove the call to encodeURI added in #1479 or do a quick check to make sure its not already encoded:

Here is an example of the problem. Every time encodeURL is run the query string gets the % re-encoded as %25:

> const url = 'http://foo.example.com?name=Jason Leach'
undefined
> encodeURI(url)
'http://foo.example.com?name=Jason%20Leach'
> encodeURI(encodeURI(url))
'http://foo.example.com?name=Jason%2520Leach'
> encodeURI(encodeURI(encodeURI(url)))
'http://foo.example.com?name=Jason%252520Leach'
> url === decodeURI(encodeURI(url))
true

I can add a quick check like this:

isEncoded = (uri: string) => {
  const aUri = uri ?? ''
  return aUri !== decodeURI(aUri)
}

Results in:

> const isEncoded = (uri) => {
... const aUri = uri ?? ''
... return aUri !== decodeURI(aUri)
... }
undefined
> isEncoded(encodeURI(url))
true
> isEncoded(decodeURI(encodeURI(url)))
false
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant