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

@@ -3,6 +3,7 @@
namespace Modules\Sirsoft\Ecommerce\Services;
use App\Extension\HookManager;
use App\Support\OutboundUrlValidator;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -2149,6 +2150,17 @@ class OrderCalculationService
*/
protected function dispatchApiRequest(string $endpoint, array $requestData, array $config): ?Response
{
// 이 호출은 공개 체크아웃 트래픽으로도 유발되므로, 저장된 엔드포인트가 내부망을
// 가리키면 요청 자체를 보내지 않는다. 저장 시점 검증(FormRequest) 도입 이전에
// 기록된 값이나 DB 직접 수정으로 들어온 값을 여기서 막는다.
if (! $this->isEndpointAllowed($endpoint)) {
Log::warning('배송비 계산 API 엔드포인트가 내부 네트워크를 가리켜 호출을 차단했습니다', [
'host' => parse_url($endpoint, PHP_URL_HOST),
]);
return null;
}
$request = Http::timeout(10)->withoutRedirecting();
// 인증 헤더 부착
@@ -2170,6 +2182,27 @@ class OrderCalculationService
: $request->post($endpoint, $requestData);
}
/**
* 배송비 계산 API 엔드포인트가 호출 가능한 주소인지 판정합니다.
*
* 사설 IP·localhost 등 내부 네트워크 주소는 기본 차단합니다. 사내 서버를 배송비 API 로
* 쓰는 운영 환경을 위해 관리자 환경설정의 `security.allow_internal_outbound_urls` 로
* 허용할 수 있으며, 그 경우에도 userinfo 위장·비 HTTP scheme 은 계속 거부합니다.
*
* @param string $endpoint API 엔드포인트 URL
* @return bool 호출을 허용하면 true
*/
protected function isEndpointAllowed(string $endpoint): bool
{
$options = ['schemes' => ['http', 'https']];
if ((bool) g7_core_settings('security.allow_internal_outbound_urls', false)) {
return OutboundUrlValidator::isStructurallySafeUrl($endpoint, $options);
}
return OutboundUrlValidator::isPublicHttpUrl($endpoint, $options);
}
/**
* 외부 API 응답에서 배송비 값을 추출합니다 (응답 형식별 분기).
*