Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Panel/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,21 @@ public static function hasAccess(User $user, string $path): bool
return false;
}

// if auth is not required the redirect is allowed
if ($auth === false) {
return true;
// check the firewall, if auth is required
if (
$auth !== false &&
Panel::hasAccess($user, $areaId) === false
) {
return false;
}

// check the firewall
return Panel::hasAccess($user, $areaId);
// check if the route yields a valid result
$result = $route->action()->call(
$route,
...$route->arguments()
);

return $result !== false;
});
} catch (Throwable) {
return false;
Expand Down
32 changes: 32 additions & 0 deletions tests/Panel/HomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public function testHasAccess(): void
],
'users' => [
['email' => 'test@getkirby.com', 'role' => 'admin']
],
'options' => [
'api' => [
'allowImpersonation' => true
]
]
]);

Expand Down Expand Up @@ -220,6 +225,11 @@ public function testHasAccessWithLimitedAccess(): void
],
'users' => [
['email' => 'test@getkirby.com', 'role' => 'editor']
],
'options' => [
'api' => [
'allowImpersonation' => true
]
]
]);

Expand All @@ -231,6 +241,28 @@ public function testHasAccessWithLimitedAccess(): void
$this->assertTrue(Home::hasAccess($user, 'account'));
}

public function testHasAccessWithInvalidPath(): void
{
$this->app = $this->app->clone([
'site' => [
'children' => [
['slug' => 'test']
]
],
'users' => [
['email' => 'test@getkirby.com', 'role' => 'admin']
],
'options' => [
'api' => [
'allowImpersonation' => true
]
]
]);

$user = $this->app->impersonate('test@getkirby.com');
$this->assertFalse(Home::hasAccess($user, 'pages/foo+bar'));
}

public function testHasValidDomain(): void
{
$uri = Uri::current();
Expand Down