[BUG] GlobalErrorHandler casts HttpStatusCode to HttpStatus enum, ClassCastException on non-standard status codes
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
- Severity: Medium
- Location:
`shenyu-web/src/main/java/org/apache/shenyu/web/handler/GlobalErrorHandler.java:64-66`
-
Description:
In the `ResponseStatusException` branch: `httpStatusCode = ((ResponseStatusException) throwable).getStatusCode(); HttpStatus httpStatus = (HttpStatus) httpStatusCode;`. On Spring Framework 6.1, `getStatusCode()` returns the interface `HttpStatusCode`. `HttpStatus` is an enum implementing it, but `ResponseStatusException` also accepts raw `int`/`HttpStatusCode` codes. If any exception is created with a non-enum value (e.g. `HttpStatusCode.valueOf(460)`), `getStatusCode()` returns `DefaultHttpStatusCode` and the cast to `HttpStatus` throws `ClassCastException`, crashing the error handler itself and masking the original error with a 500 + CCE stack trace.
-
Impact:
Any plugin, third-party library, or Spring framework component that throws `ResponseStatusException` with a non-enum status code causes the global error handler to crash, replacing the real error with an unhelpful 500 + CCE.
-
Suggested fix:
Replace `(HttpStatus) httpStatusCode` with `HttpStatus.resolve(httpStatusCode.value())` (returns null for non-standard codes) and null-guard, or use `httpStatusCode.toString()`.
-
Confidence: Medium — no current trigger in shenyu's own code (all use `HttpStatus` constants), but the cast is unconditionally unsafe for any third-party exception path.
- Related existing: none
---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.