Skip to content

Commit 192c8c3

Browse files
committed
fix IDOR private projects
1 parent 6218ffc commit 192c8c3

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/Http/Controllers/Api/V1/ProjectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function index(Organization $organization, ProjectIndexRequest $request):
7878
*/
7979
public function show(Organization $organization, Project $project): JsonResource
8080
{
81-
$this->checkPermission($organization, 'projects:view', $project);
81+
$this->checkPermission($organization, 'projects:view:all', $project);
8282

8383
// Note: There is currently no need to check if a user is a member of the project,
8484
// since this is only relevant for users with the role "employee" and they can not access this endpoint.

tests/Unit/Endpoint/Api/V1/ProjectEndpointTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public function test_show_endpoint_returns_project(): void
281281
// Arrange
282282
$data = $this->createUserWithPermission([
283283
'projects:view',
284+
'projects:view:all',
284285
]);
285286
$project = Project::factory()->forOrganization($data->organization)->create();
286287
Passport::actingAs($data->user);
@@ -293,6 +294,20 @@ public function test_show_endpoint_returns_project(): void
293294
$response->assertJsonPath('data.id', $project->getKey());
294295
}
295296

297+
public function test_show_endpoint_fails_if_employee_tries_to_access_private_project_that_they_are_not_a_member_of(): void
298+
{
299+
// Arrange
300+
$data = $this->createUserWithRole(Role::Employee);
301+
$privateProject = Project::factory()->forOrganization($data->organization)->isPrivate()->create();
302+
Passport::actingAs($data->user);
303+
304+
// Act
305+
$response = $this->getJson(route('api.v1.projects.show', [$data->organization->getKey(), $privateProject->getKey()]));
306+
307+
// Assert
308+
$response->assertForbidden();
309+
}
310+
296311
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_projects(): void
297312
{
298313
// Arrange

0 commit comments

Comments
 (0)