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
@@ -6,6 +6,7 @@ use App\Contracts\Extension\StorageInterface;
|
||||
use App\Contracts\Repositories\AttachmentRepositoryInterface;
|
||||
use App\Enums\AttachmentSourceType;
|
||||
use App\Extension\HookManager;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Models\Attachment;
|
||||
use App\Models\User;
|
||||
use App\Support\ImageResizer;
|
||||
@@ -231,6 +232,8 @@ class AttachmentService
|
||||
*/
|
||||
public function reorder(array $orderData): void
|
||||
{
|
||||
$this->assertReorderWithinScope($orderData);
|
||||
|
||||
// Before 훅
|
||||
HookManager::doAction('core.attachment.before_reorder', $orderData);
|
||||
|
||||
@@ -240,6 +243,44 @@ class AttachmentService
|
||||
HookManager::doAction('core.attachment.after_reorder', $orderData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 순서 변경 대상이 액터의 스코프 안에 있는지 검사합니다.
|
||||
*
|
||||
* `PATCH admin/attachments/reorder` 는 라우트 모델이 없는 정적 경로다. PermissionMiddleware
|
||||
* 는 `$request->route('attachment')` 가 Model 일 때만 스코프를 검사하고 없으면 목록
|
||||
* 엔드포인트로 보아 건너뛰므로(`PermissionMiddleware`), 상세 경로(`DELETE {attachment}`)가
|
||||
* 미들웨어로 강제하는 스코프 축이 이 경로에서만 비어 있었다. 배포 기본 역할 `manager` 가
|
||||
* `core.attachments.update` 를 `self` 스코프로 보유하므로 이론 구성이 아니라 기본값에서
|
||||
* 성립한다 — 타인 소유 첨부의 순서를 바꿀 수 있었다.
|
||||
*
|
||||
* 대상 일부만 걸러내지 않고 **전체를 거부**한다. 순서는 집합 전체에 대한 하나의 배열이라
|
||||
* 일부만 반영하면 나머지와 어긋난 순서가 저장되기 때문이다(사용자 일괄 상태변경이
|
||||
* "제외" 를 택한 것과 의미론이 다르다).
|
||||
*
|
||||
* @param array<int, array{id: int, order: int}> $orderData 순서 데이터
|
||||
*
|
||||
* @throws AuthorizationException 스코프 밖 첨부가 하나라도 포함된 경우
|
||||
*/
|
||||
private function assertReorderWithinScope(array $orderData): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_filter(
|
||||
array_map(static fn ($item): int => (int) ($item['id'] ?? 0), $orderData)
|
||||
)));
|
||||
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attachments = $this->repository->findByIds($ids);
|
||||
|
||||
// 판정은 상세 경로와 같은 SSoT 에 위임한다 — 여기서 재구현하면 두 경로의 강도가 갈린다.
|
||||
$permitted = PermissionHelper::filterByScope($attachments, 'core.attachments.update');
|
||||
|
||||
if (count($permitted) !== $attachments->count()) {
|
||||
throw new AuthorizationException(__('auth.scope_denied'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 다운로드 응답 생성
|
||||
*
|
||||
|
||||
@@ -7,8 +7,10 @@ use App\Contracts\Repositories\RoleRepositoryInterface;
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Enums\MenuPermissionType;
|
||||
use App\Extension\HookManager;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Models\Menu;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -203,11 +205,19 @@ class MenuService
|
||||
/**
|
||||
* 메뉴 순서를 업데이트합니다 (드래그 앤 드롭).
|
||||
*
|
||||
* 형제 `updateMenuOrderWithHierarchy` 와 같은 리소스를 같은 방식으로 쓰므로 스코프
|
||||
* 가드도 대칭이어야 한다. 코어 내 호출부가 없다는 사실은 방어가 아니다 — 이 서비스는
|
||||
* 확장이 주입받을 수 있고, 가드가 형제 경로에만 있으면 여기가 우회로가 된다.
|
||||
*
|
||||
* @param array $menuOrders 메뉴 ID와 순서 매핑 배열
|
||||
* @return bool 업데이트 성공 여부
|
||||
*
|
||||
* @throws AuthorizationException 스코프 밖 메뉴가 하나라도 포함된 경우
|
||||
*/
|
||||
public function updateMenuOrder(array $menuOrders): bool
|
||||
{
|
||||
$this->assertMenusWithinScope(array_map('intval', array_values($menuOrders)));
|
||||
|
||||
// 훅: 메뉴 순서 변경 전 (IDV 정책 가드 지점)
|
||||
HookManager::doAction('core.menu.before_update_order', $menuOrders);
|
||||
|
||||
@@ -227,6 +237,8 @@ class MenuService
|
||||
*/
|
||||
public function updateMenuOrderWithHierarchy(array $orderData): bool
|
||||
{
|
||||
$this->assertOrderTargetsWithinScope($orderData);
|
||||
|
||||
$result = $this->menuRepository->updateOrderWithHierarchy($orderData);
|
||||
|
||||
// 훅: 메뉴 계층 순서 변경 후
|
||||
@@ -235,6 +247,74 @@ class MenuService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 순서 변경 대상 메뉴가 액터의 스코프 안에 있는지 검사합니다.
|
||||
*
|
||||
* `PUT admin/menus/order` 는 라우트 모델이 없는 정적 경로라 PermissionMiddleware 의
|
||||
* 스코프 검사가 스킵된다(`{menu}` 파라미터 부재 → "목록 엔드포인트" 로 간주). 상세
|
||||
* 경로(`PUT menus/{menu}`)가 미들웨어로 강제하는 축이 이 경로에서만 비어 있었다.
|
||||
* 배포 기본 역할은 `core.menus.update` 를 글로벌로 주므로 기본값 노출은 아니지만,
|
||||
* 운영자가 역할 화면에서 스코프를 self/role 로 좁히는 순간 우회로가 된다.
|
||||
*
|
||||
* 첨부 순서 변경과 같은 이유로 **전량 거부**다 — 순서는 트리 전체에 대한 하나의
|
||||
* 배열이라 일부만 반영하면 나머지와 어긋난 계층이 저장된다.
|
||||
*
|
||||
* @param array $orderData 순서 데이터 (parent_menus / child_menus / moved_items)
|
||||
*
|
||||
* @throws AuthorizationException 스코프 밖 메뉴가 하나라도 포함된 경우
|
||||
*/
|
||||
private function assertOrderTargetsWithinScope(array $orderData): void
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($orderData['parent_menus'] ?? [] as $item) {
|
||||
$ids[] = (int) ($item['id'] ?? 0);
|
||||
}
|
||||
|
||||
foreach ($orderData['child_menus'] ?? [] as $children) {
|
||||
foreach ($children as $item) {
|
||||
$ids[] = (int) ($item['id'] ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 이동 항목은 **옮기는 메뉴 자신**만 확인한다. 새 부모까지 검사하면, 공용 상위 메뉴
|
||||
// 아래에 자기 메뉴를 다는 정상 사용이 막힌다 — 결함은 "남의 메뉴 순서를 바꾼다" 였지
|
||||
// "남의 메뉴 아래에 못 붙인다" 가 아니다.
|
||||
foreach ($orderData['moved_items'] ?? [] as $item) {
|
||||
$ids[] = (int) ($item['id'] ?? 0);
|
||||
}
|
||||
|
||||
$this->assertMenusWithinScope($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 메뉴 ID 집합이 전부 액터의 스코프 안에 있는지 검사합니다.
|
||||
*
|
||||
* 순서 변경 두 경로(`updateMenuOrder` · `updateMenuOrderWithHierarchy`)가 공유하는
|
||||
* 판정부다. 한쪽만 검사하면 형제 경로가 우회로가 되므로 판정을 한 곳에 둔다.
|
||||
*
|
||||
* @param array<int> $ids 검사 대상 메뉴 ID 목록
|
||||
*
|
||||
* @throws AuthorizationException 스코프 밖 메뉴가 하나라도 포함된 경우
|
||||
*/
|
||||
private function assertMenusWithinScope(array $ids): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_filter($ids)));
|
||||
|
||||
if (empty($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$menus = $this->menuRepository->findByIds($ids);
|
||||
|
||||
// 판정은 상세 경로와 같은 SSoT 에 위임한다.
|
||||
$permitted = PermissionHelper::filterByScope($menus, 'core.menus.update');
|
||||
|
||||
if (count($permitted) !== $menus->count()) {
|
||||
throw new AuthorizationException(__('auth.scope_denied'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴의 활성화 상태를 토글합니다.
|
||||
*
|
||||
|
||||
@@ -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를 자동 생성합니다.
|
||||
*
|
||||
|
||||
@@ -6,12 +6,15 @@ use App\Contracts\Repositories\RoleRepositoryInterface;
|
||||
use App\Contracts\Repositories\UserRepositoryInterface;
|
||||
use App\Enums\UserStatus;
|
||||
use App\Exceptions\CannotDeleteSuperAdminException;
|
||||
use App\Exceptions\PermissionEscalationException;
|
||||
use App\Extension\HookManager;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Helpers\TimezoneHelper;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Attachment;
|
||||
use App\Models\User;
|
||||
use App\Support\PermissionEscalationGuard;
|
||||
use App\Support\UserGradeGuard;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
@@ -26,7 +29,8 @@ class UserService
|
||||
public function __construct(
|
||||
private UserRepositoryInterface $userRepository,
|
||||
private RoleRepositoryInterface $roleRepository,
|
||||
private AttachmentService $attachmentService
|
||||
private AttachmentService $attachmentService,
|
||||
private PermissionEscalationGuard $escalationGuard
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -79,10 +83,19 @@ class UserService
|
||||
}
|
||||
unset($data['roles']);
|
||||
|
||||
// 역할 할당 권한 체크: core.permissions.update 권한 없으면 기본 역할 자동 할당
|
||||
if (! PermissionHelper::check('core.permissions.update')) {
|
||||
// 역할 할당: 요청 역할이 없으면 기본 역할('user')을 자동 배정하고, 요청 역할이
|
||||
// 있으면 액터 상한(ceiling) 검사만 받는다.
|
||||
//
|
||||
// 역할 부여는 "사용자 관리"(core.users.create — 이 경로는 라우트에서 이미 강제됨)의
|
||||
// 일부이지, "역할 정의 수정"(core.permissions.update — 역할에 권한을 가감하는 권한)을
|
||||
// 요구하지 않는다. 권한 상승 방지는 오직 상한(ceiling)이 담당한다: 액터가 보유하지
|
||||
// 않았거나 자신의 범위보다 넓은 권한을 담은 역할은 부여할 수 없다(KVE-2026-1919).
|
||||
// 신규 사용자는 기존 역할이 없으므로 요청 역할 전부가 새로 부여되는 역할이다.
|
||||
if ($roleIds === null || count($roleIds) === 0) {
|
||||
$defaultRoleId = $this->roleRepository->findByIdentifier('user')?->id;
|
||||
$roleIds = $defaultRoleId ? [$defaultRoleId] : null;
|
||||
} else {
|
||||
$this->escalationGuard->assertRoleAssignmentWithinActorCeiling($roleIds);
|
||||
}
|
||||
|
||||
$user = $this->userRepository->create($data);
|
||||
@@ -102,6 +115,11 @@ class UserService
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// 권한 상승 상한 위반은 그대로 전파해 컨트롤러가 403 으로 매핑하도록 한다.
|
||||
if ($e instanceof PermissionEscalationException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'general' => [__('user.create_failed', ['error' => $e->getMessage()])],
|
||||
]);
|
||||
@@ -119,6 +137,10 @@ class UserService
|
||||
*/
|
||||
public function updateUser(User $user, array $data): User
|
||||
{
|
||||
// 등급 상한 가드: 비-슈퍼관리자 액터는 슈퍼 관리자 계정을 수정할 수 없다.
|
||||
// (비밀번호·status(withdrawn/blocked)·email 등 모든 수정 경로를 한 지점에서 차단)
|
||||
UserGradeGuard::assertActorMayModify($user);
|
||||
|
||||
try {
|
||||
// 원본 데이터 보관 (after_update 훅에서 사용)
|
||||
$originalData = $data;
|
||||
@@ -148,17 +170,35 @@ class UserService
|
||||
}
|
||||
unset($data['roles']);
|
||||
|
||||
// 역할 할당 권한 체크
|
||||
// 역할 할당
|
||||
if ($roleIds !== null) {
|
||||
$authUser = Auth::user();
|
||||
|
||||
// core.permissions.update 권한 없으면 역할 변경 불가
|
||||
if (! PermissionHelper::check('core.permissions.update', $authUser)) {
|
||||
$roleIds = null;
|
||||
// 역할 조작 상한(ceiling): 이번 변경으로 붙거나 떨어지는 역할이 액터가 전부
|
||||
// 부여할 수 있는 권한만 담고 있는지 확인한다(KVE-2026-1919). 역할 부여는
|
||||
// "사용자 관리"(core.users.update — 이 경로는 라우트에서 이미 강제됨)의 일부이며,
|
||||
// "역할 정의 수정"(core.permissions.update — 역할에 권한을 가감하는 권한)을
|
||||
// 요구하지 않는다. 권한 상승 방지는 오직 상한이 담당한다: 액터가 보유하지
|
||||
// 않았거나 자신의 범위보다 넓은 권한을 담은 역할은 부여할 수 없고, 위반 시
|
||||
// PermissionEscalationException 이 전파되어 403 으로 명시 거부된다(과거처럼 조용히
|
||||
// 무시하지 않는다).
|
||||
//
|
||||
// 검사 대상은 **추가·제거 양방향의 변경분**이다. 추가는 그 역할의 권한을
|
||||
// 부여하는 것이고, 제거는 상위 역할의 권한 구성을 박탈하는 하향 조작이므로 —
|
||||
// 액터가 스스로 부여할 수 없는(상한 밖) 역할은 붙이지도 떼지도 못한다. 추가만
|
||||
// 검사하면 core.users.update 만 가진 하위 관리자가 다른 관리자의 상위 역할을
|
||||
// 박탈하는 경로가 상한 없이 뚫린다. 기존 유지 역할은 변경이 아니므로 제외한다.
|
||||
$currentRoleIds = $user->roles->pluck('id')->all();
|
||||
$changedRoleIds = array_values(array_unique(array_merge(
|
||||
array_diff($roleIds, $currentRoleIds), // 추가되는 역할
|
||||
array_diff($currentRoleIds, $roleIds), // 제거되는 역할
|
||||
)));
|
||||
if (! empty($changedRoleIds)) {
|
||||
$this->escalationGuard->assertRoleAssignmentWithinActorCeiling($changedRoleIds);
|
||||
}
|
||||
|
||||
// 자기잠금 방지: 마지막 admin 역할 사용자가 자기 admin 역할을 제거하려는 경우 차단
|
||||
if ($roleIds !== null && $authUser && $authUser->id === $user->id) {
|
||||
if ($authUser && $authUser->id === $user->id) {
|
||||
$adminRole = $this->roleRepository->findByIdentifier('admin');
|
||||
if ($adminRole && $user->roles->contains('id', $adminRole->id) && ! in_array($adminRole->id, $roleIds)) {
|
||||
// admin 역할을 가진 다른 사용자가 있는지 확인
|
||||
@@ -261,6 +301,12 @@ class UserService
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// 권한 상승 상한 위반은 그대로 전파해 컨트롤러가 403 으로 매핑하도록 한다
|
||||
// (일반 실패로 감싸면 422 로 잘못 내려간다).
|
||||
if ($e instanceof PermissionEscalationException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'general' => [__('user.update_failed', ['error' => $e->getMessage()])],
|
||||
]);
|
||||
@@ -589,22 +635,6 @@ class UserService
|
||||
return $excludeUserUuid && $user->uuid === $excludeUserUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 활성화 상태를 업데이트합니다.
|
||||
* 현재는 구현되지 않음 - 필요시 확장 가능
|
||||
*
|
||||
* @param User $user 대상 사용자 모델
|
||||
* @param bool $isActive 활성화 상태
|
||||
* @return User 사용자 모델
|
||||
*/
|
||||
public function updateUserStatus(User $user, bool $isActive): User
|
||||
{
|
||||
// 현재 User 모델에 is_active 필드가 없으므로 필요시 추가
|
||||
// $this->userRepository->update($user, ['is_active' => $isActive]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 활동 로그를 조회합니다.
|
||||
*
|
||||
@@ -640,6 +670,9 @@ class UserService
|
||||
*/
|
||||
public function unlockAccount(User $user): User
|
||||
{
|
||||
// 등급 상한 가드: 비-슈퍼관리자 액터는 슈퍼 관리자 계정을 조작할 수 없다(정합성).
|
||||
UserGradeGuard::assertActorMayModify($user);
|
||||
|
||||
HookManager::doAction('core.user.before_unlock', $user);
|
||||
|
||||
$this->userRepository->resetLoginAttempts($user);
|
||||
@@ -653,19 +686,6 @@ class UserService
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 마지막 로그인 시간을 현재 시간으로 업데이트합니다.
|
||||
*
|
||||
* @param User $user 대상 사용자 모델
|
||||
* @return User 업데이트된 사용자 모델
|
||||
*/
|
||||
public function updateLastLogin(User $user): User
|
||||
{
|
||||
$this->userRepository->update($user, ['last_login_at' => now()]);
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 언어 설정을 업데이트합니다.
|
||||
*
|
||||
@@ -698,14 +718,38 @@ class UserService
|
||||
|
||||
$statusEnum = UserStatus::from($status);
|
||||
|
||||
// 정적 라우트(`PATCH users/bulk-status`)는 라우트 모델이 없어 PermissionMiddleware 의
|
||||
// 스코프 검사가 통째로 건너뛰어진다. 따라서 상세 경로(`PUT users/{user}`)가 미들웨어로
|
||||
// 강제하는 두 축을 서비스 계층에서 재적용한다 — 어느 한 축만 막으면 나머지가 우회로다.
|
||||
// 탈퇴 분기보다 먼저 적용해야 한다 — 뒤에 두면 탈퇴 경로가 스코프 검사를 건너뛰는
|
||||
// 우회로가 된다(KVE-1919).
|
||||
$targets = $this->userRepository->findManyByUuids($uuids);
|
||||
|
||||
// ① 등급 축: 비-슈퍼관리자 액터가 포함시킨 슈퍼 관리자 대상은 제외한다
|
||||
// (슈퍼 관리자 무력화 차단 — 슈퍼 세션 유지).
|
||||
$modifiable = UserGradeGuard::filterModifiable($targets);
|
||||
|
||||
// ② 스코프 축: 액터의 유효 스코프(self/role/글로벌) 밖 대상은 제외한다.
|
||||
// 판정은 상세 경로와 동일한 SSoT(PermissionHelper::checkScopeAccess)에 위임한다 —
|
||||
// 여기서 재구현하면 role 분기만 빠지는 식으로 두 경로의 강도가 갈린다.
|
||||
$modifiable = PermissionHelper::filterByScope($modifiable, 'core.users.update');
|
||||
|
||||
// 일괄 '탈퇴'는 건별 정식 탈퇴로 전환한다 — 상태 컬럼만 바꾸면 익명화와
|
||||
// before/after_withdraw 훅이 통째로 생략되어, 본인 탈퇴와 결과가 달라진다.
|
||||
// 위에서 등급·스코프로 걸러낸 대상에 한해서만 수행한다.
|
||||
if ($statusEnum === UserStatus::Withdrawn) {
|
||||
return $this->bulkWithdraw($uuids, $status);
|
||||
$modifiableUuids = array_map(static fn (User $u): string => $u->uuid, $modifiable);
|
||||
|
||||
return $this->bulkWithdraw($modifiableUuids, $status);
|
||||
}
|
||||
|
||||
// UUID → 정수 ID 변환 (내부 쿼리용)
|
||||
$userIds = $this->userRepository->getIdsByUuids($uuids);
|
||||
$userIds = array_map(static fn (User $u): int => $u->id, $modifiable);
|
||||
|
||||
if (empty($userIds)) {
|
||||
HookManager::doAction('sirsoft-core.user.after_bulk_update', $uuids, $status, 0);
|
||||
|
||||
return ['updated_count' => 0];
|
||||
}
|
||||
|
||||
// DB 트랜잭션으로 일괄 업데이트
|
||||
$updatedCount = DB::transaction(function () use ($userIds, $statusEnum) {
|
||||
|
||||
Reference in new issue
Block a user