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

querystring made more consistent with Fastly #258

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akrainiouk
Copy link
Contributor

@akrainiouk akrainiouk commented Feb 15, 2024

  • falco implementation of querystring does not urlencode query parameter names which can produce invalid urls
  • Also falco implementation encodes space character with '+' which is inconsistent with Fastly. Fastly use %20 for space encoding.

@akrainiouk akrainiouk marked this pull request as ready for review February 15, 2024 22:46
@akrainiouk akrainiouk changed the title Consistency fix with Fastly: querysting fixed to URL encode keys and … querystring made more consistent with Fastly Feb 15, 2024
Copy link
Collaborator

@richardmarshall richardmarshall left a comment

Choose a reason for hiding this comment

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

Thanks. Fixing consistency issues with Fastly behavior is appreciated.

interpreter/function/shared/querystring.go Outdated Show resolved Hide resolved
@richardmarshall
Copy link
Collaborator

Did a bit of looking at the details of how Fastly handles query escapes with the querystring.* functions. From a non exhaustive check it seems like they're performing escaping only when setting values but not when reading them or performing other operations on them (filtering, sorting).

For example the following will log /?a=b+c&b=c%20d not /?a=b%20c&b%20c.

log querystring.set("/?a=b+c", "b", "c d");

Fiddle with a few more examples: https://fiddle.fastly.dev/fiddle/e019c129

If you're up to tackling investigating this further and incorporating the needed changes to the PR that would be great. If not we can create an issue to track the remaining work.

@akrainiouk
Copy link
Contributor Author

Hi Richard,
I am afraid we are opening a Pandora box :)
The problem of course is deeper than I attempted to address here. Current implementation first parses the source value into a structure then manipulates it and finally converts back to string. This however introduces several unwanted side effects such as grouping name value pairs (implied by underlying query structure), it also makes it hard to follow various Fastly quirks. For instance in some cases (e.g. sort) original '?' separator is preserved even if the query is empty, in other cases (filter) it is removed.
Another quirk is that sorting is applied to unsplit name=value pairs so that

querystring.sort({"?foo=one&foo>=too&foo<=three"})

returns

?foo<=three&foo=one&foo>=too

and not

?foo=one&foo<=three&foo>=two

as one might expect.
If you guys are interested, in this PR draft I provided an alternative implementation of querystring functions that do not try to pre-parse the source string and attempt to follow Fastly behavior as much as I can check.
I converted existing unit tests so that at least existing test cases are still valid and added some more (the behavior is more of less covered in this Fastly fiddle.

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