Skip to content

Commit 2e54fe7

Browse files
authored
refactor(plugins): deduplicate install security scan contracts (#129272)
1 parent 750a64e commit 2e54fe7

2 files changed

Lines changed: 37 additions & 131 deletions

File tree

‎src/plugins/install-security-scan.runtime.ts‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import {
1717
import { isPathInside } from "../security/scan-paths.js";
1818
import { getGlobalHookRunner } from "./hook-runner-global.js";
1919
import { createBeforeInstallHookPayload } from "./install-policy-context.js";
20+
import type {
21+
InstallSecurityScanResult,
22+
SkillInstallSpecMetadata,
23+
} from "./install-security-scan.js";
2024
import type {
2125
InstallPolicyWarningDetails,
2226
InstallSafetyOverrides,
@@ -92,30 +96,6 @@ type InstalledPackageScanRoot = {
9296
realPath: string;
9397
};
9498

95-
type SkillInstallSpec = {
96-
id?: string;
97-
kind: "brew" | "node" | "go" | "uv" | "download";
98-
label?: string;
99-
bins?: string[];
100-
os?: string[];
101-
formula?: string;
102-
package?: string;
103-
module?: string;
104-
url?: string;
105-
archive?: string;
106-
extract?: boolean;
107-
stripComponents?: number;
108-
targetDir?: string;
109-
};
110-
111-
export type InstallSecurityScanResult = {
112-
blocked?: {
113-
code?: "security_scan_blocked" | "security_scan_failed";
114-
reason: string;
115-
installPolicyWarning?: InstallPolicyWarningDetails;
116-
};
117-
};
118-
11999
function failOversizedInstallPolicyWarning(params: {
120100
result: Awaited<ReturnType<typeof runInstallPolicy>>;
121101
targetName: string;
@@ -582,7 +562,7 @@ async function runBeforeInstallHook(params: {
582562
requestedSpecifier?: string;
583563
skill?: {
584564
installId: string;
585-
installSpec?: SkillInstallSpec;
565+
installSpec?: SkillInstallSpecMetadata;
586566
};
587567
plugin?: {
588568
contentType: "bundle" | "package" | "file";
@@ -733,7 +713,7 @@ async function runOperatorInstallPolicy(params: {
733713
requestedSpecifier?: string;
734714
skill?: {
735715
installId: string;
736-
installSpec?: SkillInstallSpec;
716+
installSpec?: SkillInstallSpecMetadata;
737717
};
738718
plugin?: {
739719
contentType: "bundle" | "package" | "file" | "dependency-tree";
@@ -1246,7 +1226,7 @@ export async function preflightPluginGitInstallPolicyRuntime(params: {
12461226
export async function evaluateSkillInstallPolicyRuntime(params: {
12471227
config?: OpenClawConfig;
12481228
installId: string;
1249-
installSpec?: SkillInstallSpec;
1229+
installSpec?: SkillInstallSpecMetadata;
12501230
logger: InstallScanLogger;
12511231
mode?: "install" | "update";
12521232
onInstallPolicyWarning?: InstallSafetyOverrides["onInstallPolicyWarning"];
Lines changed: 30 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
// Runs security checks over plugin install candidates before activation.
2-
import type { OpenClawConfig } from "../config/types.openclaw.js";
3-
import type {
4-
InstallPolicyOrigin,
5-
InstallPolicyRequestKind,
6-
InstallPolicySource,
7-
} from "../security/install-policy.js";
8-
import type {
9-
InstallPolicyWarningDetails,
10-
InstallSafetyOverrides,
11-
} from "./install-security-scan.types.js";
2+
import type { InstallPolicyWarningDetails } from "./install-security-scan.types.js";
123
export type { InstallSafetyOverrides } from "./install-security-scan.types.js";
134

14-
type InstallScanLogger = {
15-
warn?: (message: string) => void;
16-
};
17-
185
/** Result returned by plugin/skill install security policy checks. */
196
export type InstallSecurityScanResult = {
207
blocked?: {
@@ -24,9 +11,6 @@ export type InstallSecurityScanResult = {
2411
};
2512
};
2613

27-
/** Plugin install request kinds that share install policy without skill install semantics. */
28-
type PluginInstallRequestKind = Exclude<InstallPolicyRequestKind, "skill-install">;
29-
3014
/** Skill install metadata shape passed into shared install policy evaluation. */
3115
export type SkillInstallSpecMetadata = {
3216
id?: string;
@@ -51,60 +35,30 @@ async function loadInstallSecurityScanRuntime() {
5135

5236
/** Scans an unpacked bundle source before plugin install/update. */
5337
export async function scanBundleInstallSource(
54-
params: InstallSafetyOverrides & {
55-
config?: OpenClawConfig;
56-
logger: InstallScanLogger;
57-
pluginId: string;
58-
sourceDir: string;
59-
requestKind?: PluginInstallRequestKind;
60-
requestedSpecifier?: string;
61-
mode?: "install" | "update";
62-
version?: string;
63-
source?: InstallPolicySource;
64-
},
38+
params: Parameters<
39+
typeof import("./install-security-scan.runtime.js").scanBundleInstallSourceRuntime
40+
>[0],
6541
): Promise<InstallSecurityScanResult | undefined> {
6642
const { scanBundleInstallSourceRuntime } = await loadInstallSecurityScanRuntime();
6743
return await scanBundleInstallSourceRuntime(params);
6844
}
6945

7046
/** Scans a package source directory and executable metadata before install/update. */
7147
export async function scanPackageInstallSource(
72-
params: InstallSafetyOverrides & {
73-
config?: OpenClawConfig;
74-
extensions: string[];
75-
logger: InstallScanLogger;
76-
packageDir: string;
77-
pluginId: string;
78-
requestKind?: PluginInstallRequestKind;
79-
requestedSpecifier?: string;
80-
mode?: "install" | "update";
81-
packageName?: string;
82-
manifestId?: string;
83-
version?: string;
84-
source?: InstallPolicySource;
85-
trustedSourceLinkedOfficialInstall?: boolean;
86-
},
48+
params: Parameters<
49+
typeof import("./install-security-scan.runtime.js").scanPackageInstallSourceRuntime
50+
>[0],
8751
): Promise<InstallSecurityScanResult | undefined> {
8852
const { scanPackageInstallSourceRuntime } = await loadInstallSecurityScanRuntime();
8953
return await scanPackageInstallSourceRuntime(params);
9054
}
9155

9256
/** Scans the installed package dependency tree after npm resolution. */
93-
export async function scanInstalledPackageDependencyTree(params: {
94-
additionalPackageDirs?: string[];
95-
allowManagedNpmRootPackagePeerSymlinks?: boolean;
96-
config?: OpenClawConfig;
97-
dependencyScanRootDir?: string;
98-
logger: InstallScanLogger;
99-
mode?: "install" | "update";
100-
onInstallPolicyWarning?: InstallSafetyOverrides["onInstallPolicyWarning"];
101-
packageDir: string;
102-
pluginId: string;
103-
requestKind?: PluginInstallRequestKind;
104-
requestedSpecifier?: string;
105-
source?: InstallPolicySource;
106-
trustedSourceLinkedOfficialInstall?: boolean;
107-
}): Promise<InstallSecurityScanResult | undefined> {
57+
export async function scanInstalledPackageDependencyTree(
58+
params: Parameters<
59+
typeof import("./install-security-scan.runtime.js").scanInstalledPackageDependencyTreeRuntime
60+
>[0],
61+
): Promise<InstallSecurityScanResult | undefined> {
10862
const { scanInstalledPackageDependencyTreeRuntime } = await loadInstallSecurityScanRuntime();
10963
return await scanInstalledPackageDependencyTreeRuntime(params);
11064
}
@@ -114,68 +68,40 @@ export async function scanInstalledPackageDependencyTree(params: {
11468
* Remove only with the matching runtime-postbuild legacy alias cleanup.
11569
*/
11670
export async function scanFileInstallSource(
117-
params: InstallSafetyOverrides & {
118-
config?: OpenClawConfig;
119-
filePath: string;
120-
logger: InstallScanLogger;
121-
mode?: "install" | "update";
122-
pluginId: string;
123-
requestedSpecifier?: string;
124-
source?: InstallPolicySource;
125-
},
71+
params: Parameters<
72+
typeof import("./install-security-scan.runtime.js").scanFileInstallSourceRuntime
73+
>[0],
12674
): Promise<InstallSecurityScanResult | undefined> {
12775
const { scanFileInstallSourceRuntime } = await loadInstallSecurityScanRuntime();
12876
return await scanFileInstallSourceRuntime(params);
12977
}
13078

13179
/** Runs npm install policy checks before package install side effects. */
132-
export async function preflightPluginNpmInstallPolicy(params: {
133-
config?: OpenClawConfig;
134-
dangerouslyForceUnsafeInstall?: boolean;
135-
logger: InstallScanLogger;
136-
mode?: "install" | "update";
137-
onInstallPolicyWarning?: InstallSafetyOverrides["onInstallPolicyWarning"];
138-
packageName: string;
139-
pluginId?: string;
140-
requestedSpecifier?: string;
141-
source?: InstallPolicySource;
142-
sourcePath: string;
143-
sourcePathKind: "file" | "directory";
144-
}): Promise<InstallSecurityScanResult | undefined> {
80+
export async function preflightPluginNpmInstallPolicy(
81+
params: Parameters<
82+
typeof import("./install-security-scan.runtime.js").preflightPluginNpmInstallPolicyRuntime
83+
>[0],
84+
): Promise<InstallSecurityScanResult | undefined> {
14585
const { preflightPluginNpmInstallPolicyRuntime } = await loadInstallSecurityScanRuntime();
14686
return await preflightPluginNpmInstallPolicyRuntime(params);
14787
}
14888

14989
/** Runs git install policy checks before plugin install side effects. */
150-
export async function preflightPluginGitInstallPolicy(params: {
151-
config?: OpenClawConfig;
152-
dangerouslyForceUnsafeInstall?: boolean;
153-
logger: InstallScanLogger;
154-
mode?: "install" | "update";
155-
onInstallPolicyWarning?: InstallSafetyOverrides["onInstallPolicyWarning"];
156-
pluginId: string;
157-
requestedSpecifier?: string;
158-
source?: InstallPolicySource;
159-
sourcePath: string;
160-
}): Promise<InstallSecurityScanResult | undefined> {
90+
export async function preflightPluginGitInstallPolicy(
91+
params: Parameters<
92+
typeof import("./install-security-scan.runtime.js").preflightPluginGitInstallPolicyRuntime
93+
>[0],
94+
): Promise<InstallSecurityScanResult | undefined> {
16195
const { preflightPluginGitInstallPolicyRuntime } = await loadInstallSecurityScanRuntime();
16296
return await preflightPluginGitInstallPolicyRuntime(params);
16397
}
16498

16599
/** Evaluates shared install policy for skill-managed dependency installs. */
166-
export async function evaluateSkillInstallPolicy(params: {
167-
config?: OpenClawConfig;
168-
installId: string;
169-
installSpec?: SkillInstallSpecMetadata;
170-
logger: InstallScanLogger;
171-
mode?: "install" | "update";
172-
onInstallPolicyWarning?: InstallSafetyOverrides["onInstallPolicyWarning"];
173-
origin: InstallPolicyOrigin;
174-
requestedSpecifier?: string;
175-
source?: InstallPolicySource;
176-
skillName: string;
177-
sourceDir: string;
178-
}): Promise<InstallSecurityScanResult | undefined> {
100+
export async function evaluateSkillInstallPolicy(
101+
params: Parameters<
102+
typeof import("./install-security-scan.runtime.js").evaluateSkillInstallPolicyRuntime
103+
>[0],
104+
): Promise<InstallSecurityScanResult | undefined> {
179105
const { evaluateSkillInstallPolicyRuntime } = await loadInstallSecurityScanRuntime();
180106
return await evaluateSkillInstallPolicyRuntime(params);
181107
}

0 commit comments

Comments
 (0)