spring-projects / spring-projects/spring-security

SEC-2975: Provide exception handler for TypeMismatchException

Open
#3,184 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: enhancement type: jira
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Ted Bergeron (Migrated from SEC-2975) said:

See DATACMNS-576: Write an exception handler for TypeMismatchException in an @ControllerAdvice annotated type, inspect the cause and return 403 Forbidden if you find an AccessDeniedException.

Discussed with Oliver issues when trying to apply security to Spring Data repositories. There is a detailed flow described in the linked issue that shows a security exception being swallowed / chained by the spring core framework.

The actual stack trace is a chain of 3 exceptions:

org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'com.xyz.Person'; 
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.PathVariable com.xyz.Person for value '28107749'; 
nested exception is org.springframework.security.access.AccessDeniedException: Access is denied

I have an extension of org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler which is already handling TypeMismatchException. Thus, I overrode the handleTypeMismatch method and added the logic to inspect the rootCause there.

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 with Spring MVC's TypeMismatchException handling and the ResponseEntityExceptionHandler.handleTypeMismatch entry point mentioned in the issue. Trace the nested ConversionFailedException cause chain and verify that a contained AccessDeniedException produces a 403 Forbidden response; otherwise preserve the existing handling behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.