Principle:3641397194 wq Gpt6 Astra Supply Chain Isolation
| Knowledge Sources | |
|---|---|
| Domains | Supply_Chain_Security, Process_Isolation, Dependency_Management |
| Last Updated | 2026-10-26 12:00 GMT |
Overview
A dependency preparation strategy that runs `npm ci` in a fully isolated environment — scoped HOME, empty npmrc, no install scripts, locked deps, content-addressed receipt — to prevent supply-chain attacks through malicious packages.
Description
Supply Chain Isolation is the security practice of preparing third-party runtime dependencies (the REA agent runtime) in an environment that cannot be influenced by user configuration, local file paths, or install-time scripts. It addresses the problem of npm supply chain attacks: a malicious package's `install` script, a user's `.npmrc` pointing to a private registry, or a `file:`/`link:` dependency could execute arbitrary code during dependency installation.
The isolation has multiple layers:
- Environment stripping: removes `NODE_OPTIONS`, `NODE_PATH`, `NODE_V8_COVERAGE`, `NPM_CONFIG_*`, `NPM_TOKEN`, `NODE_AUTH_TOKEN` from the child env. Scoped `HOME`, `APPDATA`, `XDG_*`, `TEMP` directories are created under the install scope.
- Empty npmrc: writes empty `user.npmrc` and `global.npmrc` under the scope's config directory, and sets `npm_config_userconfig`/`npm_config_globalconfig` to those paths. Verifies they remain empty.
- No install scripts: `npm ci --omit=dev --omit=optional --ignore-scripts --no-audit --no-fund` — dev and optional deps excluded, install scripts disabled.
- Lockfile validation: `assertLockSources` rejects `file:`, `link:`, `workspace:`, `git+`, `ssh:`, relative, and absolute paths in both `package.json` dependencies and `package-lock.json` entries.
- Content-addressed receipt: after installation, `verifyDependencies` imports each core dependency (`zod`, `@modelcontextprotocol/server`), resolves its real path, and records its SHA-256. `saveReceipt` writes a receipt with `schema:1`, version hashes, node version, and per-dependency entries. `readReceipt` re-validates the receipt on every status check.
- Launcher integrity: `sameLauncher` verifies the installed `rea-launcher.cjs` is a regular file ≤ 2 MB with a SHA-256 matching the bundled copy — preventing a swapped launcher from running.
- Concurrency lock: `acquireLock` uses a file lock with PID liveness check and abandoned-lock recovery — only one preparation per scope at a time.
Usage
Use this principle when you need to install third-party npm dependencies for an embedded runtime without trusting the user's npm configuration, local file system links, or package install scripts. It is the foundation of the upstream REA prepare workflow.
Theoretical Basis
The isolation pipeline:
# Abstract algorithm (NOT real implementation)
def prepare_scope(base, options):
info = read_runtime(base) # validate package.json, lockfile, scripts
release = acquire_lock(info.scope) # file lock with PID check
child_env = prepare_environment(info.scope, source_env)
# child_env has: scoped HOME, empty npmrc, no NODE_OPTIONS,
# npm_config_ignore_scripts=true, no NPM_TOKEN
npm_cli = find_npm_cli(options) # resolve npm-cli.js, never npm.cmd
result = run_process(node, [npm_cli, "ci", "--omit=dev",
"--omit=optional", "--ignore-scripts", "--no-audit",
"--no-fund"], cwd=info.runtime, env=child_env)
assert_node_modules(base) # no symlinks escaping, no hardlinks
entries = verify_dependencies(info) # import + hash each core dep
save_receipt(info, node_version, entries) # content-addressed proof
return {ok: True, code: "REA_READY", version: info.version}
def prepare_environment(base, source_env):
env = {}
for key, value in source_env.items():
if key in STRIPPED_KEYS: continue # NODE_OPTIONS, NPM_TOKEN, etc.
if key in ALLOWED_KEYS: env[key] = value # PATH, TEMP, LANG, etc.
env["HOME"] = ensure_dir(base, "cache/home") # scoped HOME
env["npm_config_cache"] = ensure_dir(base, "cache/npm")
write_empty(base, "cache/config/user.npmrc")
write_empty(base, "cache/config/global.npmrc")
env["npm_config_ignore_scripts"] = "true"
return env
Key properties:
- Lockfile v2/v3 required: `assertLockSources` rejects lockfile versions 1 (no `packages` key) and validates every entry path starts with `node_modules/` and contains no `..`.
- npm-cli.js resolution: `findNpmCli` resolves the npm JavaScript entry point directly — never executes `npm.cmd` through an interpolated shell, preventing PATH injection.
- Abandoned lock recovery: `acquireLock` checks if the lock owner PID is alive; if dead, removes the lock (with identity recheck to avoid TOCTOU).
- Node version check: `supportedNode` validates the Node.js version is in `NODE_RANGE` before preparation; the receipt records the node version and rejects mismatches on re-check.
- Dependency verification: `verifyDependencies` runs an ESM eval script that actually `import()`s each core dependency — not just file existence, but actual module loading.
- Receipt re-validation: `readReceipt` checks schema, version, hashes, node version, and re-hashes each core dependency file on disk — the receipt is the durable proof of a correct install.
Practical Guide
- The REA scope lives at `<install-root>/.coldcoffee-upstream/` — isolated from the seat config directory.
- `statusRea(root)` is read-only: it checks status without side effects, safe to call from the UI at any time.
- `prepareRea` strips `NODE_OPTIONS`/`NODE_PATH`/`NODE_V8_COVERAGE` from the child env but preserves `PATH` so `node` can find `npm-cli.js`.
- The concurrency lock (`activePreparations` Set in `beginner-install.js`) prevents install/uninstall during preparation at the orchestrator level, complementing the file-level `acquireLock`.
- If `prepareRea` succeeds but `statusRea(root).ready` is still false, it returns `REA_NOT_READY` — the receipt did not validate.
Related Pages
Implemented By
- Implementation:3641397194_wq_Gpt6_Astra_prepareRea
- Implementation:3641397194_wq_Gpt6_Astra_beginner_install