Skip to content

Commit 553c245

Browse files
committed
fix(cloud-workers): install bundle deps after the integrity check, hash the vendor tree
The bundle install verifier walks the staged tree and compares its hash to the expected bundle hash. Two live-E2E bugs: (1) it never walked vendor/, so vendored workspace packages failed the hash; (2) npm install ran before the check, so node_modules (intentionally hash-excluded) polluted the tree. Verify the pristine bundle including vendor/, then run the production npm install. Proven locally: VERIFY_INSTALL_JS returns 0 on the extracted tarball and the worker entry resolves every module post-install.
1 parent 301a4bf commit 553c245

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/gateway/worker-environments/bootstrap.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ try {
200200
readNpmInventory();
201201
} else if (install === "bundle") {
202202
walk("dist");
203+
// Vendored workspace packages ship inside the bundle and are part of its hash;
204+
// node_modules is installed after verification and never walked here.
205+
const vendorPath = path.join(root, "vendor");
206+
const vendorStats = fs.existsSync(vendorPath) ? fs.lstatSync(vendorPath) : undefined;
207+
if (vendorStats) {
208+
if (vendorStats.isSymbolicLink() || !vendorStats.isDirectory()) {
209+
fail("unsafe worker vendor directory");
210+
}
211+
walk("vendor");
212+
}
203213
} else {
204214
fail("invalid worker install channel");
205215
}
@@ -429,11 +439,6 @@ case "$install" in
429439
exit 2
430440
fi
431441
tar -xzf "$upload" -C "$staging"
432-
if ! command -v npm >/dev/null 2>&1; then
433-
printf '%s\n' '${NPM_MISSING_MARKER}' >&2
434-
exit ${NPM_MISSING_EXIT_CODE}
435-
fi
436-
OPENCLAW_DISABLE_PLUGIN_REGISTRY_MIGRATION=1 npm install --prefix "$staging" --ignore-scripts --omit=dev --no-audit --no-fund
437442
;;
438443
npm)
439444
if ! command -v npm >/dev/null 2>&1; then
@@ -470,6 +475,15 @@ if ! node -e '${VERIFY_INSTALL_JS}' "$staging" "$hash" "$install"; then
470475
printf '%s\n' 'worker install content does not match the expected bundle hash' >&2
471476
exit 2
472477
fi
478+
# Materialize production dependencies only after the pristine bundle passed its
479+
# integrity check; npm install writes node_modules the hash intentionally excludes.
480+
if [ "$install" = bundle ]; then
481+
if ! command -v npm >/dev/null 2>&1; then
482+
printf '%s\n' '${NPM_MISSING_MARKER}' >&2
483+
exit ${NPM_MISSING_EXIT_CODE}
484+
fi
485+
OPENCLAW_DISABLE_PLUGIN_REGISTRY_MIGRATION=1 npm install --prefix "$staging" --ignore-scripts --omit=dev --no-audit --no-fund >&2
486+
fi
473487
printf '%s\n' "$receipt_json" > "$staging/${BOOTSTRAP_RECEIPT}"
474488
chmod 600 "$staging/${BOOTSTRAP_RECEIPT}"
475489
rm -rf "$install_dir"

0 commit comments

Comments
 (0)