Skip to content

Commit 76055dd

Browse files
authored
Merge pull request #18 from decksoftware/fix/self-scan-ignore-ruledefs
fix(detector): self-scan hygiene — .csreview-ignore for csreview's own rule definitions
2 parents ea9b20f + daef71c commit 76055dd

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

.csreview-ignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CSReview self-scan hygiene (read-only; report-level suppression).
2+
#
3+
# Mirrors csreview/.csreview-ignore so a self-audit is clean whether the scan root
4+
# is the repo root or the package dir. These files DEFINE the security rules and
5+
# remediation content (regex literals, rule names, descriptions, exploitation
6+
# examples, the DB-dump guide's sample connection strings); the heuristic detector
7+
# matches its own definitions when scanning csreview itself. Logic bugs are still
8+
# covered by Semgrep + CodeQL in CI.
9+
**/src/detector.js
10+
**/src/dumpGuide.js

csreview/.csreview-ignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CSReview self-scan hygiene (read-only; report-level suppression).
2+
#
3+
# These files DEFINE the security rules and remediation content: regex literals,
4+
# rule names, descriptions, exploitation examples, and the DB-dump guide's sample
5+
# connection strings. When CSReview audits its OWN source, the heuristic detector
6+
# matches its own definitions — a scanner flagging its own rulebook. That noise is
7+
# specific to scanning csreview itself and never occurs in a user's project. Logic
8+
# bugs in these files are still covered by Semgrep + CodeQL in CI.
9+
#
10+
# `**/`-prefixed so it works whether the scan root is the package dir (src/...) or
11+
# the repo root (csreview/src/...).
12+
**/src/detector.js
13+
**/src/dumpGuide.js

csreview/test/detector-calibration.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import assert from 'node:assert/strict';
44
import fs from 'node:fs';
55
import os from 'node:os';
66
import path from 'node:path';
7+
import { fileURLToPath } from 'node:url';
78
import { detectVulnerabilities } from '../src/detector.js';
9+
import { runAnalysis } from '../src/index.js';
810

911
// Calibration guards driven by real user feedback: the internal detector was
1012
// "shouting fire because it saw the word match in the dictionary" — WEAK_CIPHER
@@ -84,3 +86,20 @@ test('findings in non-source paths (test/fixtures) are downgraded; real source k
8486
assert.equal(inTest.severity, 'LOW', 'test/fixture finding is downgraded to LOW');
8587
assert.equal(inTest.confidence, 'LOW');
8688
});
89+
90+
test('the shipped .csreview-ignore keeps a csreview self-audit free of rule-definition meta-FPs', async () => {
91+
// A scanner must not flag its own rulebook: detector.js (regexes/descriptions/
92+
// exploitation strings) and dumpGuide.js (sample connection strings) match the
93+
// detector's own definitions only when csreview audits itself. The shipped
94+
// .csreview-ignore suppresses them. (Reported by Thiago via GPT.)
95+
const pkgRoot = fileURLToPath(new URL('..', import.meta.url));
96+
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'csreview-selfscan-'));
97+
const result = await runAnalysis(pkgRoot, { outputDir: out, runTools: false });
98+
const ruleDefHits = result.findings.filter((f) => /src[\\/](?:detector|dumpGuide)\.js/.test(String(f.file)));
99+
assert.equal(
100+
ruleDefHits.length,
101+
0,
102+
`rule-definition files must be suppressed, got: ${ruleDefHits.map((f) => `${f.file}:${f.line}`).join(', ')}`,
103+
);
104+
assert.ok(result.suppressedByIgnore > 0, 'expected the .csreview-ignore to suppress the rule-definition meta-FPs');
105+
});

0 commit comments

Comments
 (0)