fix(security): outbound URL 내부주소·host 검증 전수 강화

서버가 외부 입력으로 목적지가 제어되는 outbound HTTP 요청을 보내는 지점을
전수 조사해, 내부망(사설 IP·루프백·링크로컬·메타데이터)과 host 위조를 차단한다.
KVE-2026-1546(이니시스 인증 URL 접두사 매칭 우회)과 동일 클래스의
지점(언어팩 URL 설치, 스케줄 URL 호출, 배송비 계산 API, GitHub URL 판정)을
코어 공용 유틸 App\Support\OutboundUrlValidator 로 수렴시켰다.

- 접두사 매칭을 host 완전일치로 교체 — userinfo(@) 위장과 접미사 확장 도메인
 우회 벡터 차단.
- 사내 서버 호출이 정당한 관리자 지점(스케줄·외부 API)은 신규 설정
 security.allow_internal_outbound_urls(기본 off)로 옵트인.
- 언어팩 URL 설치는 원격 코드 다운로드라 옵트인과 무관하게 내부 주소 항상 차단.
- 웹소켓 연결 테스트는 localhost·사설 IP 가 정상 구성이므로 구조적 위조만 차단.

각 지점에 red 재현 → 수정 → green 회귀 테스트 + 실브라우저 E2E 로 검증.
수기 API 문서가 자동 재생성으로 소실되는 사고를 막는 PreToolUse 훅을 함께 추가한다.
This commit is contained in:
HeuJung committed 2026-07-14 09:17:00 +09:00
1 parent f848086fd6
commit c4beb116ad
46 files changed
+1297 -55

No files matched your search

