-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(hmac-auth) use ngx var request_uri instead uri #3339
Conversation
c9cbf3c
to
738af76
Compare
738af76
to
524eef2
Compare
lgtm |
assert.res_status(200, res) | ||
end) | ||
|
||
it("should pass with GET with request-line having encoded query param", function() |
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.
what do we mean here by "encoded"? The below tests don't URL-encode the querystring which has an (invalid) space character.
If you wish to test a URL-encoded value, you have to encode it yourself (:send()
doesn't do it for you)
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.
(It is a good idea to test this btw, because $request_uri
will return the raw, encoded, URL, while other variables or APIs may not, so we definitely should test this 👍)
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.
Thanks @thibaultcha, I made bad assumption. I have encoded the parameters now.
assert.res_status(200, res) | ||
end) | ||
|
||
it("should pass with GET with request-line having encode path param", function() |
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.
ditto
524eef2
to
eb7d77a
Compare
it("should pass with GET with request-line having encoded query param", function() | ||
local date = os.date("!%a, %d %b %Y %H:%M:%S GMT") | ||
local escaped_uri = fmt("/request?name=foo bar", | ||
ngx.escape_uri("foo bar")) |
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.
That won't work, the template string should contain %s
in lieu of the hard-coded argument
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.
Indeed, I am blind, fixed now.
`ngx.var.uri` is normalized and so `ngx.var.request_uri` should be used to get request origional uri with arguments
eb7d77a
to
fd0fb89
Compare
it("should pass with GET with request-line having encoded query param", function() | ||
local date = os.date("!%a, %d %b %Y %H:%M:%S GMT") | ||
local escaped_uri = fmt("/request?name=%s", | ||
ngx.escape_uri("foo bar")) |
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.
btw, we could use ngx.encode_args()
here, but that's fine
`ngx.var.uri` is normalized and so `ngx.var.request_uri` should be used to get the request original URI with arguments and preserved percent-encoding. From Kong#3339
Fix PR Kong#3339 by adding support for older signatures generated from `request-line` without the query_string. To reduce performance impact, calculate the new signature version first. Only if that first validation fails, try again with the deprecated signing function.
Since #3339, signatures must be generated with querystring arguments. This is breaking for many clients still relying on the signature mechanism. This patch adds support for a fallback to the old signature generation (without querystring arguments) when the newer signature verification fails. Fix #3672 From #3699
Summary
ngx.var.uri
is normalized and songx.var.request_uri
should beused to get request origional uri with arguments
Full changelog
get original request uri