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

Fix handling of encoded slash in url path #302

Merged
merged 5 commits into from
Dec 17, 2023

Conversation

jfraudeau
Copy link
Contributor

@jfraudeau jfraudeau commented Sep 20, 2023

Currently url encoded forward slash is decoded before the routing logic is applied. This is a problem when we want to allow arbitrary user data to be passed as a path segment.

For example /test/some%2Fdata/path will be routed as /test/some/data/path it thus becomes impossible to have a forward slash in a captured path segment.

This fix bypasses the broken rountrip of intercalate "/" <-> split (=='/')

@ocramz
Copy link
Collaborator

ocramz commented Sep 24, 2023

@jfraudeau Thank you! Could you please add a test for this as well?

@jfraudeau
Copy link
Contributor Author

@ocramz I added a test, let me know if anything else is missing or if there ara conventions I didn't follow

@ocramz
Copy link
Collaborator

ocramz commented Sep 25, 2023

Thank you @jfraudeau , it looks good but I'd like to merge it after #303 and make it use captureParam instead. What do you think?

@jfraudeau
Copy link
Contributor Author

Yes no problem, do as you see fit

@ocramz ocramz self-assigned this Sep 26, 2023
@ocramz ocramz mentioned this pull request Oct 3, 2023
3 tasks
@jfraudeau
Copy link
Contributor Author

Thank you @jfraudeau , it looks good but I'd like to merge it after #303 and make it use captureParam instead. What do you think?

Hi @ocramz I updated the pr to with upstream changes. Let me know if anything is still blocking

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @jfraudeau for sleeping on this. Thanks! 👍

@@ -115,7 +115,7 @@ matchRoute :: RoutePattern -> Request -> Maybe [Param]
matchRoute (Literal pat) req | pat == path req = Just []
| otherwise = Nothing
matchRoute (Function fun) req = fun req
matchRoute (Capture pat) req = go (T.split (=='/') pat) (compress $ T.split (=='/') $ path req) []
matchRoute (Capture pat) req = go (T.split (=='/') pat) (compress $ T.fromStrict <$> "":pathInfo req) [] -- add empty segment to simulate being at the root
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I'm not so sure I like a corner case to be encoded in this function.

Is this issue a special case of capture parameters not being url-decoded first? see #262

@ocramz ocramz merged commit e036cbc into scotty-web:master Dec 17, 2023
5 checks passed
@jfraudeau jfraudeau deleted the fix-encoded-slash-in-path branch December 18, 2023 13:28
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 this pull request may close these issues.

2 participants