-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Option to enable strict duplicate detection #877
Comments
You can create a new instance of |
FWIW, this is also in the the documentation: https://github.com/jwtk/jjwt#jackson-json-processor But that section mostly talks about your own application-wide It is unclear to me if we should change the default behavior of implicitly-created |
Hi @bdemers and @lhazlewood, thanks for your quick responses.
In general, I would think duplicate properties in a JWT is a sign of a buggy or compromised authorization server. I don't think allowing both behaviors in the RFCs was a good idea, since a JWT going through different parsers/verifiers could be rejected at any of them simply depending on the choice of implementation. By the way, with strict duplicate detection enabled, duplicates in the header results in e.g. |
Thanks for the additional context @laurids , that's helpful.
You were clear 😄 . We were just basically implying that, if the default implementation doesn't suit your needs, you should be using the But I can see how that could be a 'heavier' solution than what you desire. Perhaps a general solution would be to make A more targeted solution for your particular use case would be to just default to enabling Implementation note: when changing the default, it doesn't make sense to also enable generic configuration options on the |
Is your feature request related to a problem? Please describe.
For parsing, we are using the
JacksonDeserializer
via the constructorpublic JacksonDeserializer(Map<String, Class<?>> claimTypeMap)
.When parsing a JWT with duplicate properties, the last one will be used, and the rest are ignored. Although this behavior is allowed by the RFCs, we would prefer for the parser to throw an exception if there are duplicate keys.
In general, it can create vulnerabilities if e.g. different parsers are used in a stack, where some use the first item, and some use the last item, in cases of duplicates. This is of course not allowed in JWT context, but we would also like to fail fast, if the next parser fails.
This can be done by enabling
JsonParser.Feature.STRICT_DUPLICATE_DETECTION
on the underlyingObjectMapper
.The problem is that there is no way to access the
objectMapper
inJacksonDeserializer
.Describe the solution you'd like
An option to enable
JsonParser.Feature.STRICT_DUPLICATE_DETECTION
on theobjectMapper
inJacksonDeserializer
. Whether it be by adding a getter for theobjectMapper
or an extra constructor that also takesJsonParser.Feature
s?Describe alternatives you've considered
We could write our own implementation of
AbstractSerializer
, but it would be a copy of theJacksonDeserializer
class except for enabling the strict duplicate detection.Additional context
The RFCs allows both behaviors for parsing duplicates in both header and payload:
https://www.rfc-editor.org/rfc/rfc7515.html#section-4
https://www.rfc-editor.org/rfc/rfc7519#section-4
Strict duplicate detection:
https://fasterxml.github.io/jackson-core/javadoc/2.9/com/fasterxml/jackson/core/JsonParser.Feature.html#STRICT_DUPLICATE_DETECTION
The text was updated successfully, but these errors were encountered: