- generic [ref=f27e3]: - link "본문으로 건너뛰기" [ref=f27e4] [cursor=pointer]: - /url: "#main-content" - banner [ref=f27e5]: - generic [ref=f27e6]: - link "TechLog Studio" [ref=f27e7] [cursor=pointer]: - /url: /studio - text: TechLog - generic [ref=f27e8]: Studio - navigation "Studio 주 탐색" [ref=f27e10]: - link "작업본" [ref=f27e11] [cursor=pointer]: - /url: /studio/documents - link "게시 기록" [ref=f27e12] [cursor=pointer]: - /url: /studio/publications - link "새 문서" [ref=f27e13] [cursor=pointer]: - /url: /studio/documents/new - link "주제·프로젝트" [ref=f27e14] [cursor=pointer]: - /url: /studio/taxonomy - link "릴리즈" [ref=f27e15] [cursor=pointer]: - /url: /studio/releases - link "공개 사이트 보기" [ref=f27e16] [cursor=pointer]: - /url: / - button "로그아웃" [ref=f27e17] - main [ref=f27e18]: - generic [ref=f27e19]: - generic [ref=f27e20]: - region [ref=f27e21]: - generic [ref=f27e22]: - paragraph [ref=f27e23]: CASE · VERSION 29 - heading "문서 편집" [level=1] [ref=f27e24] - paragraph [ref=f27e25]: SPA에서 토큰을 직접 관리하면서 드러난 Browser Credential 경계 - region [ref=f27e26]: - generic [ref=f27e27]: - paragraph [ref=f27e28]: DOCUMENT - heading "기본 정보" [level=2] [ref=f27e29] - generic [ref=f27e30]: - generic [ref=f27e31]: - generic [ref=f27e32]: 제목 - textbox "제목" [ref=f27e33]: SPA에서 토큰을 직접 관리하면서 드러난 Browser Credential 경계 - generic [ref=f27e34]: - generic [ref=f27e35]: slug - textbox "slug" [ref=f27e36]: - /placeholder: 비우면 제목에서 만듭니다 (영문 소문자·숫자·하이픈) - text: spa-browser-credential-boundary - generic [ref=f27e37]: - generic [ref=f27e38]: 요약 - textbox "요약" [ref=f27e39]: SPA가 public OAuth client로 code를 직접 교환하고 access·refresh·ID token을 JavaScript memory에만 두는 AP1을 실행했다. memory-only는 새로고침 뒤 남는 복사본만 없앨 뿐, 실행 중 script가 fetch를 가로채거나 사용자 대신 API를 부르는 부분은 남아있다. - generic [ref=f27e40]: - generic [ref=f27e41]: Topic - combobox "Topic" [ref=f27e42]: - option "선택하지 않음" - option "OAuth/OIDC 인증 경계" [selected] - generic [ref=f27e43]: - generic [ref=f27e44]: Project - combobox "Project" [ref=f27e45]: - option "미지정" - option "Backend Clean Architecture" - option "KeyCloak Patterns" [selected] - option "Liner N + 1문제" - group "관계" [ref=f27e46]: - generic [ref=f27e48]: - generic [ref=f27e49]: - generic [ref=f27e50]: 관계 1 대상 - combobox "관계 1 대상" [ref=f27e51]: - option "대상 선택" - option "인증 구조를 보안 성숙도 단계로 취급하지 않는다" [disabled] - option "서버 세션 기반 인증 구조는 다중 인스턴스에서 어떻게 운영할 것인가" - option "Authorization Code Flow의 Endpoint와 Credential 이동 기준" [selected] - option "BFF 인증 구조 설계 기준" - option "BFF가 OAuth Token을 관리하는 조건" - option "BFF의 Session과 OAuth2AuthorizedClient를 어디에 저장할 것인가" - option "Browser Token을 없애면서 BFF에 Session과 CSRF 책임이 생긴 과정" - option "Forward-Auth 구조에서 Application Authorization을 어디까지 Edge에 둘 것인가" - option "Forward-Auth에서 Client가 보낸 Identity Header를 신뢰하면 안 되는 이유" - option "Forward-Auth에서 Identity Header를 신뢰하기 위한 조건" - option "외부 IdP Federation을 별도의 인증 구조로 세지 않는다" - option "외부 IdP Federation과 Application 인증 경계" - option "OAuth/OIDC 인증 패턴 선택 기준" - option "OAuth Token과 Application Session을 구분하는 기준" [disabled] - option "Public Client와 Confidential Client 구분 기준" [disabled] - option "Refresh Token 관리만 서버로 이전, Access Token은 여전히 Browser에 노출" - option "Refresh Token Rotation과 다중 Replica 경쟁을 어떻게 처리할 것인가" - option "SPA가 Authorization Code를 직접 교환하고 Resource Server를 호출한 구조" - generic [ref=f27e52]: - generic [ref=f27e53]: 관계 1 이유 - textbox "관계 1 이유" [ref=f27e54]: 브라우저가 authorization endpoint와 token endpoint를 모두 지나는 흐름이다. 이 기준의 endpoint별 이동을 코드로 확인한 자리다. - generic [ref=f27e55]: - button "위로" [disabled] [ref=f27e56] - button "아래로" [ref=f27e57] - button "삭제" [ref=f27e58] - generic [ref=f27e59]: - generic [ref=f27e60]: - generic [ref=f27e61]: 관계 2 대상 - combobox "관계 2 대상" [ref=f27e62]: - option "대상 선택" - option "인증 구조를 보안 성숙도 단계로 취급하지 않는다" [disabled] - option "서버 세션 기반 인증 구조는 다중 인스턴스에서 어떻게 운영할 것인가" - option "Authorization Code Flow의 Endpoint와 Credential 이동 기준" [disabled] - option "BFF 인증 구조 설계 기준" - option "BFF가 OAuth Token을 관리하는 조건" - option "BFF의 Session과 OAuth2AuthorizedClient를 어디에 저장할 것인가" - option "Browser Token을 없애면서 BFF에 Session과 CSRF 책임이 생긴 과정" - option "Forward-Auth 구조에서 Application Authorization을 어디까지 Edge에 둘 것인가" - option "Forward-Auth에서 Client가 보낸 Identity Header를 신뢰하면 안 되는 이유" - option "Forward-Auth에서 Identity Header를 신뢰하기 위한 조건" - option "외부 IdP Federation을 별도의 인증 구조로 세지 않는다" - option "외부 IdP Federation과 Application 인증 경계" - option "OAuth/OIDC 인증 패턴 선택 기준" - option "OAuth Token과 Application Session을 구분하는 기준" [disabled] - option "Public Client와 Confidential Client 구분 기준" [selected] - option "Refresh Token 관리만 서버로 이전, Access Token은 여전히 Browser에 노출" - option "Refresh Token Rotation과 다중 Replica 경쟁을 어떻게 처리할 것인가" - option "SPA가 Authorization Code를 직접 교환하고 Resource Server를 호출한 구조" - generic [ref=f27e63]: - generic [ref=f27e64]: 관계 2 이유 - textbox "관계 2 이유" [ref=f27e65]: SPA가 secret을 숨길 수 없어 public client가 되고 PKCE가 그 자리를 대신한 실례다. - generic [ref=f27e66]: - button "위로" [ref=f27e67] - button "아래로" [ref=f27e68] - button "삭제" [ref=f27e69] - generic [ref=f27e70]: - generic [ref=f27e71]: - generic [ref=f27e72]: 관계 3 대상 - combobox "관계 3 대상" [ref=f27e73]: - option "대상 선택" - option "인증 구조를 보안 성숙도 단계로 취급하지 않는다" [disabled] - option "서버 세션 기반 인증 구조는 다중 인스턴스에서 어떻게 운영할 것인가" - option "Authorization Code Flow의 Endpoint와 Credential 이동 기준" [disabled] - option "BFF 인증 구조 설계 기준" - option "BFF가 OAuth Token을 관리하는 조건" - option "BFF의 Session과 OAuth2AuthorizedClient를 어디에 저장할 것인가" - option "Browser Token을 없애면서 BFF에 Session과 CSRF 책임이 생긴 과정" - option "Forward-Auth 구조에서 Application Authorization을 어디까지 Edge에 둘 것인가" - option "Forward-Auth에서 Client가 보낸 Identity Header를 신뢰하면 안 되는 이유" - option "Forward-Auth에서 Identity Header를 신뢰하기 위한 조건" - option "외부 IdP Federation을 별도의 인증 구조로 세지 않는다" - option "외부 IdP Federation과 Application 인증 경계" - option "OAuth/OIDC 인증 패턴 선택 기준" - option "OAuth Token과 Application Session을 구분하는 기준" [selected] - option "Public Client와 Confidential Client 구분 기준" [disabled] - option "Refresh Token 관리만 서버로 이전, Access Token은 여전히 Browser에 노출" - option "Refresh Token Rotation과 다중 Replica 경쟁을 어떻게 처리할 것인가" - option "SPA가 Authorization Code를 직접 교환하고 Resource Server를 호출한 구조" - generic [ref=f27e74]: - generic [ref=f27e75]: 관계 3 이유 - textbox "관계 3 이유" [ref=f27e76]: memory-only 보관과 IdP SSO cookie를 나눠 본 자리다. 브라우저에 없다는 말의 대상을 여기서 좁혔다. - generic [ref=f27e77]: - button "위로" [ref=f27e78] - button "아래로" [ref=f27e79] - button "삭제" [ref=f27e80] - generic [ref=f27e81]: - generic [ref=f27e82]: - generic [ref=f27e83]: 관계 4 대상 - combobox "관계 4 대상" [ref=f27e84]: - option "대상 선택" - option "인증 구조를 보안 성숙도 단계로 취급하지 않는다" [selected] - option "서버 세션 기반 인증 구조는 다중 인스턴스에서 어떻게 운영할 것인가" - option "Authorization Code Flow의 Endpoint와 Credential 이동 기준" [disabled] - option "BFF 인증 구조 설계 기준" - option "BFF가 OAuth Token을 관리하는 조건" - option "BFF의 Session과 OAuth2AuthorizedClient를 어디에 저장할 것인가" - option "Browser Token을 없애면서 BFF에 Session과 CSRF 책임이 생긴 과정" - option "Forward-Auth 구조에서 Application Authorization을 어디까지 Edge에 둘 것인가" - option "Forward-Auth에서 Client가 보낸 Identity Header를 신뢰하면 안 되는 이유" - option "Forward-Auth에서 Identity Header를 신뢰하기 위한 조건" - option "외부 IdP Federation을 별도의 인증 구조로 세지 않는다" - option "외부 IdP Federation과 Application 인증 경계" - option "OAuth/OIDC 인증 패턴 선택 기준" - option "OAuth Token과 Application Session을 구분하는 기준" [disabled] - option "Public Client와 Confidential Client 구분 기준" [disabled] - option "Refresh Token 관리만 서버로 이전, Access Token은 여전히 Browser에 노출" - option "Refresh Token Rotation과 다중 Replica 경쟁을 어떻게 처리할 것인가" - option "SPA가 Authorization Code를 직접 교환하고 Resource Server를 호출한 구조" - generic [ref=f27e85]: - generic [ref=f27e86]: 관계 4 이유 - textbox "관계 4 이유" [ref=f27e87]: 이 기록이 성숙도 모델의 출발점으로 오해되기 쉬운 자리다. 그 오해를 막는 결정이다. - generic [ref=f27e88]: - button "위로" [ref=f27e89] - button "아래로" [disabled] [ref=f27e90] - button "삭제" [ref=f27e91] - button "관계 추가" [ref=f27e92] - region [ref=f27e93]: - generic [ref=f27e94]: - paragraph [ref=f27e95]: CASE - heading "문제와 검증" [level=2] [ref=f27e96] - generic [ref=f27e97]: - generic [ref=f27e98]: - generic [ref=f27e99]: 문제 - textbox "문제" [ref=f27e100]: token을 Web Storage에 저장하지 않고 memory에만 두면 XSS 위험도 사라지는지 확인할 필요가 있었다. AP1은 SPA가 public client가 되어 authorization code를 직접 교환하고 access·refresh·ID token을 JavaScript memory에 두는 구성이다. 이 구성에서 실제로 무엇이 브라우저에 남고, PKCE가 어느 구간을 막으며, memory-only 보관이 어느 위험을 막고 어느 위험을 막아주지 않는지 구분해야 했다. - generic [ref=f27e101]: - generic [ref=f27e102]: 결론 - textbox "결론" [ref=f27e103]: memory-only 보관이 막아주는 것은 새로고침 뒤에도 남는 token 복사본이지 실행 중 XSS의 권한이 아니다. 실행 중 악성 script는 같은 화면에서 fetch를 가로채거나 사용자를 대신해 API를 부를 수 있다. token 원문은 memory에만 있는 것이 아니라 요청마다 Authorization 헤더에도 실리기 때문에 노출된다. Resource Server가 STATELESS라 서버에 지울 session이 없고, 이미 발급된 self-contained JWT를 logout 순간에 없앨 방법도 없다. 그래서 이를 짧은 수명과 rotation, issuer·audience 검증이 커버하게 된다. PKCE는 훔친 authorization code의 교환을 막을 뿐이지 발급된 access token을 숨기지 않는다. - generic [ref=f27e104]: - generic [ref=f27e105]: 검증 환경 - textbox "검증 환경" [ref=f27e106]: "Keycloak 26.7.0 realms 설정 public-client, standard flow : o implicit flow, direct grant : x authority : http://localhost:8080/realms/keycloak-patterns redirect_uri : http://localhost:8088/OAuth2callback.html scope : openid profile email userStore : InMemoryWebStorage stateStore : sessionStorage automaticSilentRenew : true Resource Server SessionCreationPolicy.STATELESS CSRF x CORS allowlist : localhost:8088, 127.0.0.1:8088, GET·OPTIONS, Authorization·Content-Type HTTPS : x HTTP : o" - generic [ref=f27e107]: - generic [ref=f27e108]: 재현 조건 - textbox "재현 조건" [ref=f27e109]: 1. SPA를 열고 로그인후 Keycloak authorization request의 response_type=code, code_challenge_method=S256, 비어 있지 않은 code_challenge를 확인. 2. token 응답에 access·refresh·ID token이 비어 있지 않은지 확인. 3. 브라우저 fetch를 hook해 /api/me 호출의 Authorization header에서 Bearer access token을 확인. 4. Local Storage와 Session Storage에 access token substring이 남지 않는지 확인. 5. 같은 정상 JWT를 expected issuer·audience가 다른 diagnostic server 두 곳에 제출해 401을 확인. 6. refresh token으로 새 token을 받고 이전 refresh token이 거부되는지, revocation 뒤 refresh가 실패하는지, 이미 발급된 access JWT가 만료 전까지 200인지 확인. - generic [ref=f27e110]: - generic [ref=f27e111]: 마지막 검증일 - textbox "마지막 검증일" [ref=f27e112]: 2026-08-22 - generic [ref=f27e113]: - generic [ref=f27e114]: 본문 Markdown - textbox "본문 Markdown" [ref=f27e115]: "## credential이 머무는 자리 :::evidence key=\"ap1-custody-v3-6e0376d2\" alt=\"브라우저 실행 영역 안에 code 교환, access·refresh·ID token 보관, Authorization 헤더 조립 세 상자가 들어 있고 그 영역 전체가 실행 중 XSS가 닿는 범위로 표시된 그림. Keycloak과 Resource Server는 그 밖에 있다.\" caption=\" \" zoom=\"true\" ::: code 교환, token 보관, `Authorization` 헤더 조립이 모두 같은 브라우저 실행 영역에 있다. 이 영역에서 악성 script가 실행되면 세 지점 모두 영향을 받는다. ## 브라우저에 실제로 남는 것 oidc-client-ts의 `InMemoryWebStorage`는 로그인 결과를 브라우저의 영구 저장소가 아니라 실행 중 memory에만 둔다. 새로고침하면 로그인 상태가 사라지지만 Web Storage에 남아있는 복사본은 없다. 아래 표는 새로고침을 기준으로 무엇이 남고 무엇이 사라지는지 나눈 것이다. | 위치 | reload 전 | reload 후 | |---|---|---| | JavaScript memory | `User`, access·refresh·ID token, expiry, profile | 사라짐 | | Session Storage | redirect transaction용 state와 verifier | callback 완료 뒤 제거 | | Local Storage | 해당 없음 | 해당 없음 | | Keycloak origin cookie | IdP의 SSO 상태가 존재할 수 있음 | application과 별개 | memory user가 사라진다고 Keycloak SSO까지 로그아웃되는 것은 아니다. ## memory-only가 줄이는 위험 앞의 표는 \"무엇이 어디 남지?\"만 표현하고 있는데, 교차 사이트 스크립팅(XSS)으로 script가 실행되면 저장 위치는 더 이상 경계가 아니다. 같은 실행 영역 안이기 때문이다. | 위협 | memory-only가 막아주나 | |---|---| | 새로고침 뒤에도 남는 token 복사본 | 막아준다 | | 실행 중 script가 fetch를 가로채기 | 막아주지 않는다 | | 실행 중 script가 사용자 대신 API 호출 | 막아주지 않는다 | | network 요청 헤더에 실린 access token | 막아주지 않는다 | | 이미 발급된 access JWT의 만료 전 유효성 | 막아주지 않는다 | 네 번째 줄이 이 코드에서 access token이 외부 요청으로 나가는 지점이다. SPA는 요청마다 이 헤더를 만든다. ```http label=\"브라우저가 Resource Server를 직접 부를 때\" GET http://localhost:8081/api/me Authorization: Bearer ``` token 원문은 memory에도 있고 network 헤더에도 실린다. Resource Server가 `SessionCreationPolicy.STATELESS`라서 서버에 지울 session이 없다. 이미 발급된 self-contained JWT를 logout 순간에 즉시 없앨 방법이 없고, logout은 Keycloak SSO 종료와 애플리케이션 user 제거를 다룰 뿐 access JWT를 deny-list에서 관리하지 않는다. **그래서 수명을 짧게 두는 것이 안전하다.** access token : 300초 refresh token rotation, 재사용 허용 : x issuer·audience : 검증 Local Storage나 Session Storage로 옮기면 새로고침은 편해지지만 노출 시간이 길어진다. HttpOnly cookie로 옮기는 일은 저장 위치만 바꾸는 작업이 아니다. server가 session이나 token 중계를 맡는 구조가 필요하다. ## PKCE가 막는 구간 PKCE(Proof Key for Code Exchange)는 authorization request에 `code_challenge`를 싣고, code를 token으로 바꿀 때 원본인 `code_verifier`를 같이 보내게 한다. 둘이 맞아야 교환이 끝난다. ```text label=\"oidc-client-ts가 만드는 authorization request의 핵심 query\" response_type=code client_id=spa-public redirect_uri=http://localhost:8088/OAuth2callback.html scope=openid profile email state= code_challenge= code_challenge_method=S256 ``` `response_type=code`가 Authorization Code Flow를 쓴다는 뜻이고, `code_challenge`와 `code_challenge_method=S256`이 PKCE 사용을 나타낸다. 막는 구간은 code 교환까지다. 이미 발급된 access token은 막아주지 않는다. ## 확인한 것과 확인하지 않은 것 아래는 **커밋된 테스트가 확인하도록 정의한 부분**이다. 왼쪽이 정의 여부, 오른쪽이 정의 내용. | 정의 여부 | 정의 내용 | |---|---| | o | authorization request의 `response_type=code`, S256 method, 비어 있지 않은 challenge | | o | token 응답에 비어 있지 않은 access·refresh·ID token | | o | `/api/me` 200과 decoded access token의 audience 포함 | | o | 브라우저 fetch를 가로채 Authorization 헤더의 Bearer token 관측 | | o | Local Storage와 Session Storage에 access token substring 없음 | | o | refresh rotation — 새 token 발급, 이전 token 거부, revocation 뒤 refresh 실패 | | o | issuer나 audience가 다른 진단용 서버 두 곳의 401 | | x | token request body의 `code_verifier`·`client_id`·`redirect_uri`·code 값 대조 | | x | 서명이 깨진 JWT, 만료된 JWT | | x | 브라우저 간 요청(CORS)의 preflight 응답 | | x | callback에 error가 실려 돌아왔을 때의 화면 | | x | `automaticSilentRenew`의 실제 갱신 경로 | 첫 줄과 여덟째 줄을 같이 보자. **authorization request의 파라미터를 보는 것이지 PKCE 교환이 성립하는 것을 보는 것이 아니다.** :::warning SPA는 non-2xx 응답에서도 `response.ok`을 확인하기 전에 `response.json()`을 시도한다. 401 body가 비어 있거나 JSON이 아니면 의도한 메시지 대신 JSON parse error가 먼저 노출되게 된다. ::: ## 추가로 설정에서 확인해야될 것 local realm의 redirect allowlist는 `http://localhost:8088/*`와 `http://127.0.0.1:8088/*` wildcard다. SPA : `/OAuth2callback.html`만 o, exact callback만 허용하는 운영적 측면 또는 잘못된 redirect를 거부하는 검사는 x frontend Nginx에도 `/api/` proxy가 있지만 SPA는 상대 URL이 아니라 absolute `http://localhost:8081/api/me`를 쓴다. 그래서 CORS allowlist는 실제로 지나가는 경계이다. 상대 URL을 썼다면 이 경계에서 확인되는 부분은 없었을 것이다." - group [ref=f27e116]: - paragraph [ref=f27e117]: EVIDENCE - heading "본문에 Asset 삽입" [level=3] [ref=f27e118] - paragraph [ref=f27e119]: 목록에서 선택하면 본문 커서 위치에 evidence 구문을 삽입합니다. READY 상태의 Asset만 선택할 수 있습니다. - generic [ref=f27e120]: - generic [ref=f27e121]: - generic [ref=f27e122]: 업로드 종류 - combobox "업로드 종류" [ref=f27e123]: - option "이미지" [selected] - option "다이어그램" - option "첨부파일" - button "Asset 업로드" [ref=f27e124] - generic [ref=f27e125]: - search [ref=f27e126]: - generic [ref=f27e127]: Asset 검색 - generic [ref=f27e128]: - searchbox "Asset 검색" [ref=f27e129] - button "검색" [ref=f27e130] - generic [ref=f27e131]: - checkbox "삽입할 때 크게 보기 허용" [checked] [ref=f27e132] - generic [ref=f27e133]: 삽입할 때 크게 보기 허용 - status [ref=f27e134]: 삽입할 수 있는 Asset 8개 - list [ref=f27e135]: - listitem [ref=f27e136]: - button "ap4-edge-trust-1cff2399" [ref=f27e137] - button "삭제" [ref=f27e138] - listitem [ref=f27e139]: - button "ap3-csrf-split-501dd1f7" [ref=f27e140] - button "삭제" [ref=f27e141] - listitem [ref=f27e142]: - button "ap3-bff-custody-82fa18bd" [ref=f27e143] - button "삭제" [ref=f27e144] - listitem [ref=f27e145]: - button "ap2-split-custody-779cb791" [ref=f27e146] - button "삭제" [ref=f27e147] - listitem [ref=f27e148]: - button "ap1-custody-v3-6e0376d2" [ref=f27e149] - button "삭제" [ref=f27e150] - listitem [ref=f27e151]: - button "ap1-custody-v2-e110bd98" [ref=f27e152] - button "삭제" [ref=f27e153] - listitem [ref=f27e154]: - button "ap1-credential-custody-f5e0c027" [ref=f27e155] - button "삭제" [ref=f27e156] - listitem [ref=f27e157]: - button "screenshot-from-2026-08-21-18-04-49-72f1f9c6" [ref=f27e158] - button "삭제" [ref=f27e159] - region [ref=f27e160]: - generic [ref=f27e161]: - paragraph [ref=f27e162]: LIVE - heading "즉시 미리보기" [level=2] [ref=f27e163] - generic [ref=f27e166]: - generic [ref=f27e167]: - navigation "문서 경로" [ref=f27e168]: - link "Case" [ref=f27e169] [cursor=pointer]: - /url: /explore/cases - generic [ref=f27e170]: / - generic [ref=f27e171]: OAuth/OIDC 인증 경계 - generic [ref=f27e172]: / - link "KeyCloak Patterns" [ref=f27e173] [cursor=pointer]: - /url: /projects/keycloak-patterns - heading "SPA에서 토큰을 직접 관리하면서 드러난 Browser Credential 경계" [level=1] [ref=f27e174] - paragraph [ref=f27e175]: SPA가 public OAuth client로 code를 직접 교환하고 access·refresh·ID token을 JavaScript memory에만 두는 AP1을 실행했다. memory-only는 새로고침 뒤 남는 복사본만 없앨 뿐, 실행 중 script가 fetch를 가로채거나 사용자 대신 API를 부르는 부분은 남아있다. - region "문제와 결론" [ref=f27e176]: - generic [ref=f27e177]: - paragraph [ref=f27e178]: 문제 - paragraph [ref=f27e179]: token을 Web Storage에 저장하지 않고 memory에만 두면 XSS 위험도 사라지는지 확인할 필요가 있었다.AP1은 SPA가 public client가 되어 authorization code를 직접 교환하고 access·refresh·ID token을 JavaScript memory에 두는 구성이다. 이 구성에서 실제로 무엇이 브라우저에 남고, PKCE가 어느 구간을 막으며, memory-only 보관이 어느 위험을 막고 어느 위험을 막아주지 않는지 구분해야 했다. - generic [ref=f27e180]: - paragraph [ref=f27e181]: 결론 - paragraph [ref=f27e182]: memory-only 보관이 막아주는 것은 새로고침 뒤에도 남는 token 복사본이지 실행 중 XSS의 권한이 아니다.실행 중 악성 script는 같은 화면에서 fetch를 가로채거나 사용자를 대신해 API를 부를 수 있다. token 원문은 memory에만 있는 것이 아니라 요청마다 Authorization 헤더에도 실리기 때문에 노출된다.Resource Server가 STATELESS라 서버에 지울 session이 없고, 이미 발급된 self-contained JWT를 logout 순간에 없앨 방법도 없다. 그래서 이를 짧은 수명과 rotation, issuer·audience 검증이 커버하게 된다. PKCE는 훔친 authorization code의 교환을 막을 뿐이지 발급된 access token을 숨기지 않는다. - generic [ref=f27e183]: - generic [ref=f27e184]: - term [ref=f27e185]: 검증 환경 - definition [ref=f27e186]: "Keycloak 26.7.0realms 설정public-client, standard flow : o implicit flow, direct grant : xauthority : http://localhost:8080/realms/keycloak-patternsredirect_uri : http://localhost:8088/OAuth2callback.htmlscope : openid profile emailuserStore : InMemoryWebStoragestateStore : sessionStorageautomaticSilentRenew : trueResource ServerSessionCreationPolicy.STATELESS CSRF x CORS allowlist : localhost:8088, 127.0.0.1:8088, GET·OPTIONS, Authorization·Content-TypeHTTPS : x HTTP : o" - generic [ref=f27e187]: - term [ref=f27e188]: 검증 데이터 - definition [ref=f27e189]: 1. SPA를 열고 로그인후 Keycloak authorization request의 response_type=code, code_challenge_method=S256, 비어 있지 않은 code_challenge를 확인.2. token 응답에 access·refresh·ID token이 비어 있지 않은지 확인.3. 브라우저 fetch를 hook해 /api/me 호출의 Authorization header에서 Bearer access token을 확인.4. Local Storage와 Session Storage에 access token substring이 남지 않는지 확인.5. 같은 정상 JWT를 expected issuer·audience가 다른 diagnostic server 두 곳에 제출해 401을 확인.6. refresh token으로 새 token을 받고 이전 refresh token이 거부되는지, revocation 뒤 refresh가 실패하는지, 이미 발급된 access JWT가 만료 전까지 200인지 확인. - generic [ref=f27e190]: - term [ref=f27e191]: 기록 - definition [ref=f27e192]: 게시 2026.08.23 · 마지막 검증 2026.08.22 - group [ref=f27e194]: - generic "목차 · credential이 머무는 자리" [ref=f27e195] [cursor=pointer] - article [ref=f27e197]: - region [ref=f27e198]: - heading [level=2] [ref=f27e199]: - link "credential이 머무는 자리 바로가기" [ref=f27e200] [cursor=pointer]: - /url: "#credential이-머무는-자리" - text: credential이 머무는 자리 - generic [ref=f27e201]: "#" - figure [ref=f27e202]: - button "ap1-custody-v3-6e0376d2 이미지 크게 보기" [ref=f27e203]: - img "브라우저 실행 영역 안에 code 교환, access·refresh·ID token 보관, Authorization 헤더 조립 세 상자가 들어 있고 그 영역 전체가 실행 중 XSS가 닿는 범위로 표시된 그림. Keycloak과 Resource Server는 그 밖에 있다." [ref=f27e204] - generic [ref=f27e205]: 크게 보기 - generic [ref=f27e206]: 브라우저 실행 영역 안에 code 교환, access·refresh·ID token 보관, Authorization 헤더 조립 세 상자가 들어 있고 그 영역 전체가 실행 중 XSS가 닿는 범위로 표시된 그림. Keycloak과 Resource Server는 그 밖에 있다. - paragraph [ref=f27e207]: - text: code 교환, token 보관, - code [ref=f27e208]: Authorization - text: 헤더 조립이 모두 같은 브라우저 실행 영역에 있다. 이 영역에서 악성 script가 실행되면 세 지점 모두 영향을 받는다. - region [ref=f27e209]: - heading [level=2] [ref=f27e210]: - link "브라우저에 실제로 남는 것 바로가기" [ref=f27e211] [cursor=pointer]: - /url: "#브라우저에-실제로-남는-것" - text: 브라우저에 실제로 남는 것 - generic [ref=f27e212]: "#" - paragraph [ref=f27e213]: - text: oidc-client-ts의 - code [ref=f27e214]: InMemoryWebStorage - text: 는 로그인 결과를 브라우저의 영구 저장소가 아니라 실행 중 memory에만 둔다.새로고침하면 로그인 상태가 사라지지만 Web Storage에 남아있는 복사본은 없다. - paragraph [ref=f27e215]: 아래 표는 새로고침을 기준으로 무엇이 남고 무엇이 사라지는지 나눈 것이다. - region "표" [ref=f27e216]: - table [ref=f27e217]: - caption [ref=f27e218] - rowgroup [ref=f27e219]: - row [ref=f27e220]: - columnheader "위치" [ref=f27e221] - columnheader "reload 전" [ref=f27e222] - columnheader "reload 후" [ref=f27e223] - rowgroup [ref=f27e224]: - row [ref=f27e225]: - cell "JavaScript memory" [ref=f27e226] - cell [ref=f27e227]: - code [ref=f27e228]: User - text: ", access·refresh·ID token, expiry, profile" - cell "사라짐" [ref=f27e229] - row [ref=f27e230]: - cell "Session Storage" [ref=f27e231] - cell "redirect transaction용 state와 verifier" [ref=f27e232] - cell "callback 완료 뒤 제거" [ref=f27e233] - row [ref=f27e234]: - cell "Local Storage" [ref=f27e235] - cell "해당 없음" [ref=f27e236] - cell "해당 없음" [ref=f27e237] - row [ref=f27e238]: - cell "Keycloak origin cookie" [ref=f27e239] - cell "IdP의 SSO 상태가 존재할 수 있음" [ref=f27e240] - cell "application과 별개" [ref=f27e241] - paragraph [ref=f27e242]: memory user가 사라진다고 Keycloak SSO까지 로그아웃되는 것은 아니다. - region [ref=f27e243]: - heading [level=2] [ref=f27e244]: - link "memory-only가 줄이는 위험 바로가기" [ref=f27e245] [cursor=pointer]: - /url: "#memory-only가-줄이는-위험" - text: memory-only가 줄이는 위험 - generic [ref=f27e246]: "#" - paragraph [ref=f27e247]: 앞의 표는 "무엇이 어디 남지?"만 표현하고 있는데, 교차 사이트 스크립팅(XSS)으로 script가 실행되면 저장 위치는 더 이상 경계가 아니다. 같은 실행 영역 안이기 때문이다. - region "표" [ref=f27e248]: - table [ref=f27e249]: - caption [ref=f27e250] - rowgroup [ref=f27e251]: - row [ref=f27e252]: - columnheader "위협" [ref=f27e253] - columnheader "memory-only가 막아주나" [ref=f27e254] - rowgroup [ref=f27e255]: - row [ref=f27e256]: - cell "새로고침 뒤에도 남는 token 복사본" [ref=f27e257] - cell "막아준다" [ref=f27e258] - row [ref=f27e259]: - cell "실행 중 script가 fetch를 가로채기" [ref=f27e260] - cell "막아주지 않는다" [ref=f27e261] - row [ref=f27e262]: - cell "실행 중 script가 사용자 대신 API 호출" [ref=f27e263] - cell "막아주지 않는다" [ref=f27e264] - row [ref=f27e265]: - cell "network 요청 헤더에 실린 access token" [ref=f27e266] - cell "막아주지 않는다" [ref=f27e267] - row [ref=f27e268]: - cell "이미 발급된 access JWT의 만료 전 유효성" [ref=f27e269] - cell "막아주지 않는다" [ref=f27e270] - paragraph [ref=f27e271]: 네 번째 줄이 이 코드에서 access token이 외부 요청으로 나가는 지점이다. SPA는 요청마다 이 헤더를 만든다. - figure "HTTP ·브라우저가 Resource Server를 직접 부를 때 코드 복사" [ref=f27e272]: - generic [ref=f27e273]: - generic [ref=f27e274]: HTTP - generic [ref=f27e275]: ·브라우저가 Resource Server를 직접 부를 때 - button "코드 복사" [ref=f27e276] [cursor=pointer]: 복사 - region "브라우저가 Resource Server를 직접 부를 때 코드" [ref=f27e277]: - code [ref=f27e278]: "GET http://localhost:8081/api/me Authorization: Bearer " - paragraph [ref=f27e280]: token 원문은 memory에도 있고 network 헤더에도 실린다. - paragraph [ref=f27e281]: - text: Resource Server가 - code [ref=f27e282]: SessionCreationPolicy.STATELESS - text: 라서 서버에 지울 session이 없다.이미 발급된 self-contained JWT를 logout 순간에 즉시 없앨 방법이 없고, logout은 Keycloak SSO 종료와 애플리케이션 user 제거를 다룰 뿐 access JWT를 deny-list에서 관리하지 않는다. - paragraph [ref=f27e283]: - strong [ref=f27e284]: 그래서 수명을 짧게 두는 것이 안전하다. - text: "access token : 300초refresh token rotation, 재사용 허용 : xissuer·audience : 검증" - paragraph [ref=f27e285]: Local Storage나 Session Storage로 옮기면 새로고침은 편해지지만 노출 시간이 길어진다.HttpOnly cookie로 옮기는 일은 저장 위치만 바꾸는 작업이 아니다.server가 session이나 token 중계를 맡는 구조가 필요하다. - region [ref=f27e286]: - heading [level=2] [ref=f27e287]: - link "PKCE가 막는 구간 바로가기" [ref=f27e288] [cursor=pointer]: - /url: "#pkce가-막는-구간" - text: PKCE가 막는 구간 - generic [ref=f27e289]: "#" - paragraph [ref=f27e290]: - text: PKCE(Proof Key for Code Exchange)는 authorization request에 - code [ref=f27e291]: code_challenge - text: 를 싣고, code를 token으로 바꿀 때 원본인 - code [ref=f27e292]: code_verifier - text: 를 같이 보내게 한다. 둘이 맞아야 교환이 끝난다. - figure "TEXT ·oidc-client-ts가 만드는 authorization request의 핵심 query 코드 복사" [ref=f27e293]: - generic [ref=f27e294]: - generic [ref=f27e295]: TEXT - generic [ref=f27e296]: ·oidc-client-ts가 만드는 authorization request의 핵심 query - button "코드 복사" [ref=f27e297] [cursor=pointer]: 복사 - region "oidc-client-ts가 만드는 authorization request의 핵심 query 코드" [ref=f27e298]: - code [ref=f27e299]: response_type=code client_id=spa-public redirect_uri=http://localhost:8088/OAuth2callback.html scope=openid profile email state= code_challenge= code_challenge_method=S256 - paragraph [ref=f27e301]: - code [ref=f27e302]: response_type=code - text: 가 Authorization Code Flow를 쓴다는 뜻이고, - code [ref=f27e303]: code_challenge - text: 와 - code [ref=f27e304]: code_challenge_method=S256 - text: 이 PKCE 사용을 나타낸다.막는 구간은 code 교환까지다. 이미 발급된 access token은 막아주지 않는다. - region [ref=f27e305]: - heading [level=2] [ref=f27e306]: - link "확인한 것과 확인하지 않은 것 바로가기" [ref=f27e307] [cursor=pointer]: - /url: "#확인한-것과-확인하지-않은-것" - text: 확인한 것과 확인하지 않은 것 - generic [ref=f27e308]: "#" - paragraph [ref=f27e309]: - text: 아래는 - strong [ref=f27e310]: 커밋된 테스트가 확인하도록 정의한 부분 - text: 이다. 왼쪽이 정의 여부, 오른쪽이 정의 내용. - region "표" [ref=f27e311]: - table [ref=f27e312]: - caption [ref=f27e313] - rowgroup [ref=f27e314]: - row [ref=f27e315]: - columnheader "정의 여부" [ref=f27e316] - columnheader "정의 내용" [ref=f27e317] - rowgroup [ref=f27e318]: - row [ref=f27e319]: - cell "o" [ref=f27e320] - cell [ref=f27e321]: - text: authorization request의 - code [ref=f27e322]: response_type=code - text: ", S256 method, 비어 있지 않은 challenge" - row [ref=f27e323]: - cell "o" [ref=f27e324] - cell "token 응답에 비어 있지 않은 access·refresh·ID token" [ref=f27e325] - row [ref=f27e326]: - cell "o" [ref=f27e327] - cell [ref=f27e328]: - code [ref=f27e329]: /api/me - text: 200과 decoded access token의 audience 포함 - row [ref=f27e330]: - cell "o" [ref=f27e331] - cell "브라우저 fetch를 가로채 Authorization 헤더의 Bearer token 관측" [ref=f27e332] - row [ref=f27e333]: - cell "o" [ref=f27e334] - cell "Local Storage와 Session Storage에 access token substring 없음" [ref=f27e335] - row [ref=f27e336]: - cell "o" [ref=f27e337] - cell "refresh rotation — 새 token 발급, 이전 token 거부, revocation 뒤 refresh 실패" [ref=f27e338] - row [ref=f27e339]: - cell "o" [ref=f27e340] - cell "issuer나 audience가 다른 진단용 서버 두 곳의 401" [ref=f27e341] - row [ref=f27e342]: - cell "x" [ref=f27e343] - cell [ref=f27e344]: - text: token request body의 - code [ref=f27e345]: code_verifier - text: · - code [ref=f27e346]: client_id - text: · - code [ref=f27e347]: redirect_uri - text: ·code 값 대조 - row [ref=f27e348]: - cell "x" [ref=f27e349] - cell "서명이 깨진 JWT, 만료된 JWT" [ref=f27e350] - row [ref=f27e351]: - cell "x" [ref=f27e352] - cell "브라우저 간 요청(CORS)의 preflight 응답" [ref=f27e353] - row [ref=f27e354]: - cell "x" [ref=f27e355] - cell "callback에 error가 실려 돌아왔을 때의 화면" [ref=f27e356] - row [ref=f27e357]: - cell "x" [ref=f27e358] - cell [ref=f27e359]: - code [ref=f27e360]: automaticSilentRenew - text: 의 실제 갱신 경로 - paragraph [ref=f27e361]: - text: 첫 줄과 여덟째 줄을 같이 보자. - strong [ref=f27e362]: authorization request의 파라미터를 보는 것이지 PKCE 교환이 성립하는 것을 보는 것이 아니다. - complementary "주의" [ref=f27e363]: - paragraph [ref=f27e364]: 주의 - paragraph [ref=f27e365]: - text: SPA는 non-2xx 응답에서도 - code [ref=f27e366]: response.ok - text: 을 확인하기 전에 - code [ref=f27e367]: response.json() - text: 을 시도한다. 401 body가 비어 있거나 JSON이 아니면 의도한 메시지 대신 JSON parse error가 먼저 노출되게 된다. - region [ref=f27e368]: - heading [level=2] [ref=f27e369]: - link "추가로 설정에서 확인해야될 것 바로가기" [ref=f27e370] [cursor=pointer]: - /url: "#추가로-설정에서-확인해야될-것" - text: 추가로 설정에서 확인해야될 것 - generic [ref=f27e371]: "#" - paragraph [ref=f27e372]: - text: local realm의 redirect allowlist는 - code [ref=f27e373]: http://localhost:8088/* - text: 와 - code [ref=f27e374]: http://127.0.0.1:8088/* - text: "wildcard다.SPA :" - code [ref=f27e375]: /OAuth2callback.html - text: 만 o,exact callback만 허용하는 운영적 측면 또는 잘못된 redirect를 거부하는 검사는 x - paragraph [ref=f27e376]: - text: frontend Nginx에도 - code [ref=f27e377]: /api/ - text: proxy가 있지만 SPA는 상대 URL이 아니라 absolute - code [ref=f27e378]: http://localhost:8081/api/me - text: 를 쓴다. 그래서 CORS allowlist는 실제로 지나가는 경계이다.상대 URL을 썼다면 이 경계에서 확인되는 부분은 없었을 것이다. - region [ref=f27e379]: - paragraph [ref=f27e380]: Explicit relations - heading "이 기록의 연결" [level=2] [ref=f27e381] - list [ref=f27e382]: - listitem [ref=f27e383]: - link "브라우저가 authorization endpoint와 token endpoint를 모두 지나는 흐름이다. 이 기준의 endpoint별 이동을 코드로 확인한 자리다. Authorization Code Flow의 Endpoint와 Credential 이동 기준" [ref=f27e384] [cursor=pointer]: - /url: /references/authorization-code-endpoint-credential-movement - generic [ref=f27e385]: 브라우저가 authorization endpoint와 token endpoint를 모두 지나는 흐름이다. 이 기준의 endpoint별 이동을 코드로 확인한 자리다. - strong [ref=f27e386]: Authorization Code Flow의 Endpoint와 Credential 이동 기준 - generic [ref=f27e387]: ↗ - complementary [ref=f27e388]: - heading "작업 상태" [level=2] [ref=f27e389] - status "편집 상태" [ref=f27e390]: 저장됨 - generic [ref=f27e391]: - generic [ref=f27e392]: - term [ref=f27e393]: 저장 버전 - definition [ref=f27e394]: "29" - generic [ref=f27e395]: - term [ref=f27e396]: 종류 - definition [ref=f27e397]: CASE - paragraph [ref=f27e398]: 불완전한 초안도 저장할 수 있습니다. Ctrl+S 로도 저장합니다. 게시를 누르면 채워야 할 칸을 그 자리에 표시합니다. - generic [ref=f27e399]: - button "저장" [disabled] [ref=f27e400] - button "게시" [ref=f27e401] - paragraph [ref=f27e402]: 버전 29으로 저장했습니다.