Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/schema-and-wire-models/concept/concept-adapter-outbound-persistence-jpa-c05.md
T
DongHyeonkaandClaude Opus 5 b2963105a8 docs(keycloak-session-store): import the session-storage lab as a new project
The keycloak project ended with four open questions that design could not
settle. A two-VM lab was built to answer them by measurement, and this is
that material: 26 experiments, 125 raw command outputs, 22 browser captures.

Follows the import procedure in README.md.

  source/     the originating repository verbatim — 78 documents, 28 SVGs,
              8 manifests, plus .source-revision recording the commit
  final/      the SSOT
    document.md   729 lines written from the 29 experiment documents, not
                  concatenated: what was predicted, what was measured, and
                  where the measurement itself was wrong
    evidence/raw    125 outputs, flattened to <experiment>__<file> because
                    the originals collided (01-baseline.txt appeared three
                    times) and the audit only globs the top level
    evidence/meta   one per raw file; command and exitCode are null and the
                    README says why rather than inventing them
    evidence/browser  22 captures
    assets/       three diagrams through techviz
    .techviz/     their VizSpecs

A separate project rather than an addition to keycloak: the B-layer answers
that project's four questions, but the A, C and D layers are about cluster
failure, SSO and operations, and one document.md should hold one subject.
The four question records there can point here through 관계.

Recorded rather than papered over: only three of the 28 diagrams were
remade. The repository forbids hand-drawn SVG and forbids titles inside the
canvas; all 28 originals carry both, so converting them is redrawing, not
reformatting. They stay in source/ and the gap is written into the document.

verify-pipeline.py passes. audit-records.py reports no issues.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:59 +09:00

68 lines
3.2 KiB
Markdown

---
kind: CONCEPT
slug: adapter-outbound-persistence-jpa-c05
title: 자기가 만든 토큰을 자기가 거부하는 경계값
topic: schema-and-wire-models
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: concept:adapter-outbound-persistence-jpa-c05
evidenceCapturedOn: 2026-09-01
assets:
- key: adapter-outbound-persistence-jpa-c05
file: ../../../final/evidence/rendered/adapter-outbound-persistence-jpa-c05.svg
- key: adapter-outbound-persistence-jpa-c05-diagram
file: ../../../final/assets/diagrams/adapter-outbound-persistence-jpa-c05.svg
evidence:
- ../../../final/evidence/raw/adapter-outbound-persistence-jpa-c05.txt
source:
- 원본 분석 절은 analysis/05-adapter-outbound-persistence-jpa.md#L358 이다.
module: adapter-outbound-persistence-jpa
---
# 자기가 만든 토큰을 자기가 거부하는 경계값
trust boundary 방어는 촘촘한데, decode 전 크기 추정 helper가 padding을 가정해 encode 허용 영역과 decode 허용 영역이 어긋난다.
## 본문
<!-- body:start -->
codec은 다음 형태의 token을 만든다.
```text
v1.<base64url(payload)>.<base64url(HMAC-SHA256(version + '.' + payload))>
```
확인한 방어는 다음과 같다.
- signing key 최소 32 bytes
- URL-safe Base64 / no padding
- version까지 MAC input에 포함
- token 전체 길이 4096-character cap
- payload 2048-byte cap
- presented MAC 32-byte exact length 확인
- `MessageDigest.isEqual` constant-time comparison
- MAC 검증 전에 application payload decoder를 호출하지 않음
- oversized public input을 substring/decode/MAC allocation 전에 거부하려는 선행 check
기존 dedicated tests도 tampering, foreign key, unknown version, short key, oversized token, wrong-length MAC, oversized payload 등을 폭넓게 검증한다.
## SignedJsonCursorCodec 참조 위치
:::evidence key="adapter-outbound-persistence-jpa-c05" alt="코드베이스에서 SignedJsonCursorCodec 를 검색한 출력 15줄. 이 기록이 세는 참조가 그 출력에 그대로 보인다." caption="SignedJsonCursorCodec 코드베이스 검색 — 15줄 · exit 0" zoom="true"
:::
## 추정 helper가 padding을 가정한다
문제는 decoded payload size를 decode **전에** 추정하는 helper다. 이 함수는 "최대 decoded size"를 빠르게 계산하려는 의도로 commit `2f5d2fc`에서 hostile-input bounds와 함께 추가됐다. 그러나 codec은 **unpadded Base64URL**을 사용한다.
## encode와 decode의 허용 범위
:::evidence key="adapter-outbound-persistence-jpa-c05-diagram" alt="상한 크기의 payload가 base64url 인코드를 지나 크기 사전 추정 단계에서 decode 쪽 거부로 이어지는 경로" caption="encode와 decode의 허용 범위" zoom="false"
:::
실제 self-round-trip probe 결과 현재 accepted encode domain과 accepted decode domain이 다르다. 이건 hostile token을 더 엄격히 거부하는 정도가 아니다. **codec의 자기 round-trip contract를 깨는 boundary defect**다. 실행 evidence는 `evidence/raw/035a-jpa-cursor-boundary-probe.java``evidence/raw/035-jpa-cursor-boundary-probe.txt`에 있다.
<!-- body:end -->