@@ -2,6 +2,8 @@
namespace App\Http\Requests\LanguagePack;
use App\Extension\HookManager;
use App\Rules\PublicOutboundUrl;
use Illuminate\Foundation\Http\FormRequest;
/**
@@ -26,11 +28,15 @@ class InstallFromUrlRequest extends FormRequest
*/
public function rules(): array
{
return [
'url' => ['required', 'url', 'max:500'],
$rules = [
// 원격 코드를 내려받는 지점이므로 https 고정 + 내부 주소 허용 설정과 무관하게 항상 차단
'url' => ['required', 'url', 'max:500', new PublicOutboundUrl(schemes: ['https'], allowInternalOptIn: false)],
'checksum' => ['nullable', 'string', 'regex:/^[a-f0-9]{64}$/i'],
'auto_activate' => ['nullable', 'boolean'],
];
// 모듈/플러그인이 validation rules 를 동적으로 추가할 수 있도록 훅 제공
return HookManager::applyFilters('core.language_packs.install_from_url_validation_rules', $rules, $this);
}
/**
@@ -6,13 +6,18 @@ use App\Enums\ExtensionOwnerType;
use App\Enums\ScheduleFrequency;
use App\Enums\ScheduleType;
use App\Extension\HookManager;
use App\Rules\PublicOutboundUrl;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class CreateScheduleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool 권한 검사는 라우트의 permission 미들웨어가 담당하므로 항상 true
*/
public function authorize(): bool
{
@@ -22,7 +27,7 @@ class CreateScheduleRequest extends FormRequest
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -33,7 +38,16 @@ class CreateScheduleRequest extends FormRequest
'name' => 'required|string|max:255',
'description' => 'nullable|string|max:1000',
'type' => "required|string|in:{$types}",
'command' => 'required|string|max:2000',
// URL 호출 스케줄이면 command 가 곧 서버의 outbound 목적지가 되므로 내부망 주소를 차단한다
'command' => [
'required',
'string',
'max:2000',
Rule::when(
$this->input('type') === ScheduleType::Url->value,
[new PublicOutboundUrl],
),
],
'expression' => 'required|string|max:100',
'frequency' => "required|string|in:{$frequencies}",
'without_overlapping' => 'boolean',
@@ -86,7 +100,9 @@ class CreateScheduleRequest extends FormRequest
}
/**
* 검증된 데이터 반환
* 검증된 데이터에 생성자(created_by)를 덧붙여 반환합니다.
*
* @return array<string, mixed> 검증된 입력 + created_by
*/
public function validatedWithCreator(): array
{
@@ -6,12 +6,18 @@ use App\Enums\ExtensionOwnerType;
use App\Enums\ScheduleFrequency;
use App\Enums\ScheduleType;
use App\Extension\HookManager;
use App\Models\Schedule;
use App\Rules\PublicOutboundUrl;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateScheduleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool 권한 검사는 라우트의 permission 미들웨어가 담당하므로 항상 true
*/
public function authorize(): bool
{
@@ -21,7 +27,7 @@ class UpdateScheduleRequest extends FormRequest
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -32,7 +38,14 @@ class UpdateScheduleRequest extends FormRequest
'name' => 'sometimes|required|string|max:255',
'description' => 'nullable|string|max:1000',
'type' => "sometimes|required|string|in:{$types}",
'command' => 'sometimes|required|string|max:2000',
// URL 호출 스케줄이면 command 가 곧 서버의 outbound 목적지가 되므로 내부망 주소를 차단한다
'command' => [
'sometimes',
'required',
'string',
'max:2000',
Rule::when($this->resolvesToUrlSchedule(), [new PublicOutboundUrl]),
],
'expression' => 'sometimes|required|string|max:100',
'frequency' => "sometimes|required|string|in:{$frequencies}",
'without_overlapping' => 'boolean',
@@ -47,6 +60,25 @@ class UpdateScheduleRequest extends FormRequest
return HookManager::applyFilters('core.schedule.update_validation_rules', $rules, $this);
}
/**
* 이번 수정 결과 URL 호출 스케줄이 되는지 판정합니다.
*
* PATCH 라 `type` 이 요청에 없을 수 있으므로, 없으면 저장된 스케줄의 타입을 기준으로
* 판정한다 — 그렇지 않으면 기존 url 스케줄의 command 만 바꾸는 요청이 검증을 비껴간다.
*
* @return bool URL 호출 스케줄이면 true
*/
protected function resolvesToUrlSchedule(): bool
{
if ($this->has('type')) {
return $this->input('type') === ScheduleType::Url->value;
}
$schedule = $this->route('schedule');
return $schedule instanceof Schedule && $schedule->type === ScheduleType::Url;
}
/**
* Get custom messages for validator errors.
*
@@ -231,6 +231,8 @@ class SaveSettingsRequest extends FormRequest
'security.auth_token_lifetime' => $this->getSecurityTabAuthTokenRules($tab),
'security.max_login_attempts' => ['nullable', 'integer', 'min:0', 'max:100'],
'security.login_lockout_time' => ['nullable', 'integer', 'min:0', 'max:1440'],
// 신규 설정이므로 미전송(기존 클라이언트)을 허용한다 — 미전송 시 기본값 false 유지
'security.allow_internal_outbound_urls' => ['nullable', 'boolean'],
// 캐시 설정 (advanced 탭)
'advanced.cache_enabled' => $this->getTabRules($tab, 'advanced', 'boolean'),
@@ -614,6 +616,7 @@ class SaveSettingsRequest extends FormRequest
'security.auth_token_lifetime.integer' => __('validation.settings.auth_token_lifetime_integer'),
'security.auth_token_lifetime.min' => __('validation.settings.auth_token_lifetime_min'),
'security.auth_token_lifetime.max' => __('validation.settings.auth_token_lifetime_max'),
'security.allow_internal_outbound_urls.boolean' => __('validation.settings.allow_internal_outbound_urls_boolean'),
'security.max_login_attempts.integer' => __('validation.settings.max_login_attempts_integer'),
'security.max_login_attempts.min' => __('validation.settings.max_login_attempts_min'),
'security.max_login_attempts.max' => __('validation.settings.max_login_attempts_max'),