Skip to content

Commit 847f5a1

Browse files
committed
fix(security): bound skill-file audit read via safe reader (restore removed fs dependency)
1 parent 75b1ac1 commit 847f5a1

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/security/audit-extra.async.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*
44
* These functions perform I/O (filesystem, config reads) to detect security issues.
55
*/
6-
import fs from "node:fs/promises";
76
import path from "node:path";
87
import { clearTimeout as clearNodeTimeout, setTimeout as setNodeTimeout } from "node:timers";
98
import {
@@ -99,6 +98,10 @@ function expandTilde(p: string, env: NodeJS.ProcessEnv): string | null {
9998
}
10099

101100
const MAX_PLUGIN_MANIFEST_BYTES = 1024 * 1024;
101+
// Skill file audit reads are bounded like other audit reads; matches the
102+
// workspace loader's DEFAULT_MAX_SKILL_FILE_BYTES so oversized SKILL.md files
103+
// cannot force an unbounded read during the code-safety scan.
104+
const MAX_SKILL_AUDIT_FILE_BYTES = 256_000;
102105

103106
async function readPluginManifestExtensions(pluginPath: string): Promise<string[]> {
104107
const manifestPath = path.join(pluginPath, "package.json");
@@ -194,7 +197,10 @@ async function getSkillCodeSafetySummary(params: {
194197
dirPath: params.dirPath,
195198
summaryCache: params.summaryCache,
196199
}),
197-
fs.readFile(params.skillFilePath, "utf-8"),
200+
readRegularFile({
201+
filePath: params.skillFilePath,
202+
maxBytes: MAX_SKILL_AUDIT_FILE_BYTES,
203+
}).then(({ buffer }) => buffer.toString("utf-8")),
198204
loadSkillScannerModule(),
199205
]);
200206
const skillFindings = [

0 commit comments

Comments
 (0)