fix(security)!: 모든 전송이 같은 호출자로 권한을 판정하고 JWT·tenant 빈틈을 막는다

@RequiresPermission이 web 밖에서 늘 거부한다. gRPC·STOMP는 인증한
호출자를 SecurityContext에 넣지 않아 권한 있는 호출자도 거부되고, 거부는
web 403, gRPC INTERNAL+ERROR, GraphQL 가린 INTERNAL_ERROR+ERROR로 갈린다.
GraphQL 정책은 하위 좌표(User.salary) 규칙을 받고 판정하지 않는다. 배포
jar가 SPRING_PROFILES_ACTIVE=test로 떠 prod 검사가 꺼진다. JWT 변환은
최상위 roles claim을 권한으로 읽고, sub 없는 token을 통과시켜 뒤에서 500이
되고, 틀린 tenant claim을 AUTH_TOKEN_MALFORMED로 본다. 모르는 profile의
알림 callback은 500+ERROR이고 공격자 문자열을 감사 WARN에 남긴다. patch
거부는 요청이 쓴 이름을 제한 없이 되풀이한다. tenant 입력 이름 거부가
web·GraphQL에서 갈리고, 익명 GraphQL tenant 출처가 SYSTEM이다. STOMP
거부는 자기 로그가 없고 설정 주석이 순서를 틀리게 적는다.

- AuthorizationDeniedException을 AUTHZ_INSUFFICIENT_PERMISSION carrier로
  만들고 method security가 그것을 그대로 던진다. 전송마다 이미 있는
  carrier 대응이 같은 코드로 답한다(gRPC PERMISSION_DENIED, GraphQL
  FORBIDDEN). 버린 안: 전송마다 AccessDeniedException 대응 추가(네 곳에
  같은 표를 둔다).
- gRPC listener callback과 STOMP frame 처리 동안 호출자를 SecurityContext에
  둔다(spring-security-core 의존, lockfile 갱신). Authentication이면
  그대로, 아니면 권한 없는 인증 token이다. 역할은 AuthenticatedPrincipal
  에서만 읽는다.
- GraphQL 실행 전 판정이 fragment를 한 번씩 펼치며 typed parent로 좌표를
  모은다. root는 늘, 하위 좌표는 규칙이 있을 때 판정하고 interface·구현
  좌표의 규칙도 본다.
- 배포 산출물은 test profile을 기동 실패로 거부한다.
- JWT: 최상위 roles를 버리고, sub 없음·틀린 tenant는 401
  AUTH_CLAIM_MAPPING_FAILED다.
- callback은 profile을 먼저 찾고 없으면 감사 없이 400이다
  (ProviderCallbackAdapterRegistry.require → find).
- patch 거부는 이름을 16개·128자·안전 문자만 되풀이한다.
- tenant 입력 이름 어휘를 TenantId.namesATenant 하나로 모으고, 익명
  GraphQL 출처를 ANONYMOUS로 둔다(값 public, 거부는 하지 않는다 — 공개
  DataLoader가 그 tenant로 돈다).
- STOMP 거부는 사유·command만 담은 WARN 한 줄을 남긴다(session id는
  SockJS가 client URL에서 받아 뺀다).
- 고치며 찾음: decoder를 만든 뒤 JWKS 재조회를 IdP가 받지 않으면 라이브러리
  문구("…decode the Jwt: <HTTP 오류>") 때문에 401 AUTH_TOKEN_MALFORMED로
  분류됐다. 원인 사슬의 HTTP·I/O 실패를 먼저 보고 503
  AUTH_JWKS_UNAVAILABLE로 답한다.

위험: 응답이 바뀐다(gRPC·GraphQL 거부 코드, sub 없음 401, JWKS 재조회
실패 503, 모르는 callback 400, test profile 기동 실패). 할 일은
docs/upgrade/2026-11-round9-authz.md 1~11행이다. registry 구현은 find를
구현해야 컴파일된다.

검증: desktop에서 바뀐 leaf check·systemTest, :app-bootstrap:test·
architectureTest·documentContractTest, verifyDependencyLocks rc=0. 새
시험은 고치기 전 트리에서 실패했다(RED).

Refs: RR9-02-02, RR9-02-16, RR9-02-17, RR9-02-18, RR9-02-20, RR9-02-23,
  RR9-02-25, RR9-02-28, RR9-02-29
