question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Valid authorization tokens rejected in version 0.5.4 and above

See original GitHub issue

I am experiencing what I believe to be a bug when upgrading from version 0.5.3 to 0.5.4.

I am trying to test a backend app that receives requests from a frontend app. I am using version 2.1.7 of token-support to set up token validation. The code I am using to mock the authentication looks something like

private val mockOAuth2Server = MockOAuth2Server()

fun mockAuthToken(): String =
    mockOAuth2Server.issueToken(
        issuerId = "mockIssuer", // not the actual value used
        subject = "mockSubject",
        audience = "aud-localhost",
        claims = mapOf(
            "pid" to "mockPid"
        )
    )
        .serialize()

When using 0.5.3, my tests are completing as expected. In short, requests are made to a mocked app which either responds 200 OK or 401 Unauthorized, depending on the content of the “Authorization”-header of the request. When using 0.5.4, all requests return 401 Unauthorized.

I’m not entirely sure what causes the bug, but I’ve been able to pinpoint a piece of code which differs in behaviour when using the different versions. The code that behaves differently can be found here.

I’ll try to explain the issue I’m experiencing based on the code referred to above. Using 0.5.3 of mock-oauth2-server, when using a valid authorization token, jwtToken.getIssuer() evaluates to "http://view-localhost:<port>/<issuer>", and config.issuers, which the config.getIssuer(...) accesses, contains "<issuer>" and "http://view-localhost:<port>/<issuer>". Changing to version 0.5.4, and with no other changes, config.issuers is different. It now contains "<issuer>" (identical) and "http://localhost:<port>/<issuer>" (missing the “view-”-part). This leads the filter-predicate to evaluate to false, and the JWT to be considered invalid and the request to be unauthorized.

That’s pretty much what I’ve been able to figure out so far. I’ll be happy to provide any more information if the issue is unclear in any way.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bjergacommented, Nov 25, 2022

@ybelMekk Host-header is not set explicitly and it does not seem to be present during the request. However, when I set a breakpoint at https://github.com/tanettrimas/mock-oauth2-server/blob/master/src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpRequest.kt#L142, hostheader has value <issuer>:<port>, which seems to cause the altered response from fun proxyAwareUrl() between 0.5.3 and 0.5.4.

0reactions
joakibjcommented, Dec 13, 2022

We have the same issue with token-support:2.1.5 and higher (includes mock-oauth2-server:0.5.4). Looks like the iss claim uses an entry in the Windows IP to host mapping C:\Windows\System32\drivers\etc\hosts (e.g. view-localhost) instead of defaulting to the DNS name localhost for 127.0.0.1

This fails locally on Windows but not on CI (Jenkins on Linux)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · navikt/mock-oauth2-server - GitHub
Valid authorization tokens rejected in version 0.5.4 and above bug Something isn't working. #380 opened last month by bjerga.
Read more >
Blocking requests that don't have a valid token - AWS WAF ...
The Bot Control rule group doesn't block a request with a rejected token, and neither rule group blocks an individual request that's missing...
Read more >
JSON Web Token Tutorial using AngularJS & Laravel - Toptal
The server then validates the token and, if it's valid, returns the secure resource to the client. The authentication server can sign the...
Read more >
Authentication between microservices using Kubernetes ...
Learn how you can secure communications between microservices to prevent unauthenticated requests using Kubernetes identities.
Read more >
Secure a Web API with Individual Accounts and Local Login in ...
For that reason, bearer tokens should only be used over a HTTPS, and should have relatively short expiration times. Authorization server. A ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found