fix(security): KVE-2026-1914/1915/1919 remediation 전건
위임 관리자(부관리자)가 권한·역할·표현식·비밀 콘텐츠 경계를 우회하던 결함군을 계층 대칭성 원칙으로 전건 차단한다. 약한 경로가 정상 응답을 내보내는 것이 유일한 증상이라, 게이트를 생산 지점 한 곳(SSoT)에 두고 같은 데이터를 내보내는 소비 경로 전부가 그 게이트를 경유하도록 맞췄다. - 등급 상한(rank ceiling): 슈퍼관리자 보호·역할/사용자 역할 배정(추가·제거 대칭)·일괄 상태변경·순서변경을 상세 경로와 동일 강도로 재적용. 가드는 DB 쓰기에 선행하여 거부 시 상태 불변. - 레이아웃 표현식: new Function/with 실행을 AST 화이트리스트 평가기로 교체. 비-문자열 computed 키 정규화(normalizeKey)·Object facade(리플렉션 static 제거)·legacy 접근자 차단. 저장측 검증·정적 검사와 3계층 동형. - secret 게이트: 비밀글의 댓글·첨부·문의 독립 경로 재적용, hash 파일서빙 소유권·비밀·발행 상태 검사 통일. - 신뢰 스크립트 호스트: 확장 선언 기반 + same-origin 브라우저 정규화를 런타임·저장측·정적검사 3층 동형화. - 회귀 감지: 단위·Feature·E2E·시나리오 매니페스트 전축 + audit 룰 4종 신설.
This commit is contained in:
1 parent
cd84b63d2b
commit
71abdeaf60
249 files changed
+14354
-1134
No files matched your search
@@ -3,11 +3,13 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Repositories\RoleRepositoryInterface;
|
||||
use App\Exceptions\CannotModifyProtectedRoleException;
|
||||
use App\Exceptions\ExtensionOwnedRoleDeleteException;
|
||||
use App\Exceptions\SystemRoleDeleteException;
|
||||
use App\Extension\HookManager;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Support\PermissionEscalationGuard;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -17,7 +19,8 @@ use Illuminate\Support\Str;
|
||||
class RoleService
|
||||
{
|
||||
public function __construct(
|
||||
private RoleRepositoryInterface $roleRepository
|
||||
private RoleRepositoryInterface $roleRepository,
|
||||
private PermissionEscalationGuard $escalationGuard
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -105,6 +108,12 @@ class RoleService
|
||||
$permissions = $data['permissions'] ?? [];
|
||||
unset($data['permissions']);
|
||||
|
||||
// 권한 상승 상한을 **역할 생성 전에** 검사한다. 생성 뒤에 검사하면 거부된 요청이
|
||||
// 권한 0개짜리 고아 역할 행을 남긴다(사용자 경로와 동일한 "가드 → 쓰기" 순서).
|
||||
if (! empty($permissions)) {
|
||||
$this->escalationGuard->assertGrantWithinActorCeiling($permissions);
|
||||
}
|
||||
|
||||
// 훅: 생성 전
|
||||
HookManager::doAction('core.role.before_create', $data);
|
||||
|
||||
@@ -134,10 +143,20 @@ class RoleService
|
||||
*/
|
||||
public function updateRole(Role $role, array $data): Role
|
||||
{
|
||||
// 보호된 역할(코어/확장 소유) 수정 상한: 삭제 경로와 대칭.
|
||||
// 비-슈퍼관리자 액터는 admin 등 코어/확장 소유 역할을 변경할 수 없다.
|
||||
$this->assertActorMayModifyRole($role);
|
||||
|
||||
// 권한 목록 분리
|
||||
$permissions = $data['permissions'] ?? null;
|
||||
unset($data['permissions']);
|
||||
|
||||
// 권한 상승 상한을 **속성 업데이트 전에** 검사한다. update 뒤에 검사하면
|
||||
// 403 을 받은 요청이 name/is_active 변경만 반영된 상태를 남긴다.
|
||||
if ($permissions !== null) {
|
||||
$this->escalationGuard->assertGrantWithinActorCeiling($permissions);
|
||||
}
|
||||
|
||||
// 훅: 업데이트 전 (원본 data 전달)
|
||||
HookManager::doAction('core.role.before_update', $role, $data);
|
||||
|
||||
@@ -213,6 +232,15 @@ class RoleService
|
||||
*/
|
||||
public function syncPermissions(Role $role, array $permissions): void
|
||||
{
|
||||
// 보호된 역할(코어/확장 소유) 수정 상한: updateRole·toggleRoleStatus 와 대칭.
|
||||
// 이 메서드는 public 이므로 서비스를 주입한 확장이 직접 호출할 수 있다 —
|
||||
// 형제 경로에만 가드를 두면 여기가 코어 역할 보호의 우회로가 된다.
|
||||
$this->assertActorMayModifyRole($role);
|
||||
|
||||
// 권한 상승 상한(ceiling): 비-슈퍼관리자 액터는 자신이 보유하지 않았거나
|
||||
// 자신의 범위(scope)보다 넓은 범위의 권한을 부여할 수 없다(SSoT 가드에 위임).
|
||||
$this->escalationGuard->assertGrantWithinActorCeiling($permissions);
|
||||
|
||||
// 동기화 전 현재 권한 식별자 캡처 (Listener diff 계산용)
|
||||
$previousPermIdentifiers = $role->permissions()->pluck('identifier')->toArray();
|
||||
|
||||
@@ -244,6 +272,9 @@ class RoleService
|
||||
*/
|
||||
public function toggleRoleStatus(Role $role): bool
|
||||
{
|
||||
// 보호된 역할(코어/확장 소유) 상태변경 상한: 삭제 경로와 대칭.
|
||||
$this->assertActorMayModifyRole($role);
|
||||
|
||||
$newStatus = ! $role->is_active;
|
||||
|
||||
// 훅: 상태 변경 전
|
||||
@@ -259,6 +290,37 @@ class RoleService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 액터가 보호된 역할(코어/확장 소유)을 수정할 수 있는지 확인합니다.
|
||||
*
|
||||
* 인증 액터가 없으면(Artisan/내부 시더) 신뢰 경로로 간주해 통과시킵니다.
|
||||
* 슈퍼 관리자는 모든 역할을 수정할 수 있고, 그 외 액터는 삭제 경로와 동일하게
|
||||
* 코어/확장 소유 역할을 수정할 수 없습니다.
|
||||
*
|
||||
* @param Role $role 대상 역할
|
||||
*
|
||||
* @throws CannotModifyProtectedRoleException 상한 위반 시
|
||||
*/
|
||||
private function assertActorMayModifyRole(Role $role): void
|
||||
{
|
||||
$actor = Auth::user();
|
||||
|
||||
// 인증 액터 부재 = 내부/Artisan 신뢰 경로 → 가드 미적용
|
||||
if (! $actor instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 슈퍼 관리자는 모든 역할 수정 가능
|
||||
if ($actor->isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 비-슈퍼관리자는 코어/확장 소유 역할 수정 불가
|
||||
if ($role->isCore() || $role->isExtensionOwned()) {
|
||||
throw new CannotModifyProtectedRoleException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* name에서 identifier를 자동 생성합니다.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user