v7.0.0 release
This commit is contained in:
1 parent
0e7fa04b03
commit
c4ea9a6cd1
3582 files changed
+626189
-160151
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\IdentityPolicy;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
/**
|
||||
* 같은 적용 지점(scope + target)에 동률 우선순위(priority) 정책이 둘 이상 활성화되는 것을 차단하는 Rule.
|
||||
*
|
||||
* 배경: 본인인증 정책은 같은 scope+target 에 여러 개 걸릴 수 있는데, 동일 priority 면
|
||||
* 어느 정책이 먼저 enforce 되는지(어떤 purpose 로 challenge 되는지)가 비결정적이 된다. 운영자가
|
||||
* 우선순위 입력으로 순서를 정하더라도 같은 값을 넣으면 동률이 재발하므로, 저장 시점에 동률을
|
||||
* 차단해 "의도한 인증(예: 성인 인증)이 무시되고 임의 정책이 적용"되는 결함을 원천 봉쇄한다.
|
||||
*
|
||||
* 비활성(enabled=false) 정책은 enforce 되지 않아 동률이어도 무해하므로, 저장하려는 정책이
|
||||
* 활성일 때만, 그리고 기존 활성 정책에 대해서만 충돌을 검사한다.
|
||||
*/
|
||||
class UniquePolicyPriorityPerTarget implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* @param string $scope 적용 시점 (route|hook) — 저장하려는 정책 기준
|
||||
* @param string $target 적용 위치 (route name 또는 hook name)
|
||||
* @param bool $enabled 저장하려는 정책의 활성 여부
|
||||
* @param int|null $ignoreId 수정 시 자기 자신을 충돌 검사에서 제외하기 위한 정책 ID
|
||||
*/
|
||||
public function __construct(
|
||||
private string $scope,
|
||||
private string $target,
|
||||
private bool $enabled,
|
||||
private ?int $ignoreId = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 검증 수행 — 같은 scope+target+priority 의 활성 정책이 이미 있으면 실패.
|
||||
*
|
||||
* @param string $attribute 검증 대상 속성명 (priority)
|
||||
* @param mixed $value 검증 대상 값 (우선순위 정수)
|
||||
* @param Closure $fail 실패 콜백
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
// 저장하려는 정책이 비활성이면 동률이어도 enforce 되지 않으므로 검사 불필요.
|
||||
if (! $this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// scope/target 미상(수정 요청에 미포함 등)이면 검사 불가 — 통과시키고 다른 규칙에 위임.
|
||||
if ($this->scope === '' || $this->target === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value === null || $value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$priority = (int) $value;
|
||||
|
||||
$conflict = IdentityPolicy::query()
|
||||
->where('scope', $this->scope)
|
||||
->where('target', $this->target)
|
||||
->where('priority', $priority)
|
||||
->where('enabled', true)
|
||||
->when($this->ignoreId !== null, fn ($q) => $q->where('id', '!=', $this->ignoreId))
|
||||
->exists();
|
||||
|
||||
if ($conflict) {
|
||||
$fail(__('validation.identity_policy.priority_duplicate', [
|
||||
'target' => $this->target,
|
||||
'priority' => $priority,
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
/**
|
||||
* 레이아웃 확장 정의 구조 검증
|
||||
*
|
||||
* 모듈/플러그인이 레이아웃에 주입하는 확장 정의(extension_point / overlay)의
|
||||
* JSON 구조를 검증합니다.
|
||||
*
|
||||
* - extension_point 타입: `extension_point` 키 + `components` 배열
|
||||
* - overlay 타입: `target_layout` 키 + `injections` 배열
|
||||
* - 두 키는 상호 배타적 (xor)
|
||||
*/
|
||||
class ValidLayoutExtensionStructure implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* 최대 중첩 깊이
|
||||
*/
|
||||
private const MAX_DEPTH = 10;
|
||||
|
||||
/**
|
||||
* 레이아웃 확장 JSON 스키마 검증
|
||||
*
|
||||
* @param string $attribute 속성명
|
||||
* @param mixed $value 검증 대상 값
|
||||
* @param Closure $fail 실패 콜백
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
// JSON 문자열인 경우 디코딩
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$fail(__('validation.layout_extension.invalid_json'));
|
||||
|
||||
return;
|
||||
}
|
||||
$value = $decoded;
|
||||
}
|
||||
|
||||
if (! is_array($value)) {
|
||||
$fail(__('validation.layout_extension.must_be_array'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// extension_point xor target_layout
|
||||
$hasExtensionPoint = isset($value['extension_point']);
|
||||
$hasTargetLayout = isset($value['target_layout']);
|
||||
|
||||
if (! $hasExtensionPoint && ! $hasTargetLayout) {
|
||||
$fail(__('validation.layout_extension.target_required'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($hasExtensionPoint && $hasTargetLayout) {
|
||||
$fail(__('validation.layout_extension.target_exclusive'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($hasExtensionPoint) {
|
||||
$this->validateExtensionPoint($value, $fail);
|
||||
} else {
|
||||
$this->validateOverlay($value, $fail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* extension_point 타입 검증
|
||||
*
|
||||
* @param array $data 확장 정의
|
||||
* @param Closure $fail 실패 콜백
|
||||
*/
|
||||
private function validateExtensionPoint(array $data, Closure $fail): void
|
||||
{
|
||||
if (! is_string($data['extension_point']) || $data['extension_point'] === '') {
|
||||
$fail(__('validation.layout_extension.extension_point_invalid'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// components 검증 (선택 — 빈 확장점도 허용)
|
||||
if (isset($data['components'])) {
|
||||
if (! is_array($data['components'])) {
|
||||
$fail(__('validation.layout_extension.components_must_be_array'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($data['components'] as $index => $component) {
|
||||
if (! $this->validateComponent($component, $index, $fail)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->validateOptionalSections($data, $fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay 타입 검증
|
||||
*
|
||||
* @param array $data 확장 정의
|
||||
* @param Closure $fail 실패 콜백
|
||||
*/
|
||||
private function validateOverlay(array $data, Closure $fail): void
|
||||
{
|
||||
if (! is_string($data['target_layout']) || $data['target_layout'] === '') {
|
||||
$fail(__('validation.layout_extension.target_layout_invalid'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// injections 검증
|
||||
if (! isset($data['injections'])) {
|
||||
$fail(__('validation.layout_extension.injections_required'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_array($data['injections'])) {
|
||||
$fail(__('validation.layout_extension.injections_must_be_array'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($data['injections'] as $index => $injection) {
|
||||
if (! $this->validateInjection($injection, $index, $fail)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->validateOptionalSections($data, $fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 injection 항목 검증
|
||||
*
|
||||
* @param mixed $injection injection 정의
|
||||
* @param int|string $index 인덱스
|
||||
* @param Closure $fail 실패 콜백
|
||||
* @return bool 유효 여부
|
||||
*/
|
||||
private function validateInjection(mixed $injection, int|string $index, Closure $fail): bool
|
||||
{
|
||||
if (! is_array($injection)) {
|
||||
$fail(__('validation.layout_extension.injection_must_be_array', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// target_id 필수
|
||||
if (! isset($injection['target_id']) || ! is_string($injection['target_id'])) {
|
||||
$fail(__('validation.layout_extension.injection_target_id_required', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// position 검증 (선택 — 기본 append_child)
|
||||
$validPositions = ['prepend', 'append', 'prepend_child', 'append_child', 'replace', 'inject_props'];
|
||||
$position = $injection['position'] ?? 'append_child';
|
||||
if (! in_array($position, $validPositions, true)) {
|
||||
$fail(__('validation.layout_extension.injection_position_invalid', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// inject_props 가 아니면 components 검증
|
||||
if ($position !== 'inject_props' && isset($injection['components'])) {
|
||||
if (! is_array($injection['components'])) {
|
||||
$fail(__('validation.layout_extension.injection_components_must_be_array', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($injection['components'] as $compIndex => $component) {
|
||||
if (! $this->validateComponent($component, "{$index}.{$compIndex}", $fail)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inject_props 는 props 배열 검증
|
||||
if ($position === 'inject_props' && isset($injection['props']) && ! is_array($injection['props'])) {
|
||||
$fail(__('validation.layout_extension.injection_props_must_be_array', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 선택적 섹션(data_sources, modals, scripts, computed, state, init_actions) 타입 검증
|
||||
*
|
||||
* @param array $data 확장 정의
|
||||
* @param Closure $fail 실패 콜백
|
||||
*/
|
||||
private function validateOptionalSections(array $data, Closure $fail): void
|
||||
{
|
||||
foreach (['data_sources', 'modals', 'scripts', 'computed', 'state', 'init_actions'] as $section) {
|
||||
if (isset($data[$section]) && ! is_array($data[$section])) {
|
||||
$fail(__('validation.layout_extension.section_must_be_array', ['section' => $section]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 개별 컴포넌트 노드 검증 (ValidLayoutStructure 재귀 로직 참고)
|
||||
*
|
||||
* @param mixed $component 컴포넌트 노드
|
||||
* @param int|string $index 인덱스
|
||||
* @param Closure $fail 실패 콜백
|
||||
* @param int $depth 현재 깊이
|
||||
* @return bool 유효 여부
|
||||
*/
|
||||
private function validateComponent(mixed $component, int|string $index, Closure $fail, int $depth = 0): bool
|
||||
{
|
||||
if ($depth > self::MAX_DEPTH) {
|
||||
$fail(__('validation.layout_extension.max_depth_exceeded', ['max' => self::MAX_DEPTH]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! is_array($component)) {
|
||||
$fail(__('validation.layout_extension.component_must_be_array', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 슬롯/Partial 참조는 type/name 검증 건너뜀
|
||||
if ((isset($component['slot']) && is_string($component['slot']))
|
||||
|| (isset($component['partial']) && is_string($component['partial']))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// extension_point 노드는 type 만 있으면 됨 (중첩 확장점 허용)
|
||||
if (($component['type'] ?? '') === 'extension_point') {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (['type', 'name'] as $field) {
|
||||
if (! isset($component[$field])) {
|
||||
$fail(__('validation.layout_extension.component_required_field_missing', ['index' => $index, 'field' => $field]));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! is_string($component['name'])) {
|
||||
$fail(__('validation.layout_extension.component_name_must_be_string', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! in_array($component['type'], ['basic', 'composite', 'layout'], true)) {
|
||||
$fail(__('validation.layout_extension.component_type_invalid', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($component['props']) && ! is_array($component['props']) && ! is_object($component['props'])) {
|
||||
$fail(__('validation.layout_extension.props_must_be_object', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// children 재귀 검증
|
||||
if (isset($component['children'])) {
|
||||
if (! is_array($component['children'])) {
|
||||
$fail(__('validation.layout_extension.children_must_be_array', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($component['children'] as $childIndex => $child) {
|
||||
if (! $this->validateComponent($child, "{$index}.children[{$childIndex}]", $fail, $depth + 1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -172,8 +172,13 @@ class ValidLayoutStructure implements ValidationRule
|
||||
return false;
|
||||
}
|
||||
|
||||
// type 필드 검증
|
||||
if (! in_array($component['type'], ['basic', 'composite', 'layout'])) {
|
||||
// type 필드 검증 — basic/composite/layout 외에 extension_point 도 정상 노드 타입이다.
|
||||
// extension_point 노드(예: `user_global_overlay`, `identity_provider_ui:provider`)는
|
||||
// 호스트 레이아웃에 선언되는 확장 주입 지점으로, type="extension_point" + name(슬롯명) +
|
||||
// default/children 구조를 가진다. 이를 허용하지 않으면 extension_point 를 포함한 레이아웃
|
||||
// (`_user_base` 등)을 편집기에서 저장할 수 없다(`components[N].children[0].type`
|
||||
// 422). ValidLayoutExtensionStructure 가 이미 동일하게 extension_point 를 예외 허용한다.
|
||||
if (! in_array($component['type'], ['basic', 'composite', 'layout', 'extension_point'], true)) {
|
||||
$fail(__('validation.layout.component_type_invalid', ['index' => $index]));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -8,16 +8,19 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
||||
/**
|
||||
* API 엔드포인트 화이트리스트 검증 Rule
|
||||
*
|
||||
* /api/(admin|auth|public)/ 패턴만 허용하고 다른 모든 엔드포인트를 차단합니다.
|
||||
* 코어가 등록하는 API 라우트 네임스페이스만 허용하고 다른 모든 엔드포인트를 차단합니다.
|
||||
* 외부 URL, 내부 API, 직접 경로 접근 등을 방지하여 보안을 강화합니다.
|
||||
*
|
||||
* 허용 패턴:
|
||||
* - /api/admin/*
|
||||
* - /api/auth/*
|
||||
* - /api/public/*
|
||||
* - /api/modules/{vendor-module}/* (ModuleRouteServiceProvider 가 등록하는 모듈 API 프리픽스)
|
||||
* - /api/plugins/{vendor-plugin}/* (PluginRouteServiceProvider 가 등록하는 플러그인 API 프리픽스)
|
||||
*
|
||||
* 차단 패턴:
|
||||
* - /api/internal/*
|
||||
* - /api/modules/* (확장 식별자 vendor-name 형식이 아닌 세그먼트)
|
||||
* - /admin/* (직접 경로)
|
||||
* - http://* (외부 URL)
|
||||
* - https://* (외부 URL)
|
||||
@@ -26,8 +29,12 @@ class WhitelistedEndpoint implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* 허용된 API 엔드포인트 패턴
|
||||
*
|
||||
* modules/plugins 프리픽스는 확장 식별자(vendor-name — 하이픈 포함 필수) 세그먼트가
|
||||
* 뒤따를 때만 허용한다. 하이픈을 강제해 /api/modules/assets/ 등 비확장 세그먼트는
|
||||
* 화이트리스트에 포함되지 않는다.
|
||||
*/
|
||||
private const ALLOWED_PATTERN = '/^\/api\/(admin|auth|public)\//';
|
||||
private const ALLOWED_PATTERN = '/^\/api\/((admin|auth|public)\/|(modules|plugins)\/[a-z0-9][a-z0-9_]*(-[a-z0-9_]+)+\/)/';
|
||||
|
||||
/**
|
||||
* 검증 규칙 실행
|
||||
@@ -132,7 +139,7 @@ class WhitelistedEndpoint implements ValidationRule
|
||||
|
||||
// 화이트리스트 패턴 검증
|
||||
if (! preg_match(self::ALLOWED_PATTERN, $value)) {
|
||||
$fail(__('validation.endpoint.not_whitelisted', ['pattern' => '/api/(admin|auth|public)/']));
|
||||
$fail(__('validation.endpoint.not_whitelisted', ['pattern' => '/api/(admin|auth|public)/, /api/(modules|plugins)/{vendor-id}/']));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user