Skip to content
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

fix: empty http path and method in permission allows any route open; #5741

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Auth/Database/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function roles(): BelongsToMany
public function shouldPassThrough(Request $request): bool
{
if (empty($this->http_method) && empty($this->http_path)) {
return true;
return false;
}

$method = $this->http_method;
Expand Down
16 changes: 16 additions & 0 deletions tests/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Auth\Database\Permission;
use Encore\Admin\Auth\Database\Role;
use Illuminate\Http\Request;

class PermissionsTest extends TestCase
{
Expand Down Expand Up @@ -194,6 +195,21 @@ public function testPermissionThroughRole()
$this->assertTrue(Administrator::find(2)->can('can-remove'));
}

public function testPermissionWithoutHttpMethodAndHttpPath()
{
// 1.add a permission without http_path and http_method
$permission = Permission::create([
'slug' => 'not-http-based-permission',
'name' => 'Not http based permission',
'http_path' => '',
'http_method' => [''],
]);

// 2.check that this permissions does not pass through protected routes (as it is checked in the Permission middleware)
$request = Request::create('admin/auth/permissions');
$this->assertFalse($permission->shouldPassThrough($request));
}

public function testEditPermission()
{
$this->visit('admin/auth/permissions/create')
Expand Down