Skip to content

Create Jackson Mixin for InvalidOneTimeTokenException#19210

Open
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:fix/issue-19203-invalid-ott-mixin
Open

Create Jackson Mixin for InvalidOneTimeTokenException#19210
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:fix/issue-19203-invalid-ott-mixin

Conversation

@seonwooj0810
Copy link
Copy Markdown

Closes gh-19203

Problem

InvalidOneTimeTokenException had no Jackson mixin registered. When the
session is persisted to a serialized backing store (e.g. Redis), and the
security context contains this exception (for example after a failed
one-time-token login attempt), the session cannot be deserialized.

This is the same shape of bug that gh-18095 reported for
OneTimeTokenAuthenticationToken (fixed in gh-18096).

Change

Mirrors the existing BadCredentialsExceptionMixin pattern, which
covers an analogous AuthenticationException subtype:

  • Adds InvalidOneTimeTokenExceptionMixin in both the
    org.springframework.security.jackson (Jackson 3) and
    org.springframework.security.jackson2 (Jackson 2, deprecated)
    packages.
  • Registers the mixins in CoreJacksonModule and CoreJackson2Module.
  • Adds InvalidOneTimeTokenException to the allowed subtypes in
    CoreJacksonModule#configurePolymorphicTypeValidator.
  • Adds round-trip serialize/deserialize tests in both packages.

The mixin ignores cause, stackTrace, and authenticationRequest,
matching BadCredentialsExceptionMixin.

Test plan

  • ./gradlew :spring-security-core:test --tests "org.springframework.security.jackson.InvalidOneTimeTokenExceptionMixinTests" --tests "org.springframework.security.jackson2.InvalidOneTimeTokenExceptionMixinTests" — passes (4/4).
  • Regression: full jackson, jackson2, and authentication.ott test packages re-run — all green, no regressions.
  • ./gradlew :spring-security-core:checkFormatMain :spring-security-core:checkFormatTest :spring-security-core:checkstyleMain :spring-security-core:checkstyleTest — passes.

Build was run with -PtestToolchain=21 since JDK 25 was not available
locally; the project compiles with --release 17 so this does not
affect the produced bytecode.

InvalidOneTimeTokenException had no Jackson mixin registered, so storing
the session in a serialized backing store (for example, Redis) failed to
deserialize when the exception was present in the security context.

This commit follows the existing BadCredentialsExceptionMixin pattern,
adding mixins in the jackson and jackson2 packages and registering them
in CoreJacksonModule and CoreJackson2Module. The Jackson 3
PolymorphicTypeValidator is updated to allow InvalidOneTimeTokenException
as a subtype.

Closes spring-projectsgh-19203

Signed-off-by: seonwoo_jung <laborlawseon@kap.kr>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidOneTimeTokenException does not have a Jackson Mixin

2 participants