fix(recipes): OIDC PKCE 레시피가 sessionStorage 키를 registry에서 가져온다

문제: OIDC PKCE session owner 레시피가 sign-in transaction의
sessionStorage 키를 글자 그대로 적는다
(`"ca-frontend:auth:v1:oidc-pkce-transaction"`). 주석은
`buildPhysicalKey(...)`라고 하지만 함수를 부르지 않는다. 템플릿의 다른
Web Storage 키는 모두 `src/contracts/storage-keys.ts` registry가
`APP_NAMESPACE`로 만들고, 어댑터가 직접 쓰는 키도 `backend: "external"`
행으로 둔다. 그래서 제품이 `APP_NAMESPACE`를 바꾸면(memento 설계가
예정한 일) 이 키만 `ca-frontend:`로 남고, registry는 앱이 쓰는 Web
Storage 키 목록이 아니게 된다. registry로 로그아웃 때 지울 키를 정하는
제품은 버려진 sign-in의 verifier·state·nonce·돌아갈 경로를 지우지 못한다.

고른 방법:
- registry에 `AUTH_REDIRECT_TRANSACTION` 행을 둔다. `scope: "auth"`,
  `name: "oidc-pkce-transaction"`, `backend: "external"`(pulse 키와 같은
  모양, StoragePort는 거절), `ttl: "session"`. 물리 키는 지금 글자와 같다
  (`ca-frontend:auth:v1:oidc-pkce-transaction`)라서 진행 중인 sign-in을
  잃지 않는다.
- 레시피의 `OIDC_PKCE_TRANSACTION_KEY`는 그 행의 `physicalKey`다.
  매뉴얼의 복사 규칙(`../../src/` → `../`)이 새 import에도 그대로 맞는다.
- 분류는 `opaque-cache`다. `sensitive-forbidden`은 "저장하지 않는다"는
  뜻이고 backend가 disabled·forbidden이어야 해서 맞지 않는다. 이 값은
  리다이렉트 한 번 동안 저장하는 것이 설계다.
- FE-REG-STORAGE의 `orphanExemptRows`에 이 행을 더한다
  (`config/contracts/registry-governance.json`). 이 행을 쓰는 곳은 레시피
  하나뿐이고, 레시피는 제품이 지울 수 있다(test:optional-recipe-removal).
  행은 registry로 지울 키를 정하는 제품을 위해 남는다. `AUTH_TOKEN`처럼
  사용처 없이 선언만 하는 행이다. 빼지 않으면 `src`만 복사해
  check:registries를 돌리는 `tests/unit/second-api-feature-registries.test.ts`가
  "has no executable consumer"로 실패한다.
  버린 대안: consumer 폴더에 `recipes`를 더하기. 레시피를 지운 사본(FE-GATE-020)
  에서 다시 사용처가 사라진다.

버린 대안: registry에 새 분류(예: `session-transaction`)를 더하기. 계약
타입의 union과 registry 기준선의 허용 값이 함께 바뀌는데, 분류가 코드
동작을 바꾸는 곳은 `sensitive-forbidden` 검사뿐이라 얻는 것이 없다.

위험·한계:
- `src/contracts/storage-keys.ts`에 행 하나가 더해진다(FE-REG-STORAGE
  additive). CHANGELOG [계약] 행이 필요하다.
- 이미 레시피를 복사한 제품은 자기 복사본을 같은 diff로 고쳐야 키가
  namespace를 따른다.
- orphan 검사가 이 행을 보지 않는다. 레시피가 키를 registry에서 가져오는지는
  `tests/recipes/oidc-pkce-session-owner.test.ts`가 본다.

검증: desktop batch에서 확인
- node scripts/run-vitest.ts run tests/unit/storage-registry.test.ts
  tests/recipes/oidc-pkce-session-owner.test.ts
- corepack pnpm check:registries (additive 행)
- node scripts/run-vitest.ts run tests/unit/second-api-feature-registries.test.ts
- corepack pnpm test:optional-recipe-removal

