-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
req.url: fixed consistency with Fastly implementation #262
Conversation
Could you please provide an example of how Falco deviates from fastly on this? A Fiddle vs a falco vcl test case for example. |
This fiddle demonstrates fastly behavior: https://fiddle.fastly.dev/fiddle/86d69ef4
As you can see all req.url fields maintains the original encoding.
and run it in the debugger: falco simulate -debug main.vcl Send test http request: curl -Ss 'http://localhost:3124/d%69rname/ba%73e+name.extensi%6Fn' And then when the execution breaks into debugger just manually url components while watching the output:
Note that as opposed to Fastly behavior all url components come out decoded. Also falco behavior can be demonstrated with this test case (sorry for some reason I am unable to attach it as a file):
Save it to 'main.test.vcl' file (no need for main.vcl as it never gets called) and then run:
The test fails with this message:
This test demonstrates that the decoding actually happens when the internal representation of url.path is accessed and converted to string. |
Thank you for the details. So this is an interesting case; these changes do fix a consistency issue but also break an edge case where we're currently compatible with Fastly. Fastly allows you to set set req.url = "/a b";
log req.url; // yields `/a b` not `/a%20b` Granted we're only compatible with this edge case by way of an accident but still worth maintaining. It should be pretty straightforward to retain compatibility by comparing the result of Something along the lines of: u := req.URL.EscapedPath()
if req.URL.RawPath != "" && u != req.url.RawPath {
u = req.URL.RawPath
} |
- fixed one more code occurrence
@richardmarshall thanks for your advice. I amended code responsible for accessing url raw path as you suggested and this took care of space character handling. One case that is still not covered is when assigned URL value contains invalid URL encoding (and probably any malformed URL). Fixing this in Falco will require deeper changes so I am holding for now. |
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.
Overall looks good. Just one typo and a linter issue that need fixing.
Regarding the invalid escape sequence issue I agree that it can be dealt with separately.
There is a similarity in behavior of req.url and querystring function family (see #264). From what I can see from Fastly behavior req.url handling shares the same implementation as querystring functions, at least in the sense that they both avoid full URL parsing. Perhaps the same code can be used for both. |
Thanks both, I've just caught up on the implementation and discussions - understanding |
Fastly implementation of req.url, req.url.path, req.url.basename and req.url.ext returns the raw version of these values while falco returns urldecoded versions.
This PR fixes this inconsistency