spring-projects / spring-projects/spring-security

[Enhancement] Exception Hierarchy in Spring Security

Open
#18,301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

I recently ran into an issue where I tried to make a custom JwtDecoder that would try to parse the incoming token in order to inspect the headers, before doing further validation. SignedJWT.parse() ended up bubbling up a general ParseException and that resulted in an error thrown and logged without tracing information. It was pointed out that the surface level problem here could be solved by catching all exceptions and rethrowing using a JwtException instead, but this raises a couple issues:

  1. This is intrinsically an old Java pattern and it will effectively force all implementers of JwtDecoder to always have to implement a general try/catch(ex: Exception) and rewrap in order to have observable errors and traceable logs, even if you're using Kotlin.
  2. This same issue likely exists within other places called by FilterChainProxy.doProxy
  3. People calling the application with an invalid token is unlikely to be rare, especially in the case of an attacker, so it seems heavy-handed to raise an exception for this

In my real project, an application gateway bug caused this case to happen a lot and because of the servlet error log raised a higher level than usual alert. However, the problem was harder to track down because of the lack of a trace ID to tie it to other related logs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing JwtDecoder implementations and the exception flow through FilterChainProxy.doProxy, including the reported SignedJWT.parse() failure. Clarify the desired exception hierarchy, logging and tracing behavior, and how invalid tokens should be handled; the work is done only when that scope and its expected behavior are agreed and covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.