diff --git a/README.md b/README.md index 422214a4..7e3aa74d 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ Build and deploy variables, lowest precedence first: | Variable | Sets | Default | | --- | --- | --- | | `APP_PROFILE` | which `config/runtime/.json` is used | `local`; an empty value fails the build | -| `RUNTIME_API_BASE_URL` | `API_BASE_URL`, overriding the profile | the profile value | -| `RUNTIME_TELEMETRY_ENDPOINT` | `TELEMETRY_ENDPOINT`, overriding the profile | the profile value | +| `RUNTIME_API_BASE_URL` | `API_BASE_URL`, overriding the profile; the CI workflow cannot pass it (see below) | the profile value | +| `RUNTIME_TELEMETRY_ENDPOINT` | `TELEMETRY_ENDPOINT`, overriding the profile; the CI workflow cannot pass it (see below) | the profile value | | `VITE_BUILD_ID` | `BUILD_ID` in the runtime config and the release manifest | `local-build` | | `RELEASE_ID` | `RELEASE_ID` in the runtime config and the release manifest | `local-release` | | `RELEASE_TARGET` | the environment FE-GATE-027 admits the build to; must equal `APP_PROFILE` | none; admission refuses without it | @@ -52,14 +52,23 @@ admission reads (`scripts/verify-documentation-readiness.ts`). Only the two `RUNTIME_*` values can differ from the reviewed profile. Anything else changes by editing the profile file. Staging and production reject demo -auth and non-HTTPS endpoints. +auth, non-HTTPS endpoints and the names reserved for examples and tests +(`example.com`, `example.net`, `example.org` and their subdomains, `.example`, +`.invalid`, `.test`). The shipped `staging` and `production` profiles use +`*.example.com`, so admission refuses them until a project sets its own +endpoints. -A production build and its admission check: +In CI the only way to set the endpoints is to commit them to +`config/runtime/.json`. The CI contract binds just `APP_PROFILE` and +`RELEASE_TARGET` to the build job (`scripts/contracts/ci-gates.ts`), so a +`RUNTIME_*` repository variable never reaches the build. + +A local production build and its admission check: ```bash APP_PROFILE=production \ -RUNTIME_API_BASE_URL=https://api.example.com/ \ -RUNTIME_TELEMETRY_ENDPOINT=https://telemetry.example.com/v1/events \ +RUNTIME_API_BASE_URL=/ \ +RUNTIME_TELEMETRY_ENDPOINT= \ VITE_BUILD_ID= RELEASE_ID= \ corepack pnpm build APP_PROFILE=production RELEASE_TARGET=production corepack pnpm check:release-admission diff --git a/src/contracts/deployment-admission.ts b/src/contracts/deployment-admission.ts index 718b88e9..d095dd5c 100644 --- a/src/contracts/deployment-admission.ts +++ b/src/contracts/deployment-admission.ts @@ -127,10 +127,30 @@ function publicEndpointViolations( field, reason: `${url.hostname} is not reachable from a user's browser`, }); + } else if (isReservedExampleHost(url.hostname)) { + violations.push({ + field, + reason: `${url.hostname} is a name reserved for examples and tests; set the project's endpoint in config/runtime`, + }); } return violations; } +/** + * 1101/13-02. RFC 2606 and RFC 6761 reserve these names for documentation and + * tests. The staging and production profiles ship `*.example.com` endpoints, + * so a host here is a template value nobody replaced, the most common + * configuration to escape after a developer one. + */ +function isReservedExampleHost(hostname: string): boolean { + const host = hostname.toLowerCase().replace(/\.$/u, ""); + return ( + ["example.com", "example.net", "example.org"].some( + (domain) => host === domain || host.endsWith(`.${domain}`), + ) || /\.(?:example|invalid|test)$/u.test(host) + ); +} + /** * Q-6.7-10. The one list of loopback hosts (in `URL.hostname` form) on which * a REST or browser RPC provider may use plain `http:`. diff --git a/tests/unit/deployment-admission.test.ts b/tests/unit/deployment-admission.test.ts index 98ceb542..547bd7ec 100644 --- a/tests/unit/deployment-admission.test.ts +++ b/tests/unit/deployment-admission.test.ts @@ -17,7 +17,7 @@ import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts" const PRODUCTION_ARTIFACT: AdmissionInput = Object.freeze({ APP_ENV: "production", - API_BASE_URL: "https://api.example.com/", + API_BASE_URL: "https://api.my-product.kr/", REQUEST_TIMEOUT_MS: 10_000, MAX_RETRY_ATTEMPTS: 2, TELEMETRY_ENABLED: false, @@ -112,13 +112,16 @@ describe("deployment admission", () => { it("permits a routable public host", () => { for (const host of [ - "https://api.172.16.example.com/", + "https://api.172.16.my-product.kr/", "https://100.128.0.1/", "https://100.63.255.255/", "https://[2001:db8::1]/", "https://[fec0::1]/", - "https://internal.example.com/", - "https://local.example.com/", + "https://internal.my-product.kr/", + "https://local.my-product.kr/", + "https://myexample.com/", + "https://example.com.my-product.kr/", + "https://tested.kr/", ]) { expect( findAdmissionViolations("production", { @@ -130,6 +133,29 @@ describe("deployment admission", () => { } }); + // 1101/13-02. RFC 2606 and RFC 6761 reserve these names for examples and + // tests, so an endpoint on one is a template value that was never replaced. + it("refuses names reserved for examples and tests", () => { + for (const host of [ + "https://example.com/", + "https://api.example.com/", + "https://telemetry.staging.example.net/", + "https://example.org./", + "https://api.example/", + "https://api.invalid/", + "https://desktop.test/", + "https://API.EXAMPLE.COM/", + ]) { + const violations = findAdmissionViolations("production", { + ...PRODUCTION_ARTIFACT, + API_BASE_URL: host, + } as AdmissionInput); + expect(violations, host).toEqual([ + { field: "API_BASE_URL", reason: expect.stringContaining("reserved") }, + ]); + } + }); + it("refuses a placeholder identity on a public target", () => { for (const buildId of ["local-build", "local", "dev", "unknown", ""]) { const violations = findAdmissionViolations("production", { @@ -152,6 +178,17 @@ describe("deployment admission", () => { }); }); +const IDENTITY = Object.freeze({ + VITE_BUILD_ID: "20260815.42", + RELEASE_ID: "r-2026.08.15-1", +}); +// What a project commits to its profile; RUNTIME_* stands in for the edit here. +const PROJECT_ENDPOINTS = Object.freeze({ + ...IDENTITY, + RUNTIME_API_BASE_URL: "https://api.my-product.kr/", + RUNTIME_TELEMETRY_ENDPOINT: "https://telemetry.my-product.kr/v1/events", +}); + describe("runtime config profiles", () => { it("ships one valid profile per deployment target", async () => { const files = (await readdir("config/runtime")).sort(); @@ -174,12 +211,23 @@ describe("runtime config profiles", () => { } }); - it("produces an admissible document for every public target", async () => { + // 1101/13-02. The public profiles ship example endpoints. A project that + // starts from the template and builds without editing them must be refused. + it("refuses a public build from the unedited profile on both endpoints", async () => { for (const target of ["staging", "production"] as const) { - const config = await generateRuntimeConfig(target, { - VITE_BUILD_ID: "20260815.42", - RELEASE_ID: "r-2026.08.15-1", - }); + const config = await generateRuntimeConfig(target, IDENTITY); + expect( + findAdmissionViolations(target, config as unknown as AdmissionInput).map( + (violation) => violation.field, + ), + target, + ).toEqual(["API_BASE_URL", "TELEMETRY_ENDPOINT"]); + } + }); + + it("admits a public build once the project supplies its endpoints", async () => { + for (const target of ["staging", "production"] as const) { + const config = await generateRuntimeConfig(target, PROJECT_ENDPOINTS); expect( findAdmissionViolations(target, config as unknown as AdmissionInput), ).toEqual([]); @@ -247,10 +295,7 @@ describe("runtime config profiles", () => { ] as const)("admits a production artifact under APP_PROFILE=%s only when it names the target", async (profile, status) => { const root = await mkdtemp(path.join(tmpdir(), "release-admission-profile-")); try { - const config = await generateRuntimeConfig("production", { - VITE_BUILD_ID: "20260815.42", - RELEASE_ID: "r-2026.08.15-1", - }); + const config = await generateRuntimeConfig("production", PROJECT_ENDPOINTS); await mkdir(path.join(root, "dist"), { recursive: true }); await writeFile(path.join(root, "dist/config.json"), JSON.stringify(config)); const result = spawnSync( @@ -280,10 +325,7 @@ describe("checking an edited copy of the deployed runtime config", () => { ) { const root = await mkdtemp(path.join(tmpdir(), "release-admission-copy-")); try { - const deployed = await generateRuntimeConfig("production", { - VITE_BUILD_ID: "20260815.42", - RELEASE_ID: "r-2026.08.15-1", - }); + const deployed = await generateRuntimeConfig("production", PROJECT_ENDPOINTS); await writeFile(path.join(root, "deployed.json"), JSON.stringify(deployed)); await writeFile(path.join(root, "edited.json"), JSON.stringify(edit(deployed))); const result = spawnSync( @@ -326,7 +368,7 @@ describe("checking an edited copy of the deployed runtime config", () => { it.each([ ["BUILD_ID", "20260815.43"], ["RELEASE_ID", "r-2026.08.15-2"], - ["API_BASE_URL", "https://other.example.org/"], + ["API_BASE_URL", "https://other.my-product.kr/"], ])("refuses a copy that changes %s, which only a build may change", async (field, value) => { const result = await check((deployed) => ({ ...deployed, [field]: value })); expect(result.status).toBe(1);