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:
@@ -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 () => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user