openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
32 lines (31 loc) • 1.44 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import path from "node:path";
import fs from "node:fs/promises";
//#region src/security/installed-plugin-dirs.ts
const IGNORED_INSTALLED_PLUGIN_DIR_NAMES = /* @__PURE__ */ new Set(["node_modules", ".openclaw-install-backups"]);
/**
* Decide whether an installed-plugin directory should be skipped by security audits.
* This filters generated install debris while keeping real plugin roots visible to scans.
*/
function shouldIgnoreInstalledPluginDirName(e) {
const t = normalizeOptionalLowercaseString(e);
return !t || IGNORED_INSTALLED_PLUGIN_DIR_NAMES.has(t) || t.startsWith(".") || t.endsWith(".bak") || t.includes(".backup-") || t.includes(".disabled");
}
/**
* Lists installed plugin directories under the state extensions dir. Read
* failures surface through `onReadError` so audits can report scan problems,
* except a missing extensions dir, which is the normal no-plugins state.
*/
async function listInstalledPluginDirs(e) {
const t = path.join(e.stateDir, "extensions");
return {
extensionsDir: t,
pluginDirs: (await fs.readdir(t, { withFileTypes: true }).catch((t) => {
const n = t?.code;
if (n !== "ENOENT" && n !== "ENOTDIR") e.onReadError?.(t);
return [];
})).filter((e) => e.isDirectory()).map((e) => e.name).filter((e) => !shouldIgnoreInstalledPluginDirName(e))
};
}
//#endregion
export { listInstalledPluginDirs as t };