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

WWW-Authenticate header not present when Kong and plugins return HTTP status 401 #7772

Closed
chienhsingwu opened this issue Aug 26, 2021 · 3 comments · Fixed by #11791, #11792, #11794, #11795 or #11820
Assignees
Labels
bug plugins/basic-auth plugins/jwt plugins/key-auth plugins/ldap-auth stale/pending revisit Too old ticket. Closed, but we may revisit later. task/feature Requests for new features in Kong

Comments

@chienhsingwu
Copy link

chienhsingwu commented Aug 26, 2021

Summary

  • Kong version ($ kong version) - 2.4.1
    According to the HTTP specification for 401 error, https://httpwg.org/specs/rfc7235.html#status.401, WWW-Authenticate header field containing at least one challenge applicable to the target resource must be returned in the response.

At least the following plugins were observed to not returning the header when returning 401.

  1. basic-auth
  2. key-auth
  3. ldap-auth
  4. jwt

For Oauth2 related plugins oauth2 and jwt, below are additional requirements from the related RFCs. They further define what needs to be included in the WWW-Authenticate header.

  1. https://datatracker.ietf.org/doc/html/rfc6750#section-3
  2. https://datatracker.ietf.org/doc/html/rfc6749#section-5.2

Steps To Reproduce

Exercise any unit tests of those plugins that would return 401 error and add an assertion in those test to detect the header, the assertion would fail.

For example in jwt pluging 03_acces_spec.lua, add the LAST assertion and execute the test, it will fail.

describe("refusals", function()
  it("returns 401 Unauthorized if no JWT is found in the request", function()
    local res = assert(proxy_client:send {
      method  = "GET",
      path    = "/request",
      headers = {
        ["Host"] = "jwt1.com",
      }
    })
    assert.res_status(401, res)
    assert.not_nil(body.headers["WWW-Authenticate"])
  end)
@kikito
Copy link
Member

kikito commented Dec 20, 2022

Thank you for reporting this, I consider it a bug, we will add it to our internal tracking system

@kikito
Copy link
Member

kikito commented Mar 29, 2023

Internal tracking: KAG-1063

@StarlightIbuki
Copy link
Contributor

Dear contributor,
We're closing this issue as there hasn't been any update to it for a long time. If the issue is still relevant in the latest version, please feel free to reopen it. We're more than happy to revisit it again. Your contribution is greatly appreciated!
Please have a look at our pledge to the community for more information.
Sincerely,
Kong Gateway Team

@StarlightIbuki StarlightIbuki added the stale/pending revisit Too old ticket. Closed, but we may revisit later. label Oct 11, 2023
@nowNick nowNick reopened this Oct 13, 2023
nowNick added a commit that referenced this issue Oct 13, 2023
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT and HMAC auth were missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Oct 19, 2023
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
HMAC auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Oct 19, 2023
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Oct 19, 2023
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all key-auth 401 responses had this header. Also this
is removing the realm part from WWW-Authenticate header
as it is a potential phishing attack vector.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Oct 19, 2023
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all basic auth 401 responses had this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue May 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
HMAC auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue May 21, 2024
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue May 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all ldap-auth 401 responses had this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue May 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all oauth2 401 responses had this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Jun 14, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all ldap-auth 401 responses had this header.

Fix: #7772
KAG-321
hanshuebner pushed a commit that referenced this issue Jun 14, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all ldap-auth 401 responses had this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Jun 14, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
HMAC auth was missing this header.

Fix: #7772
KAG-321
jschmid1 pushed a commit that referenced this issue Jun 17, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
HMAC auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Jun 17, 2024
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT auth was missing this header.

Fix: #7772
KAG-321
hanshuebner pushed a commit that referenced this issue Jun 18, 2024
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT auth was missing this header.

Fix: #7772
KAG-321
nowNick added a commit that referenced this issue Jun 18, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all oauth2 401 responses had this header.

Fix: #7772
KAG-321
jschmid1 pushed a commit that referenced this issue Jun 19, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all oauth2 401 responses had this header.

Fix: #7772
KAG-321
locao pushed a commit that referenced this issue Jun 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all ldap-auth 401 responses had this header.

Fix: #7772
KAG-321

(cherry picked from commit 7585007)
locao pushed a commit that referenced this issue Jun 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
HMAC auth was missing this header.

Fix: #7772
KAG-321

(cherry picked from commit ea6b3c8)
locao pushed a commit that referenced this issue Jun 21, 2024
When serve returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
JWT auth was missing this header.

Fix: #7772
KAG-321

(cherry picked from commit a3f5410)
locao pushed a commit that referenced this issue Jun 21, 2024
When server returns 401 Unauthorized response it should
return WWW-Authenticate header as well with proper challenge.
Not all oauth2 401 responses had this header.

Fix: #7772
KAG-321

(cherry picked from commit e8080e5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment