8000 JwkSet unexpectedly "secret" / Jackson cannot serialize JwkSet · Issue #976 · jwtk/jjwt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
JwkSet unexpectedly "secret" / Jackson cannot serialize JwkSet #976
Closed
@gsprdev

Description

@gsprdev

Describe the bug

The default (and only) JWK set builder considers all "keys" members as secret, even if the set contains only public keys.
In turn, this results in a failure to serialize the set using Jackson redacted data cannot be serialized.

To Reproduce

To repro

  1. Add Jackson to the classpath
  2. Create a JWK for a public key
  3. Add that JWK to a JWKSet using the builder
  4. Attempt to serialize that set using Jackson's ObjectMapper

A complete example follows.

dependencies {
    implementation("io.jsonwebtoken:jjwt-api:0.12.6")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.6")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.6")
}
static void jwkSetUnexpectedlyPrivate(RSAPublicKey pubKey) throws Exception {
    final ObjectMapper jacksonMapper = new ObjectMapper();

    final RsaPublicJwk pubJwk = Jwks.builder()
            .key(pubKey)
            .build();

    // PASS; unredacted human-readable form
    pubJwk.toString();

    // PASS; unredacted
    jacksonMapper.writeValueAsString(pubJwk);

    // When in set, now redacted
    final JwkSet jwkSet = Jwks.set()
            .add(pubJwk)
            .build();

    // FAIL? Redacted; Possibly a safe default, not terribly problematic for debug statements
    jwkSet.toString();

    // FAIL; Throws an exception. Prevents exposure of the set for external consumption of public keys.
    jacksonMapper.writeValueAsString(jwkSet);
    // com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class
    // io.jsonwebtoken.impl.lang.RedactedSupplier and no properties discovered to create BeanSerializer
    // (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
    // (through reference chain: io.jsonwebtoken.impl.security.DefaultJwkSet["keys"])
}

Expected behavior

  1. It is expected that sets are either conditionally redacted based on whether their content is redacted,
    OR this behavior can be configured in some way to allow proper serialization.
  2. It should be possible to serialize a JwkSet using Jackson

Screenshots

See code sample above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0