mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 14:41:35 +00:00
* fix(vault): harden secrets plan writes * fix(secrets): avoid env marker collision * style(secrets): type plan write rejection * refactor(onepassword): remove obsolete path resolver * fix(secrets): preserve Windows plan path trust * refactor(secrets): compact ACL token policy * fix(secrets): route permission checks through facade
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import path from "node:path";
|
|
import { pluginSecretRefSetup } from "openclaw/plugin-sdk/secret-ref-runtime";
|
|
|
|
function errorCode(error) {
|
|
return error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
}
|
|
|
|
export const resolveTrustedExecutablePath = pluginSecretRefSetup.resolveTrustedExecutablePath;
|
|
export const resolveTrustedOnePasswordDirectoryPath =
|
|
pluginSecretRefSetup.resolveTrustedDirectoryPath;
|
|
|
|
export async function resolveTrustedOnePasswordCli(options = {}) {
|
|
const configuredPath = options.configuredPath?.trim();
|
|
if (configuredPath && !path.isAbsolute(configuredPath)) {
|
|
throw new Error(`1Password CLI path must be absolute: ${configuredPath}`);
|
|
}
|
|
const executable = process.platform === "win32" ? "op.exe" : "op";
|
|
const candidates = configuredPath
|
|
? [configuredPath]
|
|
: (options.pathEnv ?? process.env.PATH ?? "")
|
|
.split(path.delimiter)
|
|
.filter(Boolean)
|
|
.map((directory) => path.resolve(directory, executable));
|
|
let unsafeError;
|
|
for (const candidate of candidates) {
|
|
try {
|
|
return await resolveTrustedExecutablePath(candidate);
|
|
} catch (error) {
|
|
if (errorCode(error) === "ENOENT" || errorCode(error) === "ENOTDIR") {
|
|
continue;
|
|
}
|
|
unsafeError = new Error(
|
|
`Refusing unsafe 1Password CLI path "${candidate}": ${error instanceof Error ? error.message : String(error)}`,
|
|
{ cause: error },
|
|
);
|
|
if (configuredPath) {
|
|
throw unsafeError;
|
|
}
|
|
}
|
|
}
|
|
if (unsafeError) {
|
|
throw unsafeError;
|
|
}
|
|
return undefined;
|
|
}
|