tuupola/slim-basic-auth
Abandoned PSR-7/PSR-15 middleware providing HTTP Basic Authentication. Originally for Slim but works with any PSR-compatible framework (tested with Slim and Zend Expressive). Configure allowed username/password pairs and protect routes via middleware.
error callback when authentication fails.$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"users" => [
"root" => "t00r",
"somebody" => "passw0rd"
],
"error" => function ($request, $response, $arguments) {
var_dump($arguments["user"]);
var_dump($arguments["message"]);
}
]));
This is a security release.
RequestPathRule now removes multiple slashes from the URI before determining whether the path should be authenticated or not. For HTTP client /foo and //foo are different URIs and technically valid according to RFC3986. However on serverside it depends on implementation and often /foo, //foo and even /////foo are considered a same route.
Different PSR-7 implementations were behaving in different way. Diactoros removes multiple leading slashes. By default Slim does not alter any slashes. However when installed in subfolder Slim removes all slashes.
This means if you are authenticating a subfolder, for example /api and Slim is installed in document root it was possible to bypass authentication by doing a request to //api. Problem did not exist if Slim was installed in subfolder. Diactoros was not affected.
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"path" => "/api",
"users" => [
"root" => "t00r",
"somebody" => "passw0rd"
]
]));
If you were using default setting of authenticating all routes you were not affected.
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"users" => [
"root" => "t00r",
"somebody" => "passw0rd"
]
]));
I was lazy and did no keep a changelog before this.
X-Forwarded-Proto and X-Forwarded-Port when detecting https requestsSlim\Middleware to Tuupola\MiddlewareAuthorization header from the PSR-7 request. Both PHP_AUTH_USER and PHP_AUTH_PW globals as well as HTTP_AUTHORIZATION environment are now ignored.callback setting was renamed to before. It is called before executing other middlewares in the stack.passthrough setting was renamed to ignore.addRule() and withRules() are now immutable.after callback. It is called after executing other middlewares in the stack.How can I help you explore Laravel packages today?