diff --git a/plugins/harnessrouter/skills/harnessrouter/references/key-setup.md b/plugins/harnessrouter/skills/harnessrouter/references/key-setup.md index ee01a64..bbc86ed 100644 --- a/plugins/harnessrouter/skills/harnessrouter/references/key-setup.md +++ b/plugins/harnessrouter/skills/harnessrouter/references/key-setup.md @@ -113,6 +113,25 @@ export function hrApiKey(): string { Use it only in route handlers or server actions that run on the Node runtime (`export const runtime = 'nodejs'`). +Keep the file out of the server build. Next.js traces the files a server route reads and copies +them into its output. On Next.js 16.4.6, with Turbopack and with webpack alike, a build with +`output: 'standalone'` copied `.env.harnessrouter`, key included, into `.next/standalone/`. Both +the loader above and the Node template's `loadApiKey` were copied. Anything that deploys traced +files (a standalone image, Vercel) would then ship the key. Exclude it in `next.config`: + +```js +// next.config.js (or the same key in next.config.ts) +module.exports = { + outputFileTracingExcludes: { '*': ['./.env.harnessrouter'] }, +}; +``` + +Then build and check: `grep -rl env.harnessrouter .next --include='*.nft.json'` prints nothing, +and `.next/standalone/.env.harnessrouter` does not exist. A `/* turbopackIgnore: true */` comment +on the path is not enough: it stops Turbopack's trace but not webpack's. In production, set +`HR_API_KEY` in the host's secret settings, and do not put the file on the machine that builds +for production. + FastAPI (or any Python server): ```python diff --git a/plugins/harnessrouter/skills/harnessrouter/references/security-and-testing.md b/plugins/harnessrouter/skills/harnessrouter/references/security-and-testing.md index 04cdef2..b365e26 100644 --- a/plugins/harnessrouter/skills/harnessrouter/references/security-and-testing.md +++ b/plugins/harnessrouter/skills/harnessrouter/references/security-and-testing.md @@ -64,7 +64,9 @@ the renderer. Verify as applicable: - the signed preview (relative assets load, a tampered or expired token fails, the page cannot reach the product's cookies), downloads, and the unknown-type fallback; - idempotent retry: the same key and body replay, never a second run; -- no key in browser bundles, logs, screenshots, generated files, or the transcript; +- no key in browser bundles, logs, screenshots, generated files, or the transcript, and no key file in + the server build's traced output (Next.js: no `.env.harnessrouter` in `.next/**/*.nft.json` or + `.next/standalone/`; see key-setup.md); - a second user cannot read, continue, cancel, preview, or download the first user's work; - memory, when `ensure` printed a `per_user` memory: a task without `user` gets no memory, and a task with user A never recalls user B's facts (below); diff --git a/tests/test_cloud_scope.py b/tests/test_cloud_scope.py index fb86674..048ddfd 100644 --- a/tests/test_cloud_scope.py +++ b/tests/test_cloud_scope.py @@ -86,6 +86,18 @@ def test_memory_guidance_names_no_internal_systems(self): for n, line in enumerate(p.read_text().splitlines(), 1) if forbidden.search(line)] self.assertEqual(failures, []) + def test_nextjs_key_file_is_kept_out_of_the_server_build(self): + # Next.js copies the files a server route reads into its build output. Measured on 16.4.6: + # the Skill's loader and the template's loadApiKey both put .env.harnessrouter, key and all, + # into .next/standalone with Turbopack and with webpack, until next.config excluded it. + # A turbopackIgnore comment alone stopped Turbopack but not webpack, so the exclusion is + # what the reference has to keep. + key_setup = (SKILL_ROOT / "references" / "key-setup.md").read_text() + self.assertIn("outputFileTracingExcludes: { '*': ['./.env.harnessrouter'] }", key_setup) + self.assertIn("grep -rl env.harnessrouter .next --include='*.nft.json'", key_setup) + acceptance = (SKILL_ROOT / "references" / "security-and-testing.md").read_text() + self.assertIn(".next/**/*.nft.json", acceptance) + def test_skill_relative_markdown_links_resolve(self): markdown_files = [SKILL_ROOT / "SKILL.md", *sorted((SKILL_ROOT / "references").glob("*.md"))] failures = []