Skip to content

Commit 954d20e

Browse files
joshp123codex
andauthored
fix: allow Nix store plugin hardlinks (#79344)
Merged via squash. Prepared head SHA: bf533f8 Co-authored-by: Codex <[email protected]> Reviewed-by: @joshp123
1 parent b856b3f commit 954d20e

11 files changed

Lines changed: 263 additions & 55 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Docs: https://docs.openclaw.ai
191191
- Gateway/Tailscale: add opt-in `gateway.tailscale.preserveFunnel` so when `tailscale.mode = "serve"` and an externally configured Tailscale Funnel route already covers the gateway port, OpenClaw skips re-applying `tailscale serve` on startup and skips the `resetOnExit` teardown for that run, keeping operator-managed Funnel exposure alive across gateway restarts. Fixes #57241. Thanks @RenzoMXD.
192192
- Agents/compaction: keep the recent tail after manual `/compact` when Pi returns an empty or no-op compaction summary, preventing blank checkpoints from replacing the live context.
193193
- Native commands: handle slash commands before workspace and agent-reply bootstrap so Telegram `/status` and other command-only native replies do not wait behind full agent turn setup.
194+
- Plugins/Nix: allow externally configured plugin roots under `/nix/store` to load in `OPENCLAW_NIX_MODE=1` while keeping normal external plugin hardlink rejection unchanged. Thanks @joshp123.
194195
- fix(discord): gate user allowlist name resolution [AI]. (#79002) Thanks @pgondhi987.
195196
- fix(msteams): gate startup user allowlist resolution [AI]. (#79003) Thanks @pgondhi987.
196197
- Infra/fetch-timeout: pass `operation` and `url` context to `buildTimeoutAbortSignal` from the music-generate reference fetch and the Matrix guarded redirect transport, so the `fetch timeout reached; aborting operation` warning carries actionable structured fields instead of a bare line. Fixes #79195. Thanks @pandadev66.

‎src/gateway/server-startup-early.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("startGatewayEarlyRuntime", () => {
5050
chatRunBuffers: new Map(),
5151
chatDeltaSentAt: new Map(),
5252
chatDeltaLastBroadcastLen: new Map(),
53-
removeChatRun: () => {},
53+
removeChatRun: () => undefined,
5454
agentRunSeq: new Map(),
5555
nodeSendToSession: () => {},
5656
skillsRefreshDelayMs: 30_000,

‎src/plugins/channel-catalog-registry.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PluginInstallRecord } from "../config/types.plugins.js";
22
import { discoverOpenClawPlugins } from "./discovery.js";
3+
import { shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
34
import { loadInstalledPluginIndexInstallRecordsSync } from "./installed-plugin-index-record-reader.js";
45
import {
56
loadPluginManifest,
@@ -45,7 +46,14 @@ export function listChannelCatalogEntries(
4546
if (!channel?.id) {
4647
return [];
4748
}
48-
const manifest = loadPluginManifest(candidate.rootDir, candidate.origin !== "bundled");
49+
const manifest = loadPluginManifest(
50+
candidate.rootDir,
51+
shouldRejectHardlinkedPluginFiles({
52+
origin: candidate.origin,
53+
rootDir: candidate.rootDir,
54+
env: params.env,
55+
}),
56+
);
4957
if (!manifest.ok) {
5058
return [];
5159
}

‎src/plugins/discovery.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
resolvePackageRuntimeExtensionSources,
3030
resolvePackageSetupSource,
3131
} from "./package-entry-resolution.js";
32+
import { shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
3233
import { formatPosixMode, isPathInside, safeRealpathSync, safeStatSync } from "./path-safety.js";
3334
import { tracePluginLifecyclePhase } from "./plugin-lifecycle-trace.js";
3435
import type { PluginOrigin } from "./plugin-origin.types.js";
@@ -571,6 +572,7 @@ function addCandidate(params: {
571572
function discoverBundleInRoot(params: {
572573
rootDir: string;
573574
origin: PluginOrigin;
575+
env: NodeJS.ProcessEnv;
574576
ownershipUid?: number | null;
575577
workspaceDir?: string;
576578
manifest?: PackageManifest | null;
@@ -584,11 +586,17 @@ function discoverBundleInRoot(params: {
584586
return "none";
585587
}
586588
const rootRealPath = safeRealpathSync(params.rootDir, params.realpathCache) ?? undefined;
589+
const rejectHardlinks = shouldRejectHardlinkedPluginFiles({
590+
origin: params.origin,
591+
rootDir: params.rootDir,
592+
env: params.env,
593+
realpathCache: params.realpathCache,
594+
});
587595
const bundleManifest = loadBundleManifest({
588596
rootDir: params.rootDir,
589597
...(rootRealPath !== undefined ? { rootRealPath } : {}),
590598
bundleFormat,
591-
rejectHardlinks: params.origin !== "bundled",
599+
rejectHardlinks,
592600
});
593601
if (!bundleManifest.ok) {
594602
params.diagnostics.push({
@@ -620,6 +628,7 @@ function discoverBundleInRoot(params: {
620628
function discoverInDirectory(params: {
621629
dir: string;
622630
origin: PluginOrigin;
631+
env: NodeJS.ProcessEnv;
623632
ownershipUid?: number | null;
624633
workspaceDir?: string;
625634
candidates: PluginCandidate[];
@@ -684,8 +693,13 @@ function discoverInDirectory(params: {
684693
continue;
685694
}
686695

687-
const rejectHardlinks = params.origin !== "bundled";
688696
const fullPathRealPath = safeRealpathSync(fullPath, params.realpathCache) ?? undefined;
697+
const rejectHardlinks = shouldRejectHardlinkedPluginFiles({
698+
origin: params.origin,
699+
rootDir: fullPath,
700+
env: params.env,
701+
realpathCache: params.realpathCache,
702+
});
689703
const manifest = readCandidatePackageManifest({
690704
dir: fullPath,
691705
origin: params.origin,
@@ -745,6 +759,7 @@ function discoverInDirectory(params: {
745759
const bundleDiscovery = discoverBundleInRoot({
746760
rootDir: fullPath,
747761
origin: params.origin,
762+
env: params.env,
748763
ownershipUid: params.ownershipUid,
749764
workspaceDir: params.workspaceDir,
750765
manifest,
@@ -890,8 +905,13 @@ function discoverFromPath(params: {
890905
}
891906

892907
if (stat.isDirectory()) {
893-
const rejectHardlinks = params.origin !== "bundled";
894908
const resolvedRealPath = safeRealpathSync(resolved, params.realpathCache) ?? undefined;
909+
const rejectHardlinks = shouldRejectHardlinkedPluginFiles({
910+
origin: params.origin,
911+
rootDir: resolved,
912+
env: params.env,
913+
realpathCache: params.realpathCache,
914+
});
895915
const manifest = readCandidatePackageManifest({
896916
dir: resolved,
897917
origin: params.origin,
@@ -951,6 +971,7 @@ function discoverFromPath(params: {
951971
const bundleDiscovery = discoverBundleInRoot({
952972
rootDir: resolved,
953973
origin: params.origin,
974+
env: params.env,
954975
ownershipUid: params.ownershipUid,
955976
workspaceDir: params.workspaceDir,
956977
manifest,
@@ -989,6 +1010,7 @@ function discoverFromPath(params: {
9891010
discoverInDirectory({
9901011
dir: resolved,
9911012
origin: params.origin,
1013+
env: params.env,
9921014
ownershipUid: params.ownershipUid,
9931015
workspaceDir: params.workspaceDir,
9941016
candidates: params.candidates,
@@ -1062,6 +1084,7 @@ export function discoverOpenClawPlugins(params: {
10621084
discoverInDirectory({
10631085
dir: roots.workspace,
10641086
origin: "workspace",
1087+
env,
10651088
ownershipUid: params.ownershipUid,
10661089
workspaceDir: workspaceRoot,
10671090
candidates: result.candidates,
@@ -1114,6 +1137,7 @@ export function discoverOpenClawPlugins(params: {
11141137
discoverInDirectory({
11151138
dir: roots.stock,
11161139
origin: "bundled",
1140+
env,
11171141
ownershipUid: params.ownershipUid,
11181142
candidates: result.candidates,
11191143
diagnostics: result.diagnostics,
@@ -1131,6 +1155,7 @@ export function discoverOpenClawPlugins(params: {
11311155
discoverInDirectory({
11321156
dir: sourceCheckoutExtensionsDir,
11331157
origin: "bundled",
1158+
env,
11341159
ownershipUid: params.ownershipUid,
11351160
candidates: result.candidates,
11361161
diagnostics: result.diagnostics,
@@ -1157,6 +1182,7 @@ export function discoverOpenClawPlugins(params: {
11571182
discoverInDirectory({
11581183
dir: roots.global,
11591184
origin: "global",
1185+
env,
11601186
ownershipUid: params.ownershipUid,
11611187
candidates: result.candidates,
11621188
diagnostics: result.diagnostics,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, expect, it } from "vitest";
2+
import { isNixStorePluginRoot, shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
3+
4+
const nixEnv: NodeJS.ProcessEnv = { OPENCLAW_NIX_MODE: "1" };
5+
6+
describe("plugin hardlink policy", () => {
7+
it("does not reject bundled plugin files", () => {
8+
expect(
9+
shouldRejectHardlinkedPluginFiles({
10+
origin: "bundled",
11+
rootDir: "/tmp/plugin",
12+
env: {},
13+
}),
14+
).toBe(false);
15+
});
16+
17+
it("rejects hardlinked external plugin files by default", () => {
18+
expect(
19+
shouldRejectHardlinkedPluginFiles({
20+
origin: "config",
21+
rootDir: "/tmp/plugin",
22+
env: {},
23+
}),
24+
).toBe(true);
25+
});
26+
27+
it("does not treat OPENCLAW_NIX_MODE as enough by itself", () => {
28+
expect(
29+
shouldRejectHardlinkedPluginFiles({
30+
origin: "config",
31+
rootDir: "/tmp/plugin",
32+
env: nixEnv,
33+
}),
34+
).toBe(true);
35+
});
36+
37+
it.runIf(process.platform !== "win32")(
38+
"does not reject hardlinked external plugin files when Nix mode loads from the Nix store",
39+
() => {
40+
expect(isNixStorePluginRoot("/nix/store/abc-openclaw-plugin")).toBe(true);
41+
expect(isNixStorePluginRoot("/tmp/nix/store/abc-openclaw-plugin")).toBe(false);
42+
expect(
43+
shouldRejectHardlinkedPluginFiles({
44+
origin: "config",
45+
rootDir: "/nix/store/abc-openclaw-plugin",
46+
env: nixEnv,
47+
}),
48+
).toBe(false);
49+
},
50+
);
51+
});

‎src/plugins/hardlink-policy.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import path from "node:path";
2+
import { resolveIsNixMode } from "../config/paths.js";
3+
import { safeRealpathSync } from "./path-safety.js";
4+
import type { PluginOrigin } from "./plugin-origin.types.js";
5+
6+
const NIX_STORE_ROOT = "/nix/store";
7+
8+
// Hardlinks are rejected for user/config/workspace plugin roots by default. A
9+
// hardlinked file can appear to live under a plugin root while sharing an inode
10+
// with a file created elsewhere, which weakens the root-boundary checks used
11+
// before loading plugin code.
12+
//
13+
// Two roots are allowed:
14+
// - bundled: plugins shipped with OpenClaw itself, not user-installed code.
15+
// - /nix/store in OPENCLAW_NIX_MODE: immutable Nix package outputs, where
16+
// hardlinked files are normal package-store layout rather than user mutation.
17+
export function isNixStorePluginRoot(
18+
rootDir: string,
19+
realpathCache?: Map<string, string>,
20+
): boolean {
21+
const rootRealPath = safeRealpathSync(rootDir, realpathCache) ?? path.resolve(rootDir);
22+
return rootRealPath === NIX_STORE_ROOT || rootRealPath.startsWith(`${NIX_STORE_ROOT}/`);
23+
}
24+
25+
export function shouldRejectHardlinkedPluginFiles(params: {
26+
origin: PluginOrigin;
27+
rootDir: string;
28+
env?: NodeJS.ProcessEnv;
29+
realpathCache?: Map<string, string>;
30+
}): boolean {
31+
if (params.origin === "bundled") {
32+
return false;
33+
}
34+
if (resolveIsNixMode(params.env) && isNixStorePluginRoot(params.rootDir, params.realpathCache)) {
35+
return false;
36+
}
37+
return true;
38+
}

‎src/plugins/loader.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from "./config-state.js";
5050
import { isPluginEnabledByDefaultForPlatform } from "./default-enablement.js";
5151
import { discoverOpenClawPlugins, type PluginCandidate } from "./discovery.js";
52+
import { shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
5253
import { getGlobalHookRunner, initializeGlobalHookRunner } from "./hook-runner-global.js";
5354
import { toSafeImportPath } from "./import-specifier.js";
5455
import { collectPluginManifestCompatCodes } from "./installed-plugin-index-record-builder.js";
@@ -2002,11 +2003,16 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
20022003
: runtimeCandidateEntry;
20032004
const moduleLoadSource = resolveCanonicalDistRuntimeSource(loadEntry.source);
20042005
const moduleRoot = resolveCanonicalDistRuntimeSource(loadEntry.rootDir);
2006+
const rejectHardlinks = shouldRejectHardlinkedPluginFiles({
2007+
origin: candidate.origin,
2008+
rootDir: candidate.rootDir,
2009+
env,
2010+
});
20052011
const opened = openRootFileSync({
20062012
absolutePath: moduleLoadSource,
20072013
rootPath: moduleRoot,
20082014
boundaryLabel: "plugin root",
2009-
rejectHardlinks: candidate.origin !== "bundled",
2015+
rejectHardlinks,
20102016
skipLexicalRootCheck: true,
20112017
});
20122018
if (!opened.ok) {
@@ -2097,7 +2103,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
20972103
absolutePath: runtimeModuleSource,
20982104
rootPath: runtimeModuleRoot,
20992105
boundaryLabel: "plugin root",
2100-
rejectHardlinks: candidate.origin !== "bundled",
2106+
rejectHardlinks,
21012107
skipLexicalRootCheck: true,
21022108
});
21032109
if (!runtimeOpened.ok) {
@@ -2678,7 +2684,11 @@ export async function loadOpenClawPluginCliRegistry(
26782684
absolutePath: sourceForCliMetadata,
26792685
rootPath: pluginRoot,
26802686
boundaryLabel: "plugin root",
2681-
rejectHardlinks: candidate.origin !== "bundled",
2687+
rejectHardlinks: shouldRejectHardlinkedPluginFiles({
2688+
origin: candidate.origin,
2689+
rootDir: candidate.rootDir,
2690+
env,
2691+
}),
26822692
skipLexicalRootCheck: true,
26832693
});
26842694
if (!opened.ok) {

‎src/plugins/manifest-registry.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,31 @@ describe("loadPluginManifestRegistry", () => {
22272227
expectUnsafeWorkspaceManifestRejected({ id: "unsafe-hardlink", mode: "hardlink" });
22282228
});
22292229

2230+
it("still rejects config manifest hardlinks outside the Nix store in Nix mode", () => {
2231+
if (process.platform === "win32") {
2232+
return;
2233+
}
2234+
const fixture = prepareLinkedManifestFixture({
2235+
id: "unsafe-config-hardlink",
2236+
mode: "hardlink",
2237+
});
2238+
if (!fixture.linked) {
2239+
return;
2240+
}
2241+
const registry = loadPluginManifestRegistry({
2242+
env: hermeticEnv({ OPENCLAW_NIX_MODE: "1" }),
2243+
candidates: [
2244+
createPluginCandidate({
2245+
idHint: "unsafe-config-hardlink",
2246+
rootDir: fixture.rootDir,
2247+
origin: "config",
2248+
}),
2249+
],
2250+
});
2251+
expect(registry.plugins).toHaveLength(0);
2252+
expect(hasUnsafeManifestDiagnostic(registry)).toBe(true);
2253+
});
2254+
22302255
it("allows bundled manifest paths that are hardlinked aliases", () => {
22312256
if (process.platform === "win32") {
22322257
return;

‎src/plugins/manifest-registry.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { resolveCompatibilityHostVersion } from "../version.js";
1111
import { loadBundleManifest } from "./bundle-manifest.js";
1212
import { normalizePluginsConfigWithResolver } from "./config-policy.js";
1313
import { discoverOpenClawPlugins, type PluginCandidate } from "./discovery.js";
14+
import { shouldRejectHardlinkedPluginFiles } from "./hardlink-policy.js";
1415
import { loadInstalledPluginIndexInstallRecordsSync } from "./installed-plugin-index-record-reader.js";
1516
import type { PluginManifestCommandAlias } from "./manifest-command-aliases.js";
1617
import type {
@@ -843,7 +844,12 @@ export function loadPluginManifestRegistry(
843844
const currentHostVersion = resolveCompatibilityHostVersion(env);
844845

845846
for (const candidate of candidates) {
846-
const rejectHardlinks = candidate.origin !== "bundled";
847+
const rejectHardlinks = shouldRejectHardlinkedPluginFiles({
848+
origin: candidate.origin,
849+
rootDir: candidate.rootDir,
850+
env,
851+
realpathCache,
852+
});
847853
const isBundleRecord = (candidate.format ?? "openclaw") === "bundle";
848854
const manifestRes:
849855
| ReturnType<typeof loadPluginManifest>

0 commit comments

Comments
 (0)