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.

Use String equality, not URL equality, for JWT issuer validation

See original GitHub issue

Summary

URL equality is not consistent becuse it attempts DNS resolution and host comparison, which can cause both false positives and false negatives.

RFC 7519 describes “iss” claim as being a StringOrURI value, and restricts StringOrURI validation to string equality:

StringOrURI values are compared as case-sensitive strings with no transformations or canonicalizations applied.

JwtIssuerValidator should replace URL equality with plain case-sensitive string equality.

Actual Behavior

In a load balanced environment (GCP AppEngine Flexible) issuer verification behavior is inconsistent; it fails some of the time with exception below, even though the string issuer matches the required issuer perfectly.

BearerTokenAuthenticationFilter : Authentication request for failed: org.springframework.security.oauth2.core.OAuth2AuthenticationException: An error occurred while attempting to decode the Jwt: This iss claim is not equal to the configured issuer

Expected Behavior

Issuer check should succeed if and only if JWT string issuer matches expected string issuer.

Version

spring-security-oauth2-resource-server:jar:5.1.1.RELEASE

Sample

I can reproduce the problem consistently when deploying the following sample to GCP AppEngine Flexible. The first 30 or so times the application is accessed, OAuth2-based IAP authentication works great, but after that the load balancer kicks traffic over to a different subnet, and issuer verification starts failing consistently. https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-security-iap-sample

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
elefeintcommented, Nov 15, 2018

Jinx timing! And yes, 5.1.2.BUILD-SNAPSHOT fixes the issue completely.

When are you planning to release spring-security 5.1.2?

1reaction
ejazazimcommented, Dec 10, 2018

I was facing the same issue on AWS while using Cognito as Authentication provider and custom user info endpoint in my own OAuth2 Resource Server.

Updating to Boot 2.1.1 release fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring security oauth2 fails issuer validation after 30 seconds
The solution committed changed the URL to a String which allowed for the equality check to be more reliable in addition to removing...
Read more >
RFC 7519: JSON Web Token (JWT)
The claims in a JWT are encoded as a JSON object that is used as the ... Since the only string comparison operations...
Read more >
"==" and "!=" should not be used when "equals" is overridden
"==" and "!=" should not be used when "equals" is overridden ... It is equivalent to use the equality == operator and the...
Read more >
JSON Web Token (JWT) RFC 7519 - IETF Datatracker
JSON Web Token (JWT) RFC 7519 · 1. "iss" (Issuer) Claim The "iss" (issuer) claim identifies the principal that issued the JWT. ·...
Read more >
jwt - Go Packages
1.0. func Equal(t1, t2 Token) bool. Equal compares two JWT tokens. Do not use `reflect.Equal ...
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