Files
openclaw/src/plugins/hardlink-policy.ts
Peter Steinberger 98e3f729bc refactor: remove dead plugin loader exports (#105937)
* refactor(plugins): trim activation and contract exports

* test(plugins): restore fixture cleanup

* refactor(plugins): trim install and loader exports

* test(plugins): fully reset loader caches

* refactor(plugins): trim metadata and catalog exports

* test(plugins): preserve catalog trust coverage

* refactor(plugins): trim provider and plugin exports

* refactor(plugins): trim runtime and tool exports

* test(plugins): update dead-export consumers

* test(plugins): remove empty dead-export suites

* refactor(plugins): align exports with split registry

* refactor(plugins): trim drifted loader exports

* style(plugins): format test fixtures

* refactor(scripts): use supported plugin APIs

* refactor(plugins): finish dead export cleanup

* chore(deadcode): refresh export baseline

* test(cli): mock production memory state

* chore(deadcode): sync latest export baseline

* fix(tests): keep plugin fixtures inside core

* chore(deadcode): refresh rebased export baseline

* chore(deadcode): sync current ratchets

* fix(plugins): retain reserved slot invariant

* fix(plugins): preserve dead-export invariants

* test(plugins): use neutral catalog query fixture

* test(plugins): satisfy catalog lint

* test(plugins): preserve integrity drift coverage

* fix(ci): register skill experience live proof
2026-07-13 01:29:33 -07:00

39 lines
1.7 KiB
TypeScript

/** Enforces plugin root hardlink policy with bundled and immutable Nix-store exceptions. */
import path from "node:path";
import { resolveIsNixMode } from "../config/paths.js";
import { safeRealpathSync } from "./path-safety.js";
import type { PluginOrigin } from "./plugin-origin.types.js";
const NIX_STORE_ROOT = "/nix/store";
// Hardlinks are rejected for user/config/workspace plugin roots by default. A
// hardlinked file can appear to live under a plugin root while sharing an inode
// with a file created elsewhere, which weakens the root-boundary checks used
// before loading plugin code.
//
// Two roots are allowed:
// - bundled: plugins shipped with OpenClaw itself, not user-installed code.
// - /nix/store in OPENCLAW_NIX_MODE: immutable Nix package outputs, where
// hardlinked files are normal package-store layout rather than user mutation.
/** Returns true when a plugin root resolves inside the immutable Nix store. */
function isNixStorePluginRoot(rootDir: string, realpathCache?: Map<string, string>): boolean {
const rootRealPath = safeRealpathSync(rootDir, realpathCache) ?? path.resolve(rootDir);
return rootRealPath === NIX_STORE_ROOT || rootRealPath.startsWith(`${NIX_STORE_ROOT}/`);
}
/** Decides whether plugin file hardlinks should fail boundary validation for one root. */
export function shouldRejectHardlinkedPluginFiles(params: {
origin: PluginOrigin;
rootDir: string;
env?: NodeJS.ProcessEnv;
realpathCache?: Map<string, string>;
}): boolean {
if (params.origin === "bundled") {
return false;
}
if (resolveIsNixMode(params.env) && isNixStorePluginRoot(params.rootDir, params.realpathCache)) {
return false;
}
return true;
}