Skip to content

Treat invalid pattern as bad request in EnvironmentEndpoint#49888

Closed
akshitk20 wants to merge 1 commit intospring-projects:mainfrom
akshitk20:fix-environment-endpoint-invalid-pattern
Closed

Treat invalid pattern as bad request in EnvironmentEndpoint#49888
akshitk20 wants to merge 1 commit intospring-projects:mainfrom
akshitk20:fix-environment-endpoint-invalid-pattern

Conversation

@akshitk20
Copy link
Copy Markdown

Closes #49884

Summary

EnvironmentEndpoint passes the user-supplied pattern directly to Pattern.compile() when filtering property names. An invalid regex (e.g., GET /actuator/env?pattern=[)
raises a PatternSyntaxException which is not translated into the actuator's standard bad-request path.

This PR wraps PatternSyntaxException in an InvalidEndpointRequestException, ensuring a proper 400 Bad Request response. This follows the same pattern used in
MetricsEndpoint.parseTag() for handling invalid user input.

Changes

  • Added getPatternPredicate() method that catches PatternSyntaxException and throws InvalidEndpointRequestException
  • Added test to verify invalid patterns throw InvalidEndpointRequestException

Wrap PatternSyntaxException in InvalidEndpointRequestException when
an invalid regex pattern is provided to the env actuator endpoint,
ensuring a proper 400 Bad Request response.

Closes spring-projectsgh-49884

Signed-off-by: Akshit Khatri <akshit.khatri@sap.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 4, 2026
@snicoll
Copy link
Copy Markdown
Member

snicoll commented Apr 5, 2026

@akshitk20 please refrain from opening a PR for an issue that is still waiting-for-triage. Also the OP has offered to submit a PR if the issue is accepted.

@snicoll snicoll closed this Apr 5, 2026
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

500 response from env endpoint when supplied pattern is invalid

3 participants