Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Eliminate content length check in requestSignature #5

Merged
merged 2 commits into from
Oct 13, 2015

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Oct 10, 2015

Turns out the content length may not be defined for all POST requests, and may
be 0 on the sending end and -1 on the receiving end, leading to signature
mismatches. The new TestSendAuthenticatedPostRequestToServer reproduces the
bug and validates its fix.

cc: @jcscottiii

Mike Bland added 2 commits October 9, 2015 20:34
Turns out the content length may not be defined for all POST requests, and may
be 0 on the sending end and -1 on the receiving end, leading to signature
mismatches. The new `TestSendAuthenticatedPostRequestToServer` reproduces the
bug and validates its fix.
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Oct 10, 2015
Using fakeNetConn in the test exposes a bug in 18F/hmacauth when handling POST
requests, addressed by 18F/hmacauth#4. The bug was that the strings.Reader
does not consume its buffer contents the same way that a net.Conn does. So the
test would pass because its request body would still be intact after signing,
but during live testing, the request body would be consumed by
HmacAuth.requestSignature().

It also happened to expose a subsequent 18F/hmacauth bug addressed in
18F/hmacauth#5. It turns out that checking Request.ContentLength is an
unreliable way of detecting that a body is present, and checking body != nil
is sufficient.

18F/hmacauth#4 is already merged; when 18F/hmacauth#5 is in, I'll tag
18F/hmacauth v1.0.1 and update the Godeps to use that version, at which point
the test should pass.
jcscottiii added a commit that referenced this pull request Oct 13, 2015
Eliminate content length check in requestSignature
@jcscottiii jcscottiii merged commit 9232a63 into master Oct 13, 2015
@mbland mbland deleted the eliminate-content-length-check branch October 13, 2015 13:16
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Oct 13, 2015
v1.0.1 contains 18F/hmacauth#4 and 18F/hmacauth#5, needed to make
TestRequestSignaturePostRequest pass again.
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Nov 9, 2015
Using fakeNetConn in the test exposes a bug in 18F/hmacauth when handling POST
requests, addressed by 18F/hmacauth#4. The bug was that the strings.Reader
does not consume its buffer contents the same way that a net.Conn does. So the
test would pass because its request body would still be intact after signing,
but during live testing, the request body would be consumed by
HmacAuth.requestSignature().

It also happened to expose a subsequent 18F/hmacauth bug addressed in
18F/hmacauth#5. It turns out that checking Request.ContentLength is an
unreliable way of detecting that a body is present, and checking body != nil
is sufficient.

18F/hmacauth#4 is already merged; when 18F/hmacauth#5 is in, I'll tag
18F/hmacauth v1.0.1 and update the Godeps to use that version, at which point
the test should pass.
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Nov 9, 2015
v1.0.1 contains 18F/hmacauth#4 and 18F/hmacauth#5, needed to make
TestRequestSignaturePostRequest pass again.
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Nov 9, 2015
Using fakeNetConn in the test exposes a bug in 18F/hmacauth when handling POST
requests, addressed by 18F/hmacauth#4. The bug was that the strings.Reader
does not consume its buffer contents the same way that a net.Conn does. So the
test would pass because its request body would still be intact after signing,
but during live testing, the request body would be consumed by
HmacAuth.requestSignature().

It also happened to expose a subsequent 18F/hmacauth bug addressed in
18F/hmacauth#5. It turns out that checking Request.ContentLength is an
unreliable way of detecting that a body is present, and checking body != nil
is sufficient.

18F/hmacauth#4 is already merged; when 18F/hmacauth#5 is in, I'll tag
18F/hmacauth v1.0.1 and update the Godeps to use that version, at which point
the test should pass.
mbland pushed a commit to cloud-gov/oauth2_proxy that referenced this pull request Nov 9, 2015
v1.0.1 contains 18F/hmacauth#4 and 18F/hmacauth#5, needed to make
TestRequestSignaturePostRequest pass again.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants