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(hmac-auth) use ngx var request_uri instead uri #3339

Merged
merged 1 commit into from
Mar 28, 2018
Merged

Conversation

shashiranjan84
Copy link
Contributor

Summary

ngx.var.uri is normalized and so ngx.var.request_uri should be
used to get request origional uri with arguments

Full changelog

  • signature generator logic now use ngx.var.request_uri to
    get original request uri

@kidd
Copy link
Contributor

kidd commented Mar 27, 2018

lgtm

assert.res_status(200, res)
end)

it("should pass with GET with request-line having encoded query param", function()
Copy link
Member

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)

Copy link
Member

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 👍)

Copy link
Contributor Author

@shashiranjan84 shashiranjan84 Mar 27, 2018

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()
Copy link
Member

Choose a reason for hiding this comment

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

ditto

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"))
Copy link
Member

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

Copy link
Contributor Author

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
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"))
Copy link
Member

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

@thibaultcha thibaultcha merged commit 1c80866 into master Mar 28, 2018
@thibaultcha thibaultcha deleted the fix/hmac-auth branch March 28, 2018 00:28
kikito pushed a commit to kikito/kong that referenced this pull request Apr 10, 2018
`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
mlehner616 added a commit to mlehner616/kong that referenced this pull request Aug 13, 2018
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.
thibaultcha pushed a commit that referenced this pull request Aug 17, 2018
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
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.

3 participants