@cachly-dev/audit-rules 0.0.0-stage → 0.1.0
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/LICENSE +181 -0
- package/README.md +175 -2
- package/action.yml +59 -0
- package/bin/audit-rules.mjs +185 -0
- package/examples/vulnerable-demo/.cursorrules +12 -0
- package/examples/vulnerable-demo/CLAUDE.md +18 -0
- package/package.json +49 -4
- package/src/formatters.mjs +183 -0
- package/src/rules.mjs +619 -0
- package/src/scanner.mjs +209 -0
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cachly-dev/audit-rules",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local zero-network security & hygiene scanner for AI coding rule files (CLAUDE.md, .cursorrules, AGENTS.md, SKILL.md, copilot-instructions.md). Detects leaked secrets, prompt injections, invisible Unicode backdoors, rule bloat, and dead paths.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Heinrich Neb <hello@cachly.dev>",
|
|
8
|
+
"homepage": "https://cachly.dev",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/cachly-dev/agent-rules-audit.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"claude-code",
|
|
15
|
+
"cursor",
|
|
16
|
+
"cursorrules",
|
|
17
|
+
"claude-md",
|
|
18
|
+
"agents-md",
|
|
19
|
+
"skill-md",
|
|
20
|
+
"prompt-injection",
|
|
21
|
+
"secret-scanner",
|
|
22
|
+
"unicode-backdoor",
|
|
23
|
+
"sarif",
|
|
24
|
+
"security",
|
|
25
|
+
"ai-coding",
|
|
26
|
+
"mcp"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.0.0"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"audit-rules": "./bin/audit-rules.mjs"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./src/scanner.mjs",
|
|
36
|
+
"./rules": "./src/rules.mjs",
|
|
37
|
+
"./formatters": "./src/formatters.mjs"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"bin/",
|
|
41
|
+
"src/",
|
|
42
|
+
"examples/",
|
|
43
|
+
"action.yml",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "node --test test/audit.test.mjs",
|
|
49
|
+
"demo": "node bin/audit-rules.mjs --demo"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { RULE_CATALOG } from "./rules.mjs";
|
|
2
|
+
|
|
3
|
+
const ANSI = {
|
|
4
|
+
reset: "\x1b[0m",
|
|
5
|
+
bold: "\x1b[1m",
|
|
6
|
+
dim: "\x1b[2m",
|
|
7
|
+
red: "\x1b[31m",
|
|
8
|
+
yellow: "\x1b[33m",
|
|
9
|
+
green: "\x1b[32m",
|
|
10
|
+
cyan: "\x1b[36m",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function paint(text, code, enabled) {
|
|
14
|
+
return enabled ? `${code}${text}${ANSI.reset}` : text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Crisp, screenshot-friendly terminal output.
|
|
19
|
+
*/
|
|
20
|
+
export function formatTerminal(report, { color = true, promo = true } = {}) {
|
|
21
|
+
const lines = [];
|
|
22
|
+
const header = `${report.tool} v${report.version} · scanned ${report.summary.filesScanned} rule file${
|
|
23
|
+
report.summary.filesScanned === 1 ? "" : "s"
|
|
24
|
+
} (0 network calls)`;
|
|
25
|
+
|
|
26
|
+
lines.push(paint(header, ANSI.bold, color));
|
|
27
|
+
lines.push("");
|
|
28
|
+
|
|
29
|
+
if (report.summary.filesScanned === 0) {
|
|
30
|
+
lines.push(
|
|
31
|
+
paint(
|
|
32
|
+
" No AI rule files found (checked CLAUDE.md, .cursorrules, AGENTS.md, SKILL.md, copilot-instructions.md, etc.).",
|
|
33
|
+
ANSI.dim,
|
|
34
|
+
color
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
lines.push("");
|
|
38
|
+
lines.push(
|
|
39
|
+
paint(`Summary: 0 errors, 0 warnings (${report.summary.durationMs} ms)`, ANSI.green, color)
|
|
40
|
+
);
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (report.findings.length === 0) {
|
|
45
|
+
lines.push(paint(" PASS No secrets, prompt injections, or hygiene issues found.", ANSI.green, color));
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push(
|
|
48
|
+
paint(
|
|
49
|
+
`Summary: 0 errors, 0 warnings (${report.summary.durationMs} ms)`,
|
|
50
|
+
ANSI.bold,
|
|
51
|
+
color
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
return lines.join("\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const finding of report.findings) {
|
|
58
|
+
const badge =
|
|
59
|
+
finding.severity === "error"
|
|
60
|
+
? paint("ERROR", ANSI.red, color)
|
|
61
|
+
: finding.severity === "warn"
|
|
62
|
+
? paint("WARN ", ANSI.yellow, color)
|
|
63
|
+
: paint("INFO ", ANSI.cyan, color);
|
|
64
|
+
|
|
65
|
+
const ruleTag = paint(finding.ruleId, ANSI.bold, color);
|
|
66
|
+
const loc = paint(`${finding.file}:${finding.line}`, ANSI.cyan, color);
|
|
67
|
+
|
|
68
|
+
lines.push(` ${badge} ${ruleTag} ${loc}`);
|
|
69
|
+
lines.push(` ${finding.message}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
lines.push("");
|
|
73
|
+
const summaryText = `Summary: ${report.summary.errors} error${
|
|
74
|
+
report.summary.errors === 1 ? "" : "s"
|
|
75
|
+
}, ${report.summary.warnings} warning${
|
|
76
|
+
report.summary.warnings === 1 ? "" : "s"
|
|
77
|
+
} (${report.summary.durationMs} ms)`;
|
|
78
|
+
lines.push(paint(summaryText, ANSI.bold, color));
|
|
79
|
+
|
|
80
|
+
if (promo && report.findings.length > 0) {
|
|
81
|
+
lines.push(
|
|
82
|
+
paint(
|
|
83
|
+
"cachly shares team rules across Claude Code, Cursor and JetBrains: https://cachly.dev (hide this line with --no-promo)",
|
|
84
|
+
ANSI.dim,
|
|
85
|
+
color
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return lines.join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Clean JSON output for scripts and CI pipelines (no promotional footer).
|
|
95
|
+
*/
|
|
96
|
+
export function formatJson(report) {
|
|
97
|
+
return JSON.stringify(report, null, 2);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* SARIF 2.1.0 output compatible with GitHub Code Scanning (Security tab).
|
|
102
|
+
*/
|
|
103
|
+
export function formatSarif(report) {
|
|
104
|
+
const sarifLevel = (sev) => (sev === "error" ? "error" : sev === "warn" ? "warning" : "note");
|
|
105
|
+
|
|
106
|
+
const rules = Object.values(RULE_CATALOG).map((rule) => ({
|
|
107
|
+
id: rule.id,
|
|
108
|
+
name: rule.name,
|
|
109
|
+
shortDescription: { text: rule.name },
|
|
110
|
+
fullDescription: { text: rule.description },
|
|
111
|
+
help: { text: rule.help },
|
|
112
|
+
defaultConfiguration: { level: sarifLevel(rule.severity) },
|
|
113
|
+
properties: {
|
|
114
|
+
category: rule.category,
|
|
115
|
+
tags: ["security", "ai-rules", rule.category, rule.cwe],
|
|
116
|
+
},
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
const results = report.findings.map((f) => ({
|
|
120
|
+
ruleId: f.ruleId,
|
|
121
|
+
level: sarifLevel(f.severity),
|
|
122
|
+
message: { text: f.message },
|
|
123
|
+
locations: [
|
|
124
|
+
{
|
|
125
|
+
physicalLocation: {
|
|
126
|
+
artifactLocation: { uri: f.file },
|
|
127
|
+
region: { startLine: f.line || 1 },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
}));
|
|
132
|
+
|
|
133
|
+
const sarifDoc = {
|
|
134
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
135
|
+
version: "2.1.0",
|
|
136
|
+
runs: [
|
|
137
|
+
{
|
|
138
|
+
tool: {
|
|
139
|
+
driver: {
|
|
140
|
+
name: report.tool,
|
|
141
|
+
version: report.version,
|
|
142
|
+
informationUri: "https://github.com/cachly-dev/agent-rules-audit",
|
|
143
|
+
rules,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
results,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return JSON.stringify(sarifDoc, null, 2);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Markdown summary table ready to post as a GitHub Pull Request comment.
|
|
156
|
+
*/
|
|
157
|
+
export function formatMarkdown(report) {
|
|
158
|
+
const lines = [];
|
|
159
|
+
const statusIcon =
|
|
160
|
+
report.summary.errors > 0 ? "FAIL" : report.summary.warnings > 0 ? "WARN" : "PASS";
|
|
161
|
+
|
|
162
|
+
lines.push(`### AI Rules Security Audit — \`${statusIcon}\``);
|
|
163
|
+
lines.push("");
|
|
164
|
+
lines.push(
|
|
165
|
+
`Scanned **${report.summary.filesScanned}** rule file(s) locally (0 network calls, ${report.summary.durationMs} ms): **${report.summary.errors} error(s)**, **${report.summary.warnings} warning(s)**.`
|
|
166
|
+
);
|
|
167
|
+
lines.push("");
|
|
168
|
+
|
|
169
|
+
if (report.findings.length === 0) {
|
|
170
|
+
lines.push("No leaked secrets, prompt injections, invisible Unicode backdoors, or hygiene issues detected.");
|
|
171
|
+
return lines.join("\n");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
lines.push("| Severity | Rule | Location | Detail |");
|
|
175
|
+
lines.push("|---|---|---|---|");
|
|
176
|
+
|
|
177
|
+
for (const f of report.findings) {
|
|
178
|
+
const safeMsg = f.message.replace(/\|/g, "\\|");
|
|
179
|
+
lines.push(`| \`${f.severity.toUpperCase()}\` | \`${f.ruleId}\` | \`${f.file}:${f.line}\` | ${safeMsg} |`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return lines.join("\n");
|
|
183
|
+
}
|