Skip to content

Commit

Permalink
Allow other casings for bearer scheme token.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Apr 19, 2020
1 parent 575e6b8 commit 3e1dac8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ EdDSA [Ed25519] produces small signatures and it performs well.

## Standard Compliance

* RFC 2617: “HTTP Authentication”
* RFC 6750: “The OAuth 2.0 Authorization Framework: Bearer Token Usage”
* RFC 7468: “Textual Encodings of PKIX, PKCS, and CMS Structures”
* RFC 7515: “JSON Web Signature (JWS)”
Expand Down
5 changes: 4 additions & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func tokenFromHeader(r *http.Request) ([]byte, error) {

const prefix = "Bearer "
if !strings.HasPrefix(auth, prefix) {
return nil, errAuthSchema
// RFC 2617, subsection 1.2 defines the scheme token as case-insensitive.
if len(auth) < len(prefix) || !strings.EqualFold(auth[:len(prefix)], prefix) {
return nil, errAuthSchema
}
}
return []byte(auth[len(prefix):]), nil
}
Expand Down
6 changes: 3 additions & 3 deletions web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ func TestCheckHeader(t *testing.T) {
t.Error("ECDSA error:", err)
}

req.Header.Set("Authorization", "Bearer "+goldenEdDSAs[0].token)
req.Header.Set("Authorization", "BEARER "+goldenEdDSAs[0].token)
_, err = EdDSACheckHeader(req, goldenEdDSAs[0].key)
if err != nil {
t.Error("EdDSA error:", err)
}

req.Header.Set("Authorization", "Bearer "+goldenHMACs[0].token)
req.Header.Set("Authorization", "bearer "+goldenHMACs[0].token)
_, err = HMACCheckHeader(req, goldenHMACs[0].secret)
if err != nil {
t.Error("HMAC error:", err)
}

req.Header.Set("Authorization", "Bearer "+goldenRSAs[0].token)
req.Header.Set("Authorization", "bEArEr "+goldenRSAs[0].token)
_, err = RSACheckHeader(req, goldenRSAs[0].key)
if err != nil {
t.Error("RSA error:", err)
Expand Down

0 comments on commit 3e1dac8

Please sign in to comment.