Skip to content

[Investigation] AntiVpnFilter throws exceptions — validate handling and HTTP responses #70

Description

@GabrielNat1

AntiVpnFilter (src/main/java/com/example/spring_boot_project/vpn/filter/AntiVpnFilter.java) throws specific exceptions (VpnBlockedException, VpnChallengeException) directly from the filter, which may result in 500 responses if there is no appropriate global exception handling.

Evidence

  • In the doFilterInternal() method, the code does throw new VpnBlockedException(ip) / VpnChallengeException(ip) when a risk is detected.
  • There is no evidence in the repository (within the scope of this investigation) of a @ControllerAdvice/ExceptionHandler that converts these exceptions into appropriate HTTP responses.

Impact

  • If not handled, these exceptions may return a 500 response to the client instead of 403/429/401 as intended.
  • Lack of logging/context may make troubleshooting more difficult.

Recommendations

  1. Ensure that there is a global handler (e.g., @ControllerAdvice) that maps VpnBlockedException -> HTTP 403 (or 451/others according to the policy) and VpnChallengeException -> 401/429 with a clear payload.
  2. Alternatively, in the filter, write the response directly (setStatus + body) instead of throwing an exception, to ensure consistent behavior without relying on exception handlers.
  3. Add logs and metrics (counters) to monitor block/challenge events.

Related Files

  • src/main/java/com/example/spring_boot_project/vpn/filter/AntiVpnFilter.java

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions