Skip to content

Commit 75f7063

Browse files
cliffhallclaude
andcommitted
fix: the publishConfig check fails closed; pack:verify launches with a sanitized environment
- release.yml stops when the tarball cannot be read or its manifest does not parse, instead of treating either as 'no publishConfig'. - pack:verify drops PYTHONPATH, VIRTUAL_ENV, NODE_PATH and the like from the installed server's environment, so an undeclared dependency cannot resolve from the caller's shell. - RELEASING.md and the release skill say to wait for every build leg to finish and approve the healthy packages, rather than require all green. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent deff224 commit 75f7063

6 files changed

Lines changed: 79 additions & 10 deletions

File tree

‎.claude/skills/release/SKILL.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,11 @@ A maintainer does this, through the GitHub UI, after the merge PR has merged:
360360

361361
Publishing the Release starts `release.yml`. Its build jobs run first, without
362362
credentials: tests, then `pack:verify`. The publish jobs then wait for the
363-
`release` environment's approval. **Approve only after the build jobs are
364-
green**; the list of what each leg will publish or skip is in their logs.
363+
`release` environment's approval. **Wait for every build leg to finish before
364+
approving**, and read their logs: each says what its package will publish or
365+
skip. Approve the packages whose build leg passed. One failed build leg does
366+
not hold the others back; that package is handled as a failed publish
367+
(`RELEASING.md` **When a publish fails**).
365368

366369
## 6. After it publishes
367370

‎.github/workflows/release.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,18 @@ jobs:
232232
# injected registry or proxy could redirect this job's credential
233233
# flow. No package here declares one, so any present is refused, and
234234
# the registry is named on the command line as well.
235-
if tar -xOzf "$1" package/package.json | node -e "process.exit('publishConfig' in JSON.parse(require('fs').readFileSync(0, 'utf8')) ? 0 : 1)"; then
235+
# The check fails closed: a tarball that cannot be read, or a
236+
# manifest that does not parse, stops the job. Only a manifest that
237+
# was read and has no `publishConfig` goes on to `npm publish`.
238+
MANIFEST="$(tar -xOzf "$1" package/package.json)" || {
239+
echo "Refusing to publish: could not read package/package.json from $1"
240+
exit 1
241+
}
242+
VERDICT="$(printf '%s' "$MANIFEST" | node -e "console.log('publishConfig' in JSON.parse(require('fs').readFileSync(0, 'utf8')) ? 'declared' : 'clean')")" || {
243+
echo "Refusing to publish: the tarball's package.json does not parse"
244+
exit 1
245+
}
246+
if [ "$VERDICT" != "clean" ]; then
236247
echo "Refusing to publish: the tarball's package.json declares publishConfig"
237248
exit 1
238249
fi

‎RELEASING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Publishing is triggered by a maintainer **publishing a GitHub Release** whose ta
5454

5555
The split is about what runs next to the publish credential. Installing dependencies runs their lifecycle scripts, and a build runs a toolchain; in a job that can mint an OIDC token, any of that code could publish. Here the token only ever sits beside the registry client and SHA-pinned actions. Every action in the build and publish jobs is pinned to a commit SHA, enforced by `npm run verify:action-pins`.
5656

57-
The build jobs finish before the publish jobs ask for approval, so **approve the `release` environment only once the build jobs are green**. Their logs say what each package will do.
57+
The build jobs finish before the publish jobs ask for approval, so **wait for every build leg to finish before approving the `release` environment**, and read their logs: they say what each package will do. A package whose build leg passed is safe to approve. One failed build leg does not hold the others back: approve the healthy packages, and handle the failed one as described under [When a publish fails](#when-a-publish-fails).
5858

5959
The **registry-diff guard** is what makes a release idempotent and self-healing. A package whose version is already on the registry is **skipped, not failed**:
6060

‎scripts/pack-and-verify.mjs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,38 @@ export function artifactDirProblem(dir) {
205205
return null;
206206
}
207207

208+
/**
209+
* Variables that let a launched server find code OUTSIDE its install: module
210+
* search paths, an activated environment, preloaded options. With any of them
211+
* inherited, a dependency the package forgot to declare can still resolve
212+
* from the developer's shell, and the check passes on a package that fails
213+
* for a user.
214+
*/
215+
export const LEAKY_ENV = [
216+
"PYTHONPATH",
217+
"PYTHONHOME",
218+
"PYTHONSTARTUP",
219+
"VIRTUAL_ENV",
220+
"CONDA_PREFIX",
221+
"NODE_PATH",
222+
"NODE_OPTIONS",
223+
];
224+
225+
/**
226+
* The environment an installed server is launched with: the caller's, minus
227+
* the variables in `LEAKY_ENV`. Everything else (PATH, HOME, proxy settings,
228+
* the temp directory) is kept, since the server needs a working system.
229+
*
230+
* @param {NodeJS.ProcessEnv} [env]
231+
* @returns {NodeJS.ProcessEnv}
232+
*/
233+
export function consumerEnv(env = process.env) {
234+
const leaky = new Set(LEAKY_ENV);
235+
return Object.fromEntries(
236+
Object.entries(env).filter(([key]) => !leaky.has(key.toUpperCase())),
237+
);
238+
}
239+
208240
/** Is this file name something PyPI accepts: a wheel or an sdist? */
209241
export function isDistribution(file) {
210242
return file.endsWith(".whl") || file.endsWith(".tar.gz");
@@ -360,8 +392,10 @@ export async function main(argv = process.argv.slice(2)) {
360392
}),
361393
],
362394
// Not the checkout: a relative path that only resolves there
363-
// must not resolve here.
395+
// must not resolve here, and neither must a module the shell's
396+
// environment would lend it.
364397
cwd: consumer,
398+
env: consumerEnv(),
365399
},
366400
);
367401
}

‎scripts/pack-and-verify.test.mjs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { tmpdir } from "node:os";
1717
import path from "node:path";
1818
import {
1919
artifactDirProblem,
20+
consumerEnv,
2021
installedLaunch,
2122
isDistribution,
2223
main,
@@ -147,6 +148,24 @@ test("an artifact directory must be absent or empty; nothing is deleted", () =>
147148
}
148149
});
149150

151+
test("consumerEnv drops what would lend the server code from outside its install", () => {
152+
const env = consumerEnv({
153+
PATH: "/usr/bin",
154+
HOME: "/home/u",
155+
PYTHONPATH: "/checkout/src",
156+
VIRTUAL_ENV: "/checkout/.venv",
157+
NODE_PATH: "/checkout/node_modules",
158+
NODE_OPTIONS: "--require ./hook.js",
159+
Pythonpath: "windows-spelling",
160+
HTTPS_PROXY: "http://proxy",
161+
});
162+
assert.deepEqual(env, {
163+
PATH: "/usr/bin",
164+
HOME: "/home/u",
165+
HTTPS_PROXY: "http://proxy",
166+
});
167+
});
168+
150169
test("only wheels and sdists are distributions", () => {
151170
assert.equal(
152171
isDistribution("mcp_server_time-2026.8.1-py3-none-any.whl"),

‎scripts/smoke-servers.mjs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ async function stop(child) {
375375
}
376376

377377
/** The environment a server is launched with: ours, plus its own extras. */
378-
function envFor(server, ctx, extra = {}) {
378+
function envFor(server, ctx, extra = {}, base = process.env) {
379379
const env = {};
380-
for (const [key, value] of Object.entries(process.env))
380+
for (const [key, value] of Object.entries(base))
381381
if (typeof value === "string") env[key] = value;
382382
return { ...env, ...(server.env?.(ctx) ?? {}), ...extra };
383383
}
@@ -394,7 +394,9 @@ function envFor(server, ctx, extra = {}) {
394394
* @param {(typeof SERVERS)[number]} server
395395
* @param {string} transport
396396
* @param {{ dir: string, pageUrl: string }} ctx
397-
* @param {{ command: string, args: string[], cwd: string }} [installed]
397+
* @param {{ command: string, args: string[], cwd: string, env?: NodeJS.ProcessEnv }} [installed]
398+
* `env`, when given, replaces this process's environment as the base the
399+
* server's own variables are added to
398400
*/
399401
export async function smokeOne(server, transport, ctx, installed) {
400402
const spec = installed ?? launchSpec(server, transport, ctx);
@@ -421,7 +423,7 @@ export async function smokeOne(server, transport, ctx, installed) {
421423
command: spec.command,
422424
args: spec.args,
423425
cwd: spec.cwd,
424-
env: envFor(server, ctx),
426+
env: envFor(server, ctx, {}, installed?.env),
425427
stderr: "pipe",
426428
});
427429
clientTransport.stderr?.on("data", (chunk) => (stderr += chunk));
@@ -452,7 +454,7 @@ export async function smokeOne(server, transport, ctx, installed) {
452454
let output = "";
453455
const child = spawn(spec.command, spec.args, {
454456
cwd: spec.cwd,
455-
env: envFor(server, ctx, { PORT: String(port) }),
457+
env: envFor(server, ctx, { PORT: String(port) }, installed?.env),
456458
stdio: ["ignore", "pipe", "pipe"],
457459
});
458460
child.stdout.on("data", (chunk) => (output += chunk));

0 commit comments

Comments
 (0)