Refs: 1105/05-01
This commit is contained in:
DongHyeonka
2026-11-06 02:07:47 +09:00
parent 56c0bd053d
commit dc7c95b005
6 changed files with 81 additions and 3 deletions
+1 -1
View File
@@ -373,7 +373,7 @@
},
"consumerIdentityField": "logicalName",
"consumerDirectories": ["src", "tests"],
"orphanExemptRows": ["QUERY_PERSISTENCE", "AUTH_TOKEN"],
"orphanExemptRows": ["QUERY_PERSISTENCE", "AUTH_TOKEN", "AUTH_REDIRECT_TRANSACTION"],
"breakingFields": [
"logicalName",
"physicalKey",
+1
View File
@@ -44,6 +44,7 @@
- `fetcher`는 마감이 없다. owner에서 쓰지 않는다. 응답하지 않는 호출 하나가 세션을 "복구 중"에 영원히 둔다.
- `page`: 지금 URL, URL 바꾸기, 다른 페이지로 이동. 로그인 리다이렉트에 쓴다.
- `redirectStorage`: 페이지의 sessionStorage. 리다이렉트 한 번 동안의 상태만 둔다. 토큰은 두지 않는다(`AUTH_TOKEN`은 `src/contracts/storage-keys.ts`에서 `forbidden`이다).
- 키는 registry의 `AUTH_REDIRECT_TRANSACTION`(`backend: "external"`)에서 가져온다. 그래야 `APP_NAMESPACE`를 바꿀 때 같이 바뀐다. 새 owner도 키를 글자로 적지 않는다.
- `readCookie`: 페이지 쿠키 읽기.
4. recipe는 `src/bootstrap/` 아래로 **복사**한다. import하지 않는다.
- `src`가 `recipes/`를 import하면 `check:optional-recipes`가 `PRODUCTION_IMPORTS_RECIPE`로 막는다.
@@ -8,6 +8,7 @@ import type {
ProductSessionOwnerPage,
SessionOwnerFetch,
} from "../../src/bootstrap/product-composition-contract.ts";
import { STORAGE_REGISTRY } from "../../src/contracts/storage-keys.ts";
/**
* 1103/09-03. A session owner for the paired backend's JWT mode
@@ -40,8 +41,15 @@ import type {
* shows the realm client and the wiring.
*/
/** `buildPhysicalKey("auth", 1, "oidc-pkce-transaction")`; never a token. */
export const OIDC_PKCE_TRANSACTION_KEY = "ca-frontend:auth:v1:oidc-pkce-transaction";
/**
* The sessionStorage key of the sign-in transaction; never a token.
* 1105/05-01. It comes from the storage registry
* (`AUTH_REDIRECT_TRANSACTION`, `backend: "external"`), so it follows the
* app's `APP_NAMESPACE` like every other Web Storage key. It used to be a
* literal that kept `ca-frontend:` after a product renamed the namespace.
*/
export const OIDC_PKCE_TRANSACTION_KEY =
STORAGE_REGISTRY.AUTH_REDIRECT_TRANSACTION.physicalKey;
export type OidcPkceSessionOwnerOptions = Readonly<{
/** Exact issuer, e.g. `http://localhost:8081/realms/ca-skeleton`. HTTPS off this machine. */
+22
View File
@@ -133,6 +133,28 @@ export const STORAGE_REGISTRY = Object.freeze({
migration: "discard",
quotaFallback: "feature-disable",
}),
/**
* 1105/05-01. The OIDC PKCE session owner recipe
* (`recipes/session-owners/oidc-pkce-session-owner.ts`) keeps one sign-in
* transaction here in sessionStorage: the PKCE verifier, `state`, `nonce`
* and the return path, never a token, for at most ten minutes, and the
* callback deletes it first. The recipe owns the value format, so only the
* name lives here and StoragePort refuses the key. It is not
* `sensitive-forbidden`, which means "never stored"; this one is stored by
* design for one redirect.
*/
AUTH_REDIRECT_TRANSACTION: defineStorageKey({
logicalName: "AUTH_REDIRECT_TRANSACTION",
scope: "auth",
name: "oidc-pkce-transaction",
backend: "external",
classification: "opaque-cache",
schemaVersion: 1,
valueCodec: "none",
ttl: "session",
migration: "discard",
quotaFallback: "no-persist",
}),
});
export function defineStorageKey<Definition extends StorageKeyInput>(
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
import { describe, expect, it, vi } from "vitest";
import type { SessionOwnerFetch } from "../../src/bootstrap/product-composition-contract.ts";
import { STORAGE_REGISTRY } from "../../src/contracts/storage-keys.ts";
import {
createOidcPkceSessionOwner,
OIDC_PKCE_TRANSACTION_KEY,
@@ -193,6 +194,14 @@ describe("OIDC PKCE session owner: sign-in", () => {
expect(transaction.returnTo).toBe("/items?limit=1");
expect(transaction.verifier).toMatch(/^[A-Za-z0-9_-]{43}$/u);
expect(setup.storage.size).toBe(1);
// 1105/05-01. The key is the storage registry's row, so it follows the
// app's APP_NAMESPACE instead of a literal `ca-frontend:` prefix.
expect([...setup.storage.keys()]).toEqual([
STORAGE_REGISTRY.AUTH_REDIRECT_TRANSACTION.physicalKey,
]);
expect(OIDC_PKCE_TRANSACTION_KEY).toBe(
STORAGE_REGISTRY.AUTH_REDIRECT_TRANSACTION.physicalKey,
);
});
it("returns only to a path of this app", async () => {
+38
View File
@@ -200,6 +200,44 @@ describe("storage registry", () => {
);
});
// 1105/05-01. The OIDC PKCE recipe wrote its sessionStorage key as a
// literal outside the registry, so renaming APP_NAMESPACE split it off. The
// key is now a registry row the recipe reads, and StoragePort refuses it
// like the pulse key.
it("registers the PKCE sign-in transaction key as externally owned and refuses it", () => {
const transaction = STORAGE_REGISTRY.AUTH_REDIRECT_TRANSACTION;
const raw = JSON.stringify({ state: "s", nonce: "n" });
const { storage, values, setItem, removeItem } = createStorage({
initial: { [transaction.physicalKey]: raw },
});
const adapter = createBrowserStorageAdapter({ sessionStorage: storage });
expect(transaction).toMatchObject({
scope: "auth",
name: "oidc-pkce-transaction",
backend: "external",
valueCodec: "none",
});
expect(transaction.physicalKey).toBe(
buildPhysicalKey("auth", 1, "oidc-pkce-transaction"),
);
expect(adapter.read("AUTH_REDIRECT_TRANSACTION")).toMatchObject({
ok: false,
});
expect(adapter.write("AUTH_REDIRECT_TRANSACTION", "hello")).toMatchObject({
ok: false,
});
expect(adapter.remove("AUTH_REDIRECT_TRANSACTION")).toMatchObject({
ok: false,
});
expect(setItem).not.toHaveBeenCalled();
expect(removeItem).not.toHaveBeenCalled();
expect(values.get(transaction.physicalKey)).toBe(raw);
expect(() => getStorageDefinition("AUTH_REDIRECT_TRANSACTION")).toThrow(
"Externally owned storage key: AUTH_REDIRECT_TRANSACTION",
);
});
it("rejects a value codec on an externally owned key", () => {
expect(() =>
defineStorageKey({