@blundergoat/gruff-ts 0.4.0 → 0.6.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/CHANGELOG.md +123 -1
- package/CONTRIBUTING.md +32 -25
- package/README.md +55 -46
- package/SECURITY.md +18 -30
- package/UPGRADING.md +101 -0
- package/bin/gruff-ts +3 -0
- package/docs/README.md +11 -13
- package/docs/agent-hook.md +33 -24
- package/docs/ci-integration.md +38 -24
- package/docs/configuration.md +173 -71
- package/docs/dashboard.md +12 -13
- package/docs/output-formats.md +100 -25
- package/docs/philosophy.md +2 -2
- package/docs/reports-and-ci.md +14 -157
- package/docs/rules.md +140 -106
- package/package.json +10 -8
- package/src/analyser.ts +886 -282
- package/src/baseline-file.ts +867 -0
- package/src/baseline-identity.ts +463 -0
- package/src/baseline-options.ts +139 -34
- package/src/baseline.ts +85 -55
- package/src/blocks.ts +579 -364
- package/src/changed-regions.ts +414 -65
- package/src/check-ignore.ts +28 -13
- package/src/class-rules.ts +461 -302
- package/src/cli-program.ts +956 -166
- package/src/cli.ts +9 -2
- package/src/comment-rules.ts +277 -414
- package/src/comment-scanner.ts +363 -44
- package/src/complexity-metrics.ts +320 -0
- package/src/config-load-error.ts +17 -8
- package/src/config-parse.ts +291 -98
- package/src/config-preservation.ts +81 -26
- package/src/config.ts +778 -210
- package/src/constants.ts +7 -6
- package/src/context-doc-rules.ts +188 -61
- package/src/dashboard.ts +88 -23
- package/src/dead-code-rules.ts +153 -74
- package/src/discovery.ts +521 -148
- package/src/doc-rules.ts +592 -147
- package/src/duplicate-test-group-rules.ts +359 -0
- package/src/findings-helpers.ts +240 -89
- package/src/findings.ts +48 -24
- package/src/fixture-purpose-rules.ts +226 -48
- package/src/github-actions-event-guards.ts +331 -0
- package/src/github-actions-rules.ts +336 -106
- package/src/hook-contract.ts +708 -211
- package/src/init-config.ts +169 -114
- package/src/inline-suppressions.ts +340 -0
- package/src/limit-band.ts +56 -0
- package/src/line-rules.ts +331 -419
- package/src/migrate-config.ts +670 -0
- package/src/naming-pushers.ts +33 -107
- package/src/parsed-script.ts +1206 -0
- package/src/pillar-summary.ts +56 -40
- package/src/profiles.ts +97 -71
- package/src/project-config-rules.ts +335 -146
- package/src/project-rules.ts +237 -115
- package/src/public-exports.ts +284 -0
- package/src/report-html.ts +217 -85
- package/src/report-renderers.ts +864 -195
- package/src/rule-list.ts +166 -46
- package/src/rules.ts +100 -104
- package/src/safety-rules.ts +191 -132
- package/src/scoring.ts +255 -52
- package/src/security-flow-rules.ts +930 -109
- package/src/selectors.ts +169 -0
- package/src/sensitive-data-rules.ts +502 -375
- package/src/sensitive-exclusions.ts +435 -0
- package/src/source-text.ts +380 -148
- package/src/static-analysis-redundant-rules.ts +298 -41
- package/src/test-block-rules.ts +422 -228
- package/src/text-scans.ts +67 -9
- package/src/types.ts +222 -71
- package/tsconfig.json +2 -1
- package/src/process-exec-metadata.ts +0 -153
- package/src/test-fixtures.ts +0 -668
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// Metadata classifiers for `security.process-exec` findings. They turn a process call's
|
|
2
|
-
// first argument and shell option into review hints without changing whether the rule fires.
|
|
3
|
-
import { escapeRegex } from "./findings-helpers.ts";
|
|
4
|
-
|
|
5
|
-
type ProcessExecArgumentSource = "literal" | "process-exec-path" | "local-const" | "local-builder" | "parameter" | "member" | "template" | "unknown";
|
|
6
|
-
|
|
7
|
-
// Stable scanner state for the first-argument boundary walk.
|
|
8
|
-
interface ArgumentScanState {
|
|
9
|
-
depth: number;
|
|
10
|
-
quote: string | undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Stable result of consuming one character in the first-argument scanner.
|
|
14
|
-
interface ArgumentScanStep {
|
|
15
|
-
state: ArgumentScanState;
|
|
16
|
-
skip: number;
|
|
17
|
-
isBoundary: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Builds non-suppressing metadata for a child-process finding.
|
|
22
|
-
*
|
|
23
|
-
* @param callName Matched process API name, for example `spawn` or `execSync`.
|
|
24
|
-
* @param rawSource Original source text used for literal and local-const classification.
|
|
25
|
-
* @param callStart Byte offset where the process call starts in the file.
|
|
26
|
-
* @param rawSegment Original source segment from call start through closing paren.
|
|
27
|
-
* @param codeSegment Masked source segment used to read the shell option safely.
|
|
28
|
-
* @returns Stable metadata describing command-source shape and shell mode.
|
|
29
|
-
*/
|
|
30
|
-
export function processExecMetadata(callName: string, rawSource: string, callStart: number, rawSegment: string, codeSegment: string): Record<string, unknown> {
|
|
31
|
-
const firstArgument = firstProcessCallArgument(rawSegment);
|
|
32
|
-
return {
|
|
33
|
-
callName,
|
|
34
|
-
argumentSource: processExecArgumentSource(rawSource, callStart, firstArgument),
|
|
35
|
-
shellEnabled: processExecShellEnabled(callName, codeSegment),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Extracts the first top-level call argument so commas inside arrays, objects, calls, or strings
|
|
40
|
-
// do not misclassify `spawn("node", ["script,arg"])` as a dynamic command.
|
|
41
|
-
function firstProcessCallArgument(rawSegment: string): string {
|
|
42
|
-
const argsText = rawSegment.slice(rawSegment.indexOf("(") + 1, rawSegment.lastIndexOf(")"));
|
|
43
|
-
return firstTopLevelArgument(argsText).trim();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Walks one argument list with quote and nesting state. The invariant is deliberately narrow:
|
|
47
|
-
// find only the first top-level comma, because command-source classification does not need parsing.
|
|
48
|
-
function firstTopLevelArgument(argsText: string): string {
|
|
49
|
-
let state: ArgumentScanState = { depth: 0, quote: undefined };
|
|
50
|
-
for (let index = 0; index < argsText.length; index += 1) {
|
|
51
|
-
const step = argumentScanStep(argsText, index, state);
|
|
52
|
-
if (step.isBoundary) {
|
|
53
|
-
return argsText.slice(0, index);
|
|
54
|
-
}
|
|
55
|
-
state = step.state;
|
|
56
|
-
index += step.skip;
|
|
57
|
-
}
|
|
58
|
-
return argsText;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Advances one character in the argument scan while keeping string escapes and nesting separate.
|
|
62
|
-
function argumentScanStep(argsText: string, index: number, state: ArgumentScanState): ArgumentScanStep {
|
|
63
|
-
const character = argsText[index] ?? "";
|
|
64
|
-
if (state.quote) {
|
|
65
|
-
return quotedArgumentScanStep(argsText, index, state, character);
|
|
66
|
-
}
|
|
67
|
-
if (isQuoteDelimiter(character)) {
|
|
68
|
-
return scanStep({ depth: state.depth, quote: character });
|
|
69
|
-
}
|
|
70
|
-
if (isOpeningDelimiter(character)) {
|
|
71
|
-
return scanStep({ depth: state.depth + 1, quote: undefined });
|
|
72
|
-
}
|
|
73
|
-
if (isClosingDelimiter(character)) {
|
|
74
|
-
return scanStep({ depth: Math.max(0, state.depth - 1), quote: undefined });
|
|
75
|
-
}
|
|
76
|
-
return scanStep(state, character === "," && state.depth === 0);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Handles one quoted character; escaped characters skip the next byte so an escaped quote stays inside.
|
|
80
|
-
function quotedArgumentScanStep(argsText: string, index: number, state: ArgumentScanState, character: string): ArgumentScanStep {
|
|
81
|
-
if (character === "\\" && index + 1 < argsText.length) {
|
|
82
|
-
return scanStep(state, false, 1);
|
|
83
|
-
}
|
|
84
|
-
if (character === state.quote) {
|
|
85
|
-
return scanStep({ depth: state.depth, quote: undefined });
|
|
86
|
-
}
|
|
87
|
-
return scanStep(state);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Builds the scan step object with explicit defaults so the main loop stays branch-light.
|
|
91
|
-
function scanStep(state: ArgumentScanState, isBoundary = false, skip = 0): ArgumentScanStep {
|
|
92
|
-
return { state, isBoundary, skip };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Quote delimiters are all significant because shell-command strings commonly use any of them.
|
|
96
|
-
function isQuoteDelimiter(character: string): boolean {
|
|
97
|
-
return character === "\"" || character === "'" || character === "`";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Nested call/array/object delimiters suppress comma boundaries until they close.
|
|
101
|
-
function isOpeningDelimiter(character: string): boolean {
|
|
102
|
-
return character === "(" || character === "[" || character === "{";
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Closing delimiters unwind nesting but never below zero, which keeps malformed snippets bounded.
|
|
106
|
-
function isClosingDelimiter(character: string): boolean {
|
|
107
|
-
return character === ")" || character === "]" || character === "}";
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Classifies the command operand for reviewer triage. This is advisory metadata only: every emitted
|
|
111
|
-
// process-exec finding still requires human review of the surrounding command construction.
|
|
112
|
-
function processExecArgumentSource(rawSource: string, callStart: number, firstArgument: string): ProcessExecArgumentSource {
|
|
113
|
-
if (firstArgument === "process.execPath") {
|
|
114
|
-
return "process-exec-path";
|
|
115
|
-
}
|
|
116
|
-
if (/^`/.test(firstArgument)) {
|
|
117
|
-
return /\$\{/.test(firstArgument) ? "template" : "literal";
|
|
118
|
-
}
|
|
119
|
-
if (/^["'][^"']*["']$/.test(firstArgument)) {
|
|
120
|
-
return "literal";
|
|
121
|
-
}
|
|
122
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*\s*\(/.test(firstArgument)) {
|
|
123
|
-
return "local-builder";
|
|
124
|
-
}
|
|
125
|
-
const identifier = firstArgument.match(/^[A-Za-z_$][A-Za-z0-9_$]*$/)?.[0];
|
|
126
|
-
if (identifier) {
|
|
127
|
-
return hasConstLiteralCommandDeclaration(rawSource, callStart, identifier) ? "local-const" : "parameter";
|
|
128
|
-
}
|
|
129
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)+/.test(firstArgument)) {
|
|
130
|
-
return "member";
|
|
131
|
-
}
|
|
132
|
-
return "unknown";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Looks backward from the call for a same-scope `const command = "fixed"` shape so reviewers can
|
|
136
|
-
// distinguish fixed command vectors from parameter-driven command names.
|
|
137
|
-
function hasConstLiteralCommandDeclaration(rawSource: string, callStart: number, identifier: string): boolean {
|
|
138
|
-
const declaration = rawSource.slice(0, callStart).match(new RegExp(`\\bconst\\s+${escapeRegex(identifier)}\\s*=\\s*([^;]+);\\s*$`, "s"));
|
|
139
|
-
const initializer = declaration?.[1] ?? "";
|
|
140
|
-
return /["'][^"']+["']/.test(initializer) && !/[`$()[\]{}]/.test(initializer);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Reports default shell semantics: exec/execSync imply a shell unless an explicit option says false,
|
|
144
|
-
// while spawn/execFile variants default to shell-disabled unless explicitly enabled.
|
|
145
|
-
function processExecShellEnabled(callName: string, codeSegment: string): boolean {
|
|
146
|
-
if (/\bshell\s*:\s*true\b/.test(codeSegment)) {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
if (/\bshell\s*:\s*false\b/.test(codeSegment)) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return callName === "exec" || callName === "execSync";
|
|
153
|
-
}
|