-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to disable some automatic body parsing #106
Comments
You can try this code : $request->registerMediaTypeParser('application/xml', function ($input) {
return null;
});
$request->registerMediaTypeParser('text/xml', function ($input) {
return null;
}); We could also create a function |
Another simple way to solve this is to add a middleware layer that checks a whitelist of supported content types, e.g.: // Limit requests to application/json
$app->add(function (Request $request, Response $response, $next) {
$whitelistContentTypes = ['application/json'];
if (!in_array($request->getMediaType(), $whitelistContentTypes)) {
return $response->withJson(['message' => 'Unsupported Media Type'], 415);
}
return $next($request, $response);
}); [edit] You may also need to consider the case where |
Hi @pdscopes thanks for the reply, but if I want to just allow plain/normal HTTP messages, how would the code look like? (I mean blacklist XML and/or JSON and/or any other. What is the MediaType set for normal requests? Or maybe a whitelist: just allow URLencoded type.) |
To answer the original question, replace the XML media parser callback with your own. Something like this will probably work: $request->registerMediaTypeParser('application/xml', function () { return []; });
$request->registerMediaTypeParser('text/xml', function () { return []; }); (untested!) |
For normal POSTed form data, the Content-Type should be: |
To follow on from this |
nullupload-app.ERROR: Call to undefined function Slim\Http\simplexml_load_string() on /var/www/nullupload/vendor/slim/slim/Slim/Http/Request.php at 230 slimphp/Slim-Http#106
The problem is that the request object is immutable, so if you call So you might disable it, and then someone else does something like |
Hello, Is it possible to disable automatic request parsing?
At least in version 3 it parses like this:
But I don't have installed the xml extension or have the functions disabled for security reasons. When an attacker sends a xml requests it wants to parse and I get an error like:
Call to undefined function Slim\Http\simplexml_load_string() on /var/www/website/vendor/slim/slim/Slim/Http/Request.php at 230
I would like to choose what parsing is done from these 3 options.
The text was updated successfully, but these errors were encountered: