@contextfort-ai/openclaw-secure 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -83,6 +83,7 @@ module.exports = function createSkillsGuard({ readFileSync, httpsRequest, baseDi
|
|
|
83
83
|
|
|
84
84
|
function readSkillFiles(skillPath) {
|
|
85
85
|
const files = [];
|
|
86
|
+
const binaryFiles = [];
|
|
86
87
|
const MAX_FILE_SIZE = 1 * 1024 * 1024; // 1MB
|
|
87
88
|
const MAX_TOTAL_SIZE = 5 * 1024 * 1024; // 5MB
|
|
88
89
|
let totalSize = 0;
|
|
@@ -91,7 +92,7 @@ module.exports = function createSkillsGuard({ readFileSync, httpsRequest, baseDi
|
|
|
91
92
|
let entries;
|
|
92
93
|
try { entries = fs.readdirSync(dirPath, { withFileTypes: true }); } catch { return; }
|
|
93
94
|
for (const e of entries) {
|
|
94
|
-
if (e.name.startsWith('.')) continue; // skip hidden
|
|
95
|
+
if (e.name.startsWith('.') || e.name === 'node_modules') continue; // skip hidden and node_modules
|
|
95
96
|
const full = path.join(dirPath, e.name);
|
|
96
97
|
if (e.isDirectory()) {
|
|
97
98
|
walk(full, path.join(base, e.name));
|
|
@@ -100,11 +101,14 @@ module.exports = function createSkillsGuard({ readFileSync, httpsRequest, baseDi
|
|
|
100
101
|
const stat = fs.statSync(full);
|
|
101
102
|
if (stat.size > MAX_FILE_SIZE || stat.size === 0) continue;
|
|
102
103
|
if (totalSize + stat.size > MAX_TOTAL_SIZE) continue;
|
|
103
|
-
//
|
|
104
|
+
// Check for binaries: read first 512 bytes and check for null bytes
|
|
104
105
|
const buf = Buffer.alloc(Math.min(512, stat.size));
|
|
105
106
|
const fd = fs.openSync(full, 'r');
|
|
106
107
|
try { fs.readSync(fd, buf, 0, buf.length, 0); } finally { fs.closeSync(fd); }
|
|
107
|
-
if (buf.includes(0))
|
|
108
|
+
if (buf.includes(0)) {
|
|
109
|
+
binaryFiles.push(path.join(base, e.name));
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
108
112
|
|
|
109
113
|
const content = readFileSync(full, 'utf8');
|
|
110
114
|
totalSize += stat.size;
|
|
@@ -114,7 +118,7 @@ module.exports = function createSkillsGuard({ readFileSync, httpsRequest, baseDi
|
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
walk(skillPath, '');
|
|
117
|
-
return files;
|
|
121
|
+
return { files, binaryFiles };
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
function hashSkillFiles(files) {
|
|
@@ -219,14 +223,26 @@ module.exports = function createSkillsGuard({ readFileSync, httpsRequest, baseDi
|
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
function scanSkillIfChanged(skillPath) {
|
|
222
|
-
const files = readSkillFiles(skillPath);
|
|
223
|
-
if (files.length === 0) {
|
|
226
|
+
const { files, binaryFiles } = readSkillFiles(skillPath);
|
|
227
|
+
if (files.length === 0 && binaryFiles.length === 0) {
|
|
224
228
|
// Skill was deleted or is empty — remove from flagged
|
|
225
229
|
flaggedSkills.delete(skillPath);
|
|
226
230
|
skillContentHashes.delete(skillPath);
|
|
227
231
|
saveScanCache();
|
|
228
232
|
return;
|
|
229
233
|
}
|
|
234
|
+
|
|
235
|
+
// Flag immediately if binary files found — legitimate skills should not contain binaries
|
|
236
|
+
if (binaryFiles.length > 0) {
|
|
237
|
+
flaggedSkills.set(skillPath, {
|
|
238
|
+
suspicious: true,
|
|
239
|
+
reason: `Skill contains binary files (${binaryFiles.join(', ')}). Legitimate skills should only contain text files. Please delete these binary files or remove this skill.`,
|
|
240
|
+
});
|
|
241
|
+
track('skill_binary_detected', { skill_name: path.basename(skillPath), binary_count: binaryFiles.length });
|
|
242
|
+
saveScanCache();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
230
246
|
const hash = hashSkillFiles(files);
|
|
231
247
|
if (skillContentHashes.get(skillPath) === hash) return; // unchanged
|
|
232
248
|
|
package/package.json
CHANGED