ccsniff 1.1.14 → 1.1.16
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.
- package/package.json +1 -1
- package/src/cli.js +11 -4
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -380,6 +380,9 @@ if (opts['git-discipline']) {
|
|
|
380
380
|
if (opts['search-discipline']) {
|
|
381
381
|
const includeSubagents = opts['include-subagents'];
|
|
382
382
|
const BASH_SEARCH = /(^|[|&;]|\s)(rg|grep|find|ag|ack|fd|fgrep|egrep)\s/;
|
|
383
|
+
// A search-tool token inside a quoted string (echo/printf/node -e payloads) is text, not a shell
|
|
384
|
+
// invocation; blank quoted bodies before matching, like git-discipline strips commit-message bodies.
|
|
385
|
+
const stripQuoted = (s) => s.replace(/"(?:\\.|[^"\\])*"/g, '""').replace(/'(?:\\.|[^'\\])*'/g, "''");
|
|
383
386
|
const violations = [];
|
|
384
387
|
for (const ev of all) {
|
|
385
388
|
if (!filter(ev)) continue;
|
|
@@ -400,11 +403,15 @@ if (opts['search-discipline']) {
|
|
|
400
403
|
}
|
|
401
404
|
} else if (name === 'Bash') {
|
|
402
405
|
const cmd = ev.block?.input?.command || '';
|
|
403
|
-
|
|
406
|
+
// A search tool fed by a pipe (`<cmd> | grep ...`) is filtering another command's stdout,
|
|
407
|
+
// not searching the codebase tree — codesearch has no equivalent for that and it is not the
|
|
408
|
+
// bypass the rule targets. Flag only a search tool that STARTS a pipeline segment (reads the
|
|
409
|
+
// tree directly), never one immediately downstream of a pipe.
|
|
410
|
+
const isTreeSearchLine = (line) => BASH_SEARCH.test(stripQuoted(line).split('|')[0]);
|
|
411
|
+
const hitLine = cmd.split('\n').find(isTreeSearchLine);
|
|
412
|
+
if (hitLine) {
|
|
404
413
|
kind = 'native-search-bash';
|
|
405
|
-
|
|
406
|
-
const hit = cmd.split('\n').find(l => BASH_SEARCH.test(l)) || cmd;
|
|
407
|
-
detail = hit.trim().slice(0, 120);
|
|
414
|
+
detail = (hitLine.split('|')[0]).trim().slice(0, 120);
|
|
408
415
|
}
|
|
409
416
|
}
|
|
410
417
|
if (kind) violations.push({ ts, sid, project, kind, detail });
|