mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-13 14:15:58 +00:00
fix(auth): enforce authorization checks across API and Livewire components
- Add authorization checks to API controller endpoints (view, create, update, delete) - Wrap Livewire component methods with try-catch for consistent error handling - Add AuthorizesRequests trait to components requiring authorization checks - Ensure all sensitive operations verify user permissions before execution - Implement unified error handling with handleError() helper function
This commit is contained in:
1 parent
12f8f80eb1
commit
86b05b902a
84 files changed
+4046
-1055
No files matched your search
@@ -20,7 +20,9 @@ class ServicePolicy
|
||||
*/
|
||||
public function view(User $user, Service $service): bool
|
||||
{
|
||||
return true;
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
return $teamId !== null && $user->teams->contains('id', $teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,8 +30,7 @@ class ServicePolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
// return $user->isAdmin();
|
||||
return true;
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,13 +38,9 @@ class ServicePolicy
|
||||
*/
|
||||
public function update(User $user, Service $service): bool
|
||||
{
|
||||
$team = $service->team();
|
||||
if (! $team) {
|
||||
return false;
|
||||
}
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $team->id);
|
||||
return true;
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,12 +48,9 @@ class ServicePolicy
|
||||
*/
|
||||
public function delete(User $user, Service $service): bool
|
||||
{
|
||||
// if ($user->isAdmin()) {
|
||||
// return true;
|
||||
// }
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
// return false;
|
||||
return true;
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,8 +58,7 @@ class ServicePolicy
|
||||
*/
|
||||
public function restore(User $user, Service $service): bool
|
||||
{
|
||||
// return true;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,23 +66,17 @@ class ServicePolicy
|
||||
*/
|
||||
public function forceDelete(User $user, Service $service): bool
|
||||
{
|
||||
// if ($user->isAdmin()) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// return false;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can stop the service.
|
||||
*/
|
||||
public function stop(User $user, Service $service): bool
|
||||
{
|
||||
$team = $service->team();
|
||||
if (! $team) {
|
||||
return false;
|
||||
}
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
// return $user->teams->contains('id', $team->id);
|
||||
return true;
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,13 +84,9 @@ class ServicePolicy
|
||||
*/
|
||||
public function manageEnvironment(User $user, Service $service): bool
|
||||
{
|
||||
$team = $service->team();
|
||||
if (! $team) {
|
||||
return false;
|
||||
}
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
// return $user->isAdmin() && $user->teams->contains('id', $team->id);
|
||||
return true;
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,18 +94,23 @@ class ServicePolicy
|
||||
*/
|
||||
public function deploy(User $user, Service $service): bool
|
||||
{
|
||||
$team = $service->team();
|
||||
if (! $team) {
|
||||
return false;
|
||||
}
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
// return $user->teams->contains('id', $team->id);
|
||||
return true;
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can access the terminal.
|
||||
*/
|
||||
public function accessTerminal(User $user, Service $service): bool
|
||||
{
|
||||
// return $user->isAdmin() || $user->teams->contains('id', $service->team()->id);
|
||||
return true;
|
||||
$teamId = $this->getTeamId($service);
|
||||
|
||||
return $teamId !== null && $user->isAdminOfTeam($teamId);
|
||||
}
|
||||
|
||||
private function getTeamId(Service $service): ?int
|
||||
{
|
||||
return $service->team()?->id;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user