BREAKING CHANGE: gRPC·GraphQL 권한 거부 코드, JWT sub 없음·틀린 tenant
  응답, 모르는 알림 callback 응답, test profile 기동, registry require→find
  가 바뀐다. 옮기는 법은 docs/upgrade/2026-11-round9-authz.md 1~11행.
This commit is contained in:
DongHyeonka
2026-11-13 12:24:54 +09:00
parent 3ac824ae60
commit 2f0aefadee
62 changed files with 1862 additions and 179 deletions
@@ -48,6 +48,14 @@ final class ProviderCallbackIngressBridge implements ProviderCallbackIngress {
public CallbackIngestionResult ingest(ProviderCallbackHttpRequest request) {
Objects.requireNonNull(request, "request");
// The profile comes from the unauthenticated path, so it is checked first: an unknown one is
// refused before any limit check could write the caller's string to the security audit log.
// No line either — any POST could otherwise fill the log at will (review 2026-11-12).
ProviderCallbackAdapter adapter =
adapters
.find(request.providerProfileId())
.orElseThrow(() -> rejected(NotificationFailureCode.CALLBACK_PAYLOAD_REJECTED));
CallbackLimits limits = adapters.limitsFor(request.providerProfileId());
if (request.bodyLength() > limits.maxBodyBytes()) {
securityAudit.callbackRejectedByLimit(request.providerProfileId(), "BODY_TOO_LARGE");
@@ -58,7 +66,6 @@ final class ProviderCallbackIngressBridge implements ProviderCallbackIngress {
throw rejected(NotificationFailureCode.CALLBACK_PAYLOAD_REJECTED);
}
ProviderCallbackAdapter adapter = adapters.require(request.providerProfileId());
if (!adapter.providerId().equals(request.providerId())) {
securityAudit.callbackRejectedByLimit(
request.providerProfileId(), "PROVIDER_PROFILE_MISMATCH");
@@ -24,6 +24,7 @@ import dev.caskeleton.application.notification.platform.api.NormalizedProviderEv
import dev.caskeleton.application.notification.platform.api.ProviderId;
import dev.caskeleton.application.notification.platform.api.ProviderProfileId;
import dev.caskeleton.application.notification.platform.api.error.CallbackValidationException;
import dev.caskeleton.application.notification.platform.api.error.NotificationFailureCode;
import dev.caskeleton.application.notification.platform.observation.NotificationSecurityAuditPort;
import dev.caskeleton.application.notification.platform.port.in.IngestProviderCallbackCommand;
import dev.caskeleton.application.notification.platform.port.in.IngestProviderCallbackUseCase;
@@ -193,6 +194,36 @@ class ProviderCallbackIngressBridgeTest {
.containsExactly(CallbackIngressUnavailableException.class, List.of(), List.of());
}
@Test
@DisplayName(
"설정하지 않은 profile 의 콜백은 크기·형식 검사 전에 CALLBACK_PAYLOAD_REJECTED 로 거절되고 감사 로그에 그 문자열을 남기지 않는다")
void aCallbackForAnUnconfiguredProfileIsRejectedFirstWithoutAuditingTheCallersString() {
// given
ProviderCallbackAdapterRegistry registry =
new MapProviderCallbackAdapterRegistry(
Map.of(), new CallbackLimits(4, Set.of("application/json")));
RecordingAudit audit = new RecordingAudit();
RecordingIngestion ingestion = new RecordingIngestion();
ProviderCallbackIngressBridge bridge =
new ProviderCallbackIngressBridge(registry, ingestion, audit);
// when
Throwable failure =
catchThrowable(() -> bridge.ingest(request("text/plain", "longer than four bytes")));
// then
assertThat(
List.of(
failure instanceof CallbackValidationException rejected
? rejected.descriptor().code()
: String.valueOf(failure),
audit.limitReasons,
audit.signatureReasons,
ingestion.callbacks))
.containsExactly(
NotificationFailureCode.CALLBACK_PAYLOAD_REJECTED, List.of(), List.of(), List.of());
}
@Test
void rawHttpLimitsAreEnforcedBeforeTheProviderAdapterRuns() {
RecordingAdapter adapter = new RecordingAdapter(TWILIO, true);
@@ -215,8 +246,8 @@ class ProviderCallbackIngressBridgeTest {
ProviderCallbackAdapterRegistry registry =
new ProviderCallbackAdapterRegistry() {
@Override
public ProviderCallbackAdapter require(ProviderProfileId profileId) {
return adapter;
public Optional<ProviderCallbackAdapter> find(ProviderProfileId profileId) {
return Optional.of(adapter);
}
@Override