Repository navigation
Skill: keep .env.harnessrouter out of a Next.js server build - #2
Open
eric-epsilla wants to merge 1 commit into
Open
eric-epsilla wants to merge 1 commit into
eric-epsilla wants to merge 1 commit into
Conversation
Next.js traces the files a server route reads and copies them into its output. Measured on Next.js 16.4.6 with output: 'standalone': the key-setup loader and the Node template's loadApiKey both put .env.harnessrouter, key included, into .next/standalone/, with Turbopack and with webpack. A standalone image or a platform that deploys traced files would ship the key. A /* turbopackIgnore: true */ comment on the path stopped Turbopack's trace but not webpack's. outputFileTracingExcludes in next.config stopped both, for both loaders, and the built server still read the key from HR_API_KEY (standalone) and from the file (next start in the project). key-setup.md: the exclusion, the check (no match in .next/**/*.nft.json, no file in .next/standalone), and not to put the file on a production build machine. security-and-testing.md: the traced output is on the acceptance list. tests/test_cloud_scope.py checks that both stay; it fails on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
@richard-epsilla, this one is a key leak, so it should go before #1. Problem. In a Next.js 16 app built with Approach. Exclude the file with What I'd like from you:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Next.js traces the files a server route reads and copies them into the build output. I followed the Skill's Next.js key loader (
references/key-setup.md) in a fresh Next.js 16.4.6 app withoutput: 'standalone'. After the build,.env.harnessrouter, key included, was in.next/standalone/and listed in.next/server/app/api/ping/route.js.nft.json. Anything that deploys traced files ships the key: a standalone image, or Vercel.Measured
Next.js 16.4.6, one route handler calling the loader, a fake key in
.env.harnessrouter:*.nft.json.next/standalone//* turbopackIgnore: true */on the path/* turbopackIgnore: true */on the pathoutputFileTracingExcludesloadApiKey()loadApiKey()loadApiKey()outputFileTracingExcludesWith the exclusion in place, the built server still reads the key:
HR_API_KEYset answers{"ok":true};next startin the project, with only the file, answers{"ok":true}.The ignore comment alone is not enough because webpack's tracer does not read it.
Change
references/key-setup.md:next.configwithoutputFileTracingExcludes: { '*': ['./.env.harnessrouter'] };grep -rl env.harnessrouter .next --include='*.nft.json'prints nothing and that.next/standalone/.env.harnessrouterdoes not exist;HR_API_KEYin the host's secret settings.references/security-and-testing.md: the server build's traced output is on the acceptance list.tests/test_cloud_scope.py: checks that both stay. It fails on main.Verification
python3 -m unittest discover -s tests -p 'test_*.py': 45 tests, OK (1 skipped).🤖 Generated with Claude Code