Skip to content

Commit

Permalink
Authentication could be bypassed if URI had multiple slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola committed Feb 27, 2017
1 parent cc5a0cf commit 392ddee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/HttpBasicAuthentication/RequestPathRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct($options = array())
public function __invoke(\Slim\Slim $app)
{
$uri = $app->request->getResourceUri();
$uri = preg_replace("#/+#", "/", $uri);

/* If request path is matches passthrough should not authenticate. */
foreach ((array)$this->options["passthrough"] as $passthrough) {
Expand Down
40 changes: 40 additions & 0 deletions test/RequestPathRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,44 @@ public function testShouldPassthroughLogin()
));
$this->assertFalse($rule(new \Slim\Slim));
}

public function testBug50ShouldAuthenticateMultipleSlashes()
{
\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "/"
));

$rule = new RequestPathRule(array("path" => "/v1/api"));
$this->assertFalse($rule(new \Slim\Slim));

\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "/v1/api"
));
$this->assertTrue($rule(new \Slim\Slim));

\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "/v1//api"
));
$this->assertTrue($rule(new \Slim\Slim));

\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "/v1//////api"
));
$this->assertTrue($rule(new \Slim\Slim));

\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "//v1/api"
));
$this->assertTrue($rule(new \Slim\Slim));

\Slim\Environment::mock(array(
"SCRIPT_NAME" => "/index.php",
"PATH_INFO" => "//////v1/api"
));
}
}

0 comments on commit 392ddee

Please sign in to comment.