5.x Middleware and routing security hardening#3452
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves middleware security by hardening JSON/XML body parsing, preventing XXE-style XML parsing risks and enforcing configured router base paths.
Removed
Slim\Middleware\CorsMiddlewareand the corresponding CORS middleware tests.Changed
BasePathMiddlewarenow detects the base path and stores it on the router instead of passing it via a request attribute.RoutingMiddlewarenow reads base path only from the router.MethodOverrideMiddlewarenow only honors method overrides on originalPOSTrequests because method override exists to support HTML-form style submissions, while allowing a GET or other method to become DELETE, PUT, or PATCH can bypass security assumptions in CSRF checks, proxies, caches, and route handling.MethodOverrideMiddlewarenow ignores unsupported override methods to prevent clients from injecting arbitrary or nonstandard HTTP verbs into downstream routing and middleware logic.HttpBadRequestExceptionfor invalid JSON usingJSON_THROW_ON_ERROR.LIBXML_NONETandLIBXML_NO_XXEwhen available to make XML parsing safer by blocking external network access and, on PHP versions that support it, explicitly disabling XML External Entity processing.That reduces the risk of XXE-style attacks, where a malicious XML payload tries to make the parser fetch remote resources or expose local files through external entities.
RouteInterfaceinstead of concreteRoute.Method not allowed.instead of:Method not allowed. Must be one of: GET, POSTFixed