cfgsentry 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 +21 -0
- package/README.md +120 -2
- package/dist/chunk-72XI7S6P.js +451 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +102 -0
- package/dist/files.d.ts +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/report.d.ts +2 -0
- package/dist/rules.d.ts +44 -0
- package/dist/scan.d.ts +8 -0
- package/dist/types.d.ts +18 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jaydip Patel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cfgsentry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Your dependencies get scanned. Your config files don't.**
|
|
4
|
+
|
|
5
|
+
Malware has started hiding in the files every JavaScript project runs without anyone reading them: `next.config.ts`, `postcss.config.mjs`, `eslint.config.js`, `tailwind.config.js`. A typical injection adds a few hundred spaces after `export default nextConfig;` and puts an obfuscated loader after them, off the right edge of the editor. The loader fetches a payload (often through a blockchain RPC endpoint, so there is no server to take down) and starts it as a hidden `node` process every time you run `next dev`.
|
|
6
|
+
|
|
7
|
+
`cfgsentry` finds that. It has **zero runtime dependencies**.
|
|
8
|
+
|
|
9
|
+
```console
|
|
10
|
+
$ npx cfgsentry
|
|
11
|
+
|
|
12
|
+
next.config.ts
|
|
13
|
+
2:327 high hidden-offscreen-code Code hidden after a run of 300 spaces/tabs, off-screen in most editors
|
|
14
|
+
> …efault nextConfig;⟨300 spaces⟩global["r"]=require;fetch("https://bsc-dataseed.binance.org"…
|
|
15
|
+
2:1 high loader-pattern Fetches remote data (line 2) and runs code (line 2): this is how config-file malware loaders work
|
|
16
|
+
...
|
|
17
|
+
|
|
18
|
+
✖ 9 findings (8 high, 1 medium) in 2 of 14 config files
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx cfgsentry # scan config files under the current folder
|
|
25
|
+
npx cfgsentry apps/web # scan a specific folder or file
|
|
26
|
+
npx cfgsentry --staged # scan only staged config files (pre-commit)
|
|
27
|
+
npx cfgsentry --json # machine-readable output
|
|
28
|
+
npx cfgsentry --list # show which files would be scanned
|
|
29
|
+
npx cfgsentry --fail-on medium
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The exit code is `1` when a finding meets `--fail-on` (default `high`) and `2` on a usage error.
|
|
33
|
+
|
|
34
|
+
### Pre-commit hook
|
|
35
|
+
|
|
36
|
+
[husky](https://typicode.github.io/husky/): `.husky/pre-commit`
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npx cfgsentry --staged
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
[lefthook](https://github.com/evilmartians/lefthook): `lefthook.yml`
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
pre-commit:
|
|
46
|
+
commands:
|
|
47
|
+
cfgsentry:
|
|
48
|
+
run: npx cfgsentry --staged
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`--staged` reads files from the git index, so it scans exactly what is about to be committed.
|
|
52
|
+
|
|
53
|
+
### CI (GitHub Actions)
|
|
54
|
+
|
|
55
|
+
```yaml
|
|
56
|
+
- run: npx cfgsentry
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What it scans
|
|
60
|
+
|
|
61
|
+
Anything that looks like tooling config, in every folder except `node_modules`, `.git`, and build output:
|
|
62
|
+
|
|
63
|
+
- `*.config.{js,cjs,mjs,ts,cts,mts}` and `*-config.*` (Next, Vite, Tailwind, PostCSS, ESLint, Gatsby, Jest, Playwright...)
|
|
64
|
+
- `.eslintrc*`, `.babelrc*`, `.prettierrc*`, `.stylelintrc*`, `.postcssrc*`, `.swcrc`, `.mocharc*`, `.lintstagedrc*`
|
|
65
|
+
- `gatsby-node`, `gatsby-browser`, `gatsby-ssr`
|
|
66
|
+
- `package.json`
|
|
67
|
+
|
|
68
|
+
A file you name on the command line is always scanned.
|
|
69
|
+
|
|
70
|
+
## Rules
|
|
71
|
+
|
|
72
|
+
| Rule | Severity | Catches |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| `hidden-offscreen-code` | high | Code after a long run of spaces/tabs, or after very deep indentation |
|
|
75
|
+
| `hidden-below` | medium | Code after 25+ blank lines |
|
|
76
|
+
| `invisible-unicode` | high | Zero-width and bidi-override characters (Trojan Source) |
|
|
77
|
+
| `code-after-export` | high | Anything after `export default x;` on the same line |
|
|
78
|
+
| `loader-pattern` | high | Network access **and** code execution in the same file |
|
|
79
|
+
| `dynamic-code` | high | `eval`, `new Function`, `vm.*`, `data:` imports |
|
|
80
|
+
| `process-spawn` | high | `child_process`, `spawn`, `execSync`, `process.binding` |
|
|
81
|
+
| `detached-process` | high | `detached: true`, `windowsHide`, `.unref()`, `stdio: 'ignore'` |
|
|
82
|
+
| `blockchain-rpc` | high | `eth_call`, JSON-RPC bodies, known RPC hosts |
|
|
83
|
+
| `global-tamper` | high | `global['x'] = ...`, aliasing `require` |
|
|
84
|
+
| `obfuscated-identifiers` | high | `_0x1a2b`-style names |
|
|
85
|
+
| `escaped-strings` | high | Long `\x..` / `\u....` runs |
|
|
86
|
+
| `network-call` | medium | `fetch`, `http(s)`/`net`/`tls` modules, WebSocket |
|
|
87
|
+
| `encoded-blob` | medium | 200+ characters of base64/hex |
|
|
88
|
+
| `decode-call` | medium | `atob`, `Buffer.from(..., 'base64')`, `String.fromCharCode` |
|
|
89
|
+
| `long-line` | medium | Lines over 1000 characters |
|
|
90
|
+
| `install-script` | high | `preinstall`/`postinstall`/`prepare` scripts that download or evaluate code |
|
|
91
|
+
| `non-registry-dependency` | low | Dependencies installed from git or URLs |
|
|
92
|
+
|
|
93
|
+
## False positives
|
|
94
|
+
|
|
95
|
+
Put `cfgsentry-ignore` in a comment on the line, or on the line above:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// cfgsentry-ignore: we really do fetch the schema at build time
|
|
99
|
+
const schema = await fetch(SCHEMA_URL).then((r) => r.json());
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Rules that detect **hiding** (`hidden-offscreen-code`, `hidden-below`, `invisible-unicode`, `code-after-export`) and `loader-pattern` can't be silenced this way. An attacker who can hide code can add an ignore comment too.
|
|
103
|
+
|
|
104
|
+
## API
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { scanSource, scanFile, findConfigFiles } from "cfgsentry";
|
|
108
|
+
|
|
109
|
+
const findings = scanSource("next.config.ts", source);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## If it finds something
|
|
113
|
+
|
|
114
|
+
1. **Don't run** `dev`, `build`, or `install` in that project again until it's clean.
|
|
115
|
+
2. Use `git log -p -- <file>` to find the commit that added the code, and note which machine it came from.
|
|
116
|
+
3. Remove the code, then check that machine. This malware re-injects itself into config files while the machine is still infected.
|
|
117
|
+
4. Rotate any secrets that were in `.env` or the shell environment on that machine.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// src/rules.ts
|
|
2
|
+
var CODE = ["code"];
|
|
3
|
+
var ALL = ["code", "data"];
|
|
4
|
+
var INVISIBLE_RE = /[----]/;
|
|
5
|
+
var INVISIBLE_RE_G = new RegExp(INVISIBLE_RE.source, "g");
|
|
6
|
+
function patternRule(id, severity, message, patterns, opts = {}) {
|
|
7
|
+
return {
|
|
8
|
+
id,
|
|
9
|
+
severity,
|
|
10
|
+
ignorable: opts.ignorable ?? true,
|
|
11
|
+
kinds: opts.kinds ?? CODE,
|
|
12
|
+
test(line) {
|
|
13
|
+
for (const re of patterns) {
|
|
14
|
+
const m = re.exec(line);
|
|
15
|
+
if (m) return { column: m.index + 1, message };
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
var MIN_INLINE_GAP = 60;
|
|
22
|
+
var MIN_LEADING_GAP = 120;
|
|
23
|
+
var hiddenOffscreenCode = {
|
|
24
|
+
id: "hidden-offscreen-code",
|
|
25
|
+
severity: "high",
|
|
26
|
+
ignorable: false,
|
|
27
|
+
kinds: ALL,
|
|
28
|
+
test(line) {
|
|
29
|
+
const lead = /^[ \t]*/.exec(line)[0].length;
|
|
30
|
+
if (lead >= MIN_LEADING_GAP && lead < line.length) {
|
|
31
|
+
return {
|
|
32
|
+
column: lead + 1,
|
|
33
|
+
message: `Code starts after ${lead} characters of indentation, off-screen in most editors`
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const m = new RegExp(`\\S([ \\t]{${MIN_INLINE_GAP},})(?=\\S)`).exec(line);
|
|
37
|
+
if (m) {
|
|
38
|
+
const gap = m[1].length;
|
|
39
|
+
return {
|
|
40
|
+
column: m.index + 1 + gap + 1,
|
|
41
|
+
message: `Code hidden after a run of ${gap} spaces/tabs, off-screen in most editors`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var invisibleUnicode = {
|
|
48
|
+
id: "invisible-unicode",
|
|
49
|
+
severity: "high",
|
|
50
|
+
ignorable: false,
|
|
51
|
+
kinds: ALL,
|
|
52
|
+
test(line) {
|
|
53
|
+
const m = INVISIBLE_RE.exec(line);
|
|
54
|
+
if (!m) return null;
|
|
55
|
+
const cp = m[0].codePointAt(0).toString(16).toUpperCase().padStart(4, "0");
|
|
56
|
+
return { column: m.index + 1, message: `Invisible character U+${cp} can hide or reorder code` };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var codeAfterExport = {
|
|
60
|
+
id: "code-after-export",
|
|
61
|
+
severity: "high",
|
|
62
|
+
ignorable: false,
|
|
63
|
+
kinds: CODE,
|
|
64
|
+
test(line) {
|
|
65
|
+
const m = /^\s*(?:export\s+default|module\.exports\s*=)\s*[\w$.]+\s*;\s*(?=\S)/.exec(line);
|
|
66
|
+
if (!m || line.slice(m[0].length).startsWith("//")) return null;
|
|
67
|
+
return {
|
|
68
|
+
column: m[0].length + 1,
|
|
69
|
+
message: "Code on the same line after the config export, a common injection spot"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var longLine = {
|
|
74
|
+
id: "long-line",
|
|
75
|
+
severity: "medium",
|
|
76
|
+
ignorable: true,
|
|
77
|
+
kinds: CODE,
|
|
78
|
+
test(line) {
|
|
79
|
+
return line.length > 1e3 ? { column: 1001, message: `Line is ${line.length} characters long; config files rarely need this` } : null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var dynamicCode = patternRule(
|
|
83
|
+
"dynamic-code",
|
|
84
|
+
"high",
|
|
85
|
+
"Runs code built from a string at load time",
|
|
86
|
+
[
|
|
87
|
+
/(?<![\w$.])eval\s*\(/,
|
|
88
|
+
/\bnew\s+Function\s*\(/,
|
|
89
|
+
/(?<![\w$.])Function\s*\(\s*['"`]/,
|
|
90
|
+
/\bvm\s*\.\s*(?:runInThisContext|runInNewContext|runInContext|compileFunction|Script)\b/,
|
|
91
|
+
/['"`](?:node:)?vm['"`]/,
|
|
92
|
+
/\bimport\s*\(\s*['"`]data:/
|
|
93
|
+
]
|
|
94
|
+
);
|
|
95
|
+
var processSpawn = patternRule(
|
|
96
|
+
"process-spawn",
|
|
97
|
+
"high",
|
|
98
|
+
"Starts other processes from a config file",
|
|
99
|
+
[
|
|
100
|
+
/['"`](?:node:)?child_process['"`]/,
|
|
101
|
+
/(?<![\w$])(?:execSync|spawnSync|execFileSync|execFile|spawn|fork)\s*\(/,
|
|
102
|
+
/\bprocess\s*\.\s*(?:binding|dlopen|mainModule)\b/
|
|
103
|
+
]
|
|
104
|
+
);
|
|
105
|
+
var detachedProcess = patternRule(
|
|
106
|
+
"detached-process",
|
|
107
|
+
"high",
|
|
108
|
+
"Starts a hidden or detached background process",
|
|
109
|
+
[
|
|
110
|
+
/\bdetached\s*:\s*(?:true\b|!0)/,
|
|
111
|
+
/\bwindowsHide\s*:\s*(?:true\b|!0)/,
|
|
112
|
+
/\.unref\s*\(\s*\)/,
|
|
113
|
+
/\bstdio\s*:\s*['"`]ignore['"`]/
|
|
114
|
+
]
|
|
115
|
+
);
|
|
116
|
+
var networkCall = patternRule(
|
|
117
|
+
"network-call",
|
|
118
|
+
"medium",
|
|
119
|
+
"Makes network requests while the config loads",
|
|
120
|
+
[
|
|
121
|
+
/(?<![\w$.])fetch\s*\(/,
|
|
122
|
+
/\b(?:https?|net|tls|dgram)\s*\.\s*(?:request|get|connect|createConnection|createSocket)\s*\(/,
|
|
123
|
+
/\brequire\s*\(\s*['"`](?:node:)?(?:https?|net|tls|dgram|axios)['"`]\s*\)/,
|
|
124
|
+
/\bfrom\s+['"`](?:node:)?(?:https?|net|tls|dgram|axios)['"`]/,
|
|
125
|
+
/\bimport\s*\(\s*['"`](?:node:)?(?:https?|net|tls|dgram|axios)['"`]/,
|
|
126
|
+
/\bXMLHttpRequest\b/,
|
|
127
|
+
/\bnew\s+WebSocket\s*\(/
|
|
128
|
+
]
|
|
129
|
+
);
|
|
130
|
+
var blockchainRpc = patternRule(
|
|
131
|
+
"blockchain-rpc",
|
|
132
|
+
"high",
|
|
133
|
+
"Talks to a blockchain RPC endpoint; malware uses these to fetch its payload",
|
|
134
|
+
[
|
|
135
|
+
/\beth_(?:call|getTransactionByHash|getTransactionReceipt|getStorageAt|getCode|getLogs|blockNumber)\b/,
|
|
136
|
+
/['"`]?jsonrpc['"`]?\s*:\s*['"`]2\.0['"`]/,
|
|
137
|
+
/\b[\w.-]*(?:infura\.io|alchemy\.com|alchemyapi\.io|bsc-dataseed[\w.-]*|binance\.org|trongrid\.io|quiknode\.pro|ankr\.com|publicnode\.com|llamarpc\.com|blastapi\.io|drpc\.org|chainstack\.com|aptoslabs\.com|solana\.com|etherscan\.io|bscscan\.com|tronscan\.org)\b/i
|
|
138
|
+
]
|
|
139
|
+
);
|
|
140
|
+
var obfuscatedIdentifiers = patternRule(
|
|
141
|
+
"obfuscated-identifiers",
|
|
142
|
+
"high",
|
|
143
|
+
"Obfuscator-style identifiers (_0x...)",
|
|
144
|
+
[/\b_0x[0-9a-f]{4,}\b/i]
|
|
145
|
+
);
|
|
146
|
+
var globalTamper = patternRule(
|
|
147
|
+
"global-tamper",
|
|
148
|
+
"high",
|
|
149
|
+
"Stashes values or `require` on the global object, a known loader trick",
|
|
150
|
+
[
|
|
151
|
+
/\bglobal(?:This)?\s*\[\s*['"`][^'"`]{1,6}['"`]\s*\]\s*=/,
|
|
152
|
+
/(?<![=!<>])=\s*require\s*(?=[;,)]|$)/
|
|
153
|
+
]
|
|
154
|
+
);
|
|
155
|
+
var escapeSequences = {
|
|
156
|
+
id: "escaped-strings",
|
|
157
|
+
severity: "high",
|
|
158
|
+
ignorable: true,
|
|
159
|
+
kinds: CODE,
|
|
160
|
+
test(line) {
|
|
161
|
+
const hex = /(?:\\x[0-9a-f]{2}){8,}/i.exec(line);
|
|
162
|
+
if (hex) return { column: hex.index + 1, message: "Long run of \\x escapes hides readable text" };
|
|
163
|
+
const uni = /(?:\\u[0-9a-f]{4}){8,}/i.exec(line);
|
|
164
|
+
if (uni) return { column: uni.index + 1, message: "Long run of \\u escapes hides readable text" };
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var encodedBlob = patternRule(
|
|
169
|
+
"encoded-blob",
|
|
170
|
+
"medium",
|
|
171
|
+
"Long base64/hex blob; may be an encoded payload",
|
|
172
|
+
[/[A-Za-z0-9+/]{200,}={0,2}/]
|
|
173
|
+
);
|
|
174
|
+
var decodeCall = patternRule(
|
|
175
|
+
"decode-call",
|
|
176
|
+
"medium",
|
|
177
|
+
"Decodes hidden text at runtime",
|
|
178
|
+
[
|
|
179
|
+
/(?<![\w$.])atob\s*\(/,
|
|
180
|
+
/\bBuffer\s*\.\s*from\s*\([^)]*['"`](?:base64|hex)['"`]/,
|
|
181
|
+
/\bString\s*\.\s*fromCharCode\b/
|
|
182
|
+
]
|
|
183
|
+
);
|
|
184
|
+
var LINE_RULES = [
|
|
185
|
+
hiddenOffscreenCode,
|
|
186
|
+
invisibleUnicode,
|
|
187
|
+
codeAfterExport,
|
|
188
|
+
dynamicCode,
|
|
189
|
+
processSpawn,
|
|
190
|
+
detachedProcess,
|
|
191
|
+
blockchainRpc,
|
|
192
|
+
networkCall,
|
|
193
|
+
obfuscatedIdentifiers,
|
|
194
|
+
globalTamper,
|
|
195
|
+
escapeSequences,
|
|
196
|
+
encodedBlob,
|
|
197
|
+
decodeCall,
|
|
198
|
+
longLine
|
|
199
|
+
];
|
|
200
|
+
var FETCH_RULES = /* @__PURE__ */ new Set(["network-call", "blockchain-rpc"]);
|
|
201
|
+
var EXEC_RULES = /* @__PURE__ */ new Set(["dynamic-code", "process-spawn"]);
|
|
202
|
+
var HIDDEN_BELOW_BLANKS = 25;
|
|
203
|
+
var LIFECYCLE_SCRIPTS = [
|
|
204
|
+
"preinstall",
|
|
205
|
+
"install",
|
|
206
|
+
"postinstall",
|
|
207
|
+
"preuninstall",
|
|
208
|
+
"uninstall",
|
|
209
|
+
"postuninstall",
|
|
210
|
+
"prepare",
|
|
211
|
+
"preprepare",
|
|
212
|
+
"postprepare",
|
|
213
|
+
"prepublish"
|
|
214
|
+
];
|
|
215
|
+
var SUSPICIOUS_SCRIPT_RE = /\b(?:curl|wget|Invoke-WebRequest|iwr|irm|Invoke-Expression|iex|powershell|pwsh)\b|\bnode\s+(?:-e|--eval|-p|--print)\b|\b(?:bash|sh|zsh)\s+-c\b|\|\s*(?:ba|z)?sh\b|base64|https?:\/\//i;
|
|
216
|
+
var NON_REGISTRY_DEP_RE = /^(?:https?:|git(?:\+[\w-]+)?:|github:|gitlab:|bitbucket:|[\w-]+\/[\w.-]+(?:#.*)?$)/;
|
|
217
|
+
|
|
218
|
+
// src/scan.ts
|
|
219
|
+
import { readFileSync, statSync } from "fs";
|
|
220
|
+
import { basename } from "path";
|
|
221
|
+
var IGNORE_MARK = "cfgsentry-ignore";
|
|
222
|
+
var MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
223
|
+
function fileKind(path) {
|
|
224
|
+
return /\.[cm]?[jt]sx?$/i.test(path) ? "code" : "data";
|
|
225
|
+
}
|
|
226
|
+
function scanSource(file, source) {
|
|
227
|
+
const text = source.charCodeAt(0) === 65279 ? source.slice(1) : source;
|
|
228
|
+
const lines = text.split(/\r?\n/);
|
|
229
|
+
const kind = fileKind(file);
|
|
230
|
+
const findings = [];
|
|
231
|
+
const add = (rule, severity, line, column, message) => findings.push({ rule, severity, file, line, column, message, snippet: makeSnippet(lines[line - 1] ?? "", column) });
|
|
232
|
+
const rawHits = /* @__PURE__ */ new Map();
|
|
233
|
+
lines.forEach((line, i) => {
|
|
234
|
+
const ignored = line.includes(IGNORE_MARK) || i > 0 && lines[i - 1].includes(IGNORE_MARK);
|
|
235
|
+
for (const rule of LINE_RULES) {
|
|
236
|
+
if (!rule.kinds.includes(kind)) continue;
|
|
237
|
+
const m = rule.test(line);
|
|
238
|
+
if (!m) continue;
|
|
239
|
+
if (!rawHits.has(rule.id)) rawHits.set(rule.id, i + 1);
|
|
240
|
+
if (ignored && rule.ignorable) continue;
|
|
241
|
+
add(rule.id, rule.severity, i + 1, m.column, m.message);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const fetchLine = firstHit(rawHits, FETCH_RULES);
|
|
245
|
+
const execLine = firstHit(rawHits, EXEC_RULES);
|
|
246
|
+
if (fetchLine !== void 0 && execLine !== void 0) {
|
|
247
|
+
add(
|
|
248
|
+
"loader-pattern",
|
|
249
|
+
"high",
|
|
250
|
+
fetchLine,
|
|
251
|
+
1,
|
|
252
|
+
`Fetches remote data (line ${fetchLine}) and runs code (line ${execLine}): this is how config-file malware loaders work`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
let blanks = 0;
|
|
256
|
+
lines.forEach((line, i) => {
|
|
257
|
+
if (line.trim() === "") {
|
|
258
|
+
blanks++;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (blanks >= HIDDEN_BELOW_BLANKS) {
|
|
262
|
+
add("hidden-below", "medium", i + 1, 1, `Code after ${blanks} blank lines, pushed out of view`);
|
|
263
|
+
}
|
|
264
|
+
blanks = 0;
|
|
265
|
+
});
|
|
266
|
+
if (basename(file).toLowerCase() === "package.json") {
|
|
267
|
+
for (const f of scanPackageJson(text, lines)) add(f.rule, f.severity, f.line, 1, f.message);
|
|
268
|
+
}
|
|
269
|
+
return findings.sort((a, b) => a.line - b.line || a.column - b.column);
|
|
270
|
+
}
|
|
271
|
+
function scanFile(path, displayPath = path) {
|
|
272
|
+
if (statSync(path).size > MAX_FILE_BYTES) return [];
|
|
273
|
+
return scanSource(displayPath, readFileSync(path, "utf8"));
|
|
274
|
+
}
|
|
275
|
+
function firstHit(hits, ids) {
|
|
276
|
+
let best;
|
|
277
|
+
for (const id of ids) {
|
|
278
|
+
const line = hits.get(id);
|
|
279
|
+
if (line !== void 0 && (best === void 0 || line < best)) best = line;
|
|
280
|
+
}
|
|
281
|
+
return best;
|
|
282
|
+
}
|
|
283
|
+
function scanPackageJson(text, lines) {
|
|
284
|
+
let pkg;
|
|
285
|
+
try {
|
|
286
|
+
pkg = JSON.parse(text);
|
|
287
|
+
} catch {
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
const out = [];
|
|
291
|
+
const lineOf = (key, value) => {
|
|
292
|
+
const needle = `"${key}"`;
|
|
293
|
+
const idx = lines.findIndex((l) => l.includes(needle) && (value === void 0 || l.includes(value.slice(0, 20))));
|
|
294
|
+
return idx === -1 ? 1 : idx + 1;
|
|
295
|
+
};
|
|
296
|
+
const scripts = isRecord(pkg.scripts) ? pkg.scripts : {};
|
|
297
|
+
for (const name of LIFECYCLE_SCRIPTS) {
|
|
298
|
+
const cmd = scripts[name];
|
|
299
|
+
if (typeof cmd === "string" && SUSPICIOUS_SCRIPT_RE.test(cmd)) {
|
|
300
|
+
out.push({
|
|
301
|
+
rule: "install-script",
|
|
302
|
+
severity: "high",
|
|
303
|
+
line: lineOf(name),
|
|
304
|
+
message: `"${name}" runs automatically on install and downloads or evaluates code: ${truncate(cmd, 80)}`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
309
|
+
const deps = pkg[field];
|
|
310
|
+
if (!isRecord(deps)) continue;
|
|
311
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
312
|
+
if (typeof spec === "string" && NON_REGISTRY_DEP_RE.test(spec)) {
|
|
313
|
+
out.push({
|
|
314
|
+
rule: "non-registry-dependency",
|
|
315
|
+
severity: "low",
|
|
316
|
+
line: lineOf(name, spec),
|
|
317
|
+
message: `${name} is installed from ${truncate(spec, 60)} instead of the npm registry`
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
function isRecord(v) {
|
|
325
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
326
|
+
}
|
|
327
|
+
function truncate(s, n) {
|
|
328
|
+
return s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
|
|
329
|
+
}
|
|
330
|
+
function visible(s) {
|
|
331
|
+
return s.replace(/[ \t]{9,}/g, (m) => `\u27E8${m.length} spaces\u27E9`).replace(INVISIBLE_RE_G, (c) => `\u27E8U+${c.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}\u27E9`);
|
|
332
|
+
}
|
|
333
|
+
function makeSnippet(line, column) {
|
|
334
|
+
const left = visible(line.slice(0, column - 1)).trimStart();
|
|
335
|
+
const right = visible(line.slice(column - 1));
|
|
336
|
+
const l = left.length > 30 ? `\u2026${left.slice(-30)}` : left;
|
|
337
|
+
const r = right.length > 60 ? `${right.slice(0, 60)}\u2026` : right;
|
|
338
|
+
return (l + r).trimEnd();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/files.ts
|
|
342
|
+
import { execFileSync } from "child_process";
|
|
343
|
+
import { readdirSync } from "fs";
|
|
344
|
+
import { basename as basename2, join } from "path";
|
|
345
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
346
|
+
"node_modules",
|
|
347
|
+
".git",
|
|
348
|
+
".next",
|
|
349
|
+
".nuxt",
|
|
350
|
+
".svelte-kit",
|
|
351
|
+
".output",
|
|
352
|
+
".turbo",
|
|
353
|
+
".vercel",
|
|
354
|
+
".cache",
|
|
355
|
+
".parcel-cache",
|
|
356
|
+
"dist",
|
|
357
|
+
"build",
|
|
358
|
+
"out",
|
|
359
|
+
"coverage"
|
|
360
|
+
]);
|
|
361
|
+
var CONFIG_PATTERNS = [
|
|
362
|
+
// next.config.ts, vite.config.mjs, tailwind.config.js, eslint.config.mjs, gatsby-config.js ...
|
|
363
|
+
/(?:^|[.-])config\.[cm]?[jt]sx?$/i,
|
|
364
|
+
// .eslintrc.cjs, .babelrc, .prettierrc.json, .postcssrc.yml ...
|
|
365
|
+
/^\.(?:eslintrc|babelrc|prettierrc|stylelintrc|lintstagedrc|mocharc|swcrc|postcssrc)(?:\.[cm]?js|\.json|\.ya?ml)?$/i,
|
|
366
|
+
/^gatsby-(?:node|browser|ssr)\.[cm]?[jt]sx?$/i,
|
|
367
|
+
/^package\.json$/i
|
|
368
|
+
];
|
|
369
|
+
function isConfigFile(path) {
|
|
370
|
+
const name = basename2(path);
|
|
371
|
+
return CONFIG_PATTERNS.some((re) => re.test(name));
|
|
372
|
+
}
|
|
373
|
+
function findConfigFiles(root) {
|
|
374
|
+
const out = [];
|
|
375
|
+
const walk = (dir) => {
|
|
376
|
+
let entries;
|
|
377
|
+
try {
|
|
378
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
379
|
+
} catch {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
for (const e of entries) {
|
|
383
|
+
if (e.isSymbolicLink()) continue;
|
|
384
|
+
const full = join(dir, e.name);
|
|
385
|
+
if (e.isDirectory()) {
|
|
386
|
+
if (!SKIP_DIRS.has(e.name)) walk(full);
|
|
387
|
+
} else if (e.isFile() && isConfigFile(e.name)) {
|
|
388
|
+
out.push(full);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
walk(root);
|
|
393
|
+
return out.sort();
|
|
394
|
+
}
|
|
395
|
+
function stagedConfigFiles(cwd = process.cwd()) {
|
|
396
|
+
const opts = {
|
|
397
|
+
cwd,
|
|
398
|
+
encoding: "utf8",
|
|
399
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
400
|
+
maxBuffer: 16 * 1024 * 1024
|
|
401
|
+
};
|
|
402
|
+
const names = execFileSync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACMR", "-z"], opts).split("\0").filter((p) => p && isConfigFile(p));
|
|
403
|
+
return names.map((path) => ({ path, content: execFileSync("git", ["show", `:${path}`], opts) }));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/report.ts
|
|
407
|
+
var ANSI = { red: 31, yellow: 33, cyan: 36, gray: 90, green: 32, bold: 1 };
|
|
408
|
+
function formatReport(findings, filesScanned, color) {
|
|
409
|
+
const paint = (c, s) => color ? `\x1B[${ANSI[c]}m${s}\x1B[0m` : s;
|
|
410
|
+
const sevColor = { high: "red", medium: "yellow", low: "cyan" };
|
|
411
|
+
if (findings.length === 0) {
|
|
412
|
+
return paint("green", `\u2714 ${filesScanned} config file${filesScanned === 1 ? "" : "s"} scanned, nothing suspicious.`);
|
|
413
|
+
}
|
|
414
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
415
|
+
for (const f of findings) byFile.set(f.file, [...byFile.get(f.file) ?? [], f]);
|
|
416
|
+
const out = [];
|
|
417
|
+
for (const [file, list] of byFile) {
|
|
418
|
+
out.push(paint("bold", file));
|
|
419
|
+
for (const f of list) {
|
|
420
|
+
const pos = `${f.line}:${f.column}`.padEnd(8);
|
|
421
|
+
out.push(` ${paint("gray", pos)}${paint(sevColor[f.severity], f.severity.padEnd(7))}${f.rule.padEnd(24)}${f.message}`);
|
|
422
|
+
if (f.snippet) out.push(` ${" ".repeat(8)}${paint("gray", `> ${f.snippet}`)}`);
|
|
423
|
+
}
|
|
424
|
+
out.push("");
|
|
425
|
+
}
|
|
426
|
+
const count = (s) => findings.filter((f) => f.severity === s).length;
|
|
427
|
+
const parts = ["high", "medium", "low"].filter((s) => count(s) > 0).map((s) => `${count(s)} ${s}`);
|
|
428
|
+
out.push(
|
|
429
|
+
paint(
|
|
430
|
+
count("high") > 0 ? "red" : "yellow",
|
|
431
|
+
`\u2716 ${findings.length} finding${findings.length === 1 ? "" : "s"} (${parts.join(", ")}) in ${byFile.size} of ${filesScanned} config file${filesScanned === 1 ? "" : "s"}`
|
|
432
|
+
)
|
|
433
|
+
);
|
|
434
|
+
return out.join("\n");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// src/types.ts
|
|
438
|
+
var SEVERITY_RANK = { low: 1, medium: 2, high: 3 };
|
|
439
|
+
|
|
440
|
+
export {
|
|
441
|
+
LINE_RULES,
|
|
442
|
+
IGNORE_MARK,
|
|
443
|
+
scanSource,
|
|
444
|
+
scanFile,
|
|
445
|
+
makeSnippet,
|
|
446
|
+
isConfigFile,
|
|
447
|
+
findConfigFiles,
|
|
448
|
+
stagedConfigFiles,
|
|
449
|
+
formatReport,
|
|
450
|
+
SEVERITY_RANK
|
|
451
|
+
};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
SEVERITY_RANK,
|
|
4
|
+
findConfigFiles,
|
|
5
|
+
formatReport,
|
|
6
|
+
scanFile,
|
|
7
|
+
scanSource,
|
|
8
|
+
stagedConfigFiles
|
|
9
|
+
} from "./chunk-72XI7S6P.js";
|
|
10
|
+
|
|
11
|
+
// src/cli.ts
|
|
12
|
+
import { statSync } from "fs";
|
|
13
|
+
import { createRequire } from "module";
|
|
14
|
+
import { relative } from "path";
|
|
15
|
+
var VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
16
|
+
var HELP = `cfgsentry ${VERSION}
|
|
17
|
+
Scan config files for hidden malware payloads.
|
|
18
|
+
|
|
19
|
+
Usage
|
|
20
|
+
cfgsentry [paths...] Scan config files under paths (default: .)
|
|
21
|
+
cfgsentry --staged Scan staged config files (use in a pre-commit hook)
|
|
22
|
+
|
|
23
|
+
Options
|
|
24
|
+
--fail-on <level> Exit 1 when a finding is at least this severe:
|
|
25
|
+
high (default), medium, low, none
|
|
26
|
+
--json Print findings as JSON
|
|
27
|
+
--list Only list the files that would be scanned
|
|
28
|
+
-h, --help Show this help
|
|
29
|
+
-v, --version Show version
|
|
30
|
+
|
|
31
|
+
Silence a false positive with a "cfgsentry-ignore" comment on the line
|
|
32
|
+
or the line above. Rules that detect hidden code cannot be silenced.`;
|
|
33
|
+
function parseArgs(argv) {
|
|
34
|
+
const args = { paths: [], staged: false, json: false, list: false, failOn: "high" };
|
|
35
|
+
for (let i = 0; i < argv.length; i++) {
|
|
36
|
+
const a = argv[i];
|
|
37
|
+
if (a === "-h" || a === "--help") exit(HELP, 0);
|
|
38
|
+
else if (a === "-v" || a === "--version") exit(VERSION, 0);
|
|
39
|
+
else if (a === "--staged") args.staged = true;
|
|
40
|
+
else if (a === "--json") args.json = true;
|
|
41
|
+
else if (a === "--list") args.list = true;
|
|
42
|
+
else if (a === "--fail-on" || a.startsWith("--fail-on=")) {
|
|
43
|
+
const v = a.includes("=") ? a.split("=")[1] : argv[++i];
|
|
44
|
+
if (v !== "high" && v !== "medium" && v !== "low" && v !== "none") {
|
|
45
|
+
exit(`cfgsentry: --fail-on must be high, medium, low or none`, 2);
|
|
46
|
+
}
|
|
47
|
+
args.failOn = v;
|
|
48
|
+
} else if (a.startsWith("-")) exit(`cfgsentry: unknown option ${a}
|
|
49
|
+
|
|
50
|
+
${HELP}`, 2);
|
|
51
|
+
else args.paths.push(a);
|
|
52
|
+
}
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
function exit(msg, code) {
|
|
56
|
+
(code === 0 ? process.stdout : process.stderr).write(`${msg}
|
|
57
|
+
`);
|
|
58
|
+
process.exit(code);
|
|
59
|
+
}
|
|
60
|
+
var display = (p) => (relative(process.cwd(), p) || p).replace(/\\/g, "/");
|
|
61
|
+
function main() {
|
|
62
|
+
const args = parseArgs(process.argv.slice(2));
|
|
63
|
+
const findings = [];
|
|
64
|
+
let files;
|
|
65
|
+
if (args.staged) {
|
|
66
|
+
let staged;
|
|
67
|
+
try {
|
|
68
|
+
staged = stagedConfigFiles();
|
|
69
|
+
} catch {
|
|
70
|
+
exit(`cfgsentry: --staged needs git and must run inside a git repository`, 2);
|
|
71
|
+
}
|
|
72
|
+
files = staged.map((f) => f.path);
|
|
73
|
+
if (!args.list) for (const f of staged) findings.push(...scanSource(f.path, f.content));
|
|
74
|
+
} else {
|
|
75
|
+
files = [];
|
|
76
|
+
for (const p of args.paths.length ? args.paths : ["."]) {
|
|
77
|
+
let isDir;
|
|
78
|
+
try {
|
|
79
|
+
isDir = statSync(p).isDirectory();
|
|
80
|
+
} catch {
|
|
81
|
+
exit(`cfgsentry: cannot read ${p}`, 2);
|
|
82
|
+
}
|
|
83
|
+
files.push(...isDir ? findConfigFiles(p) : [p]);
|
|
84
|
+
}
|
|
85
|
+
if (!args.list) for (const f of files) findings.push(...scanFile(f, display(f)));
|
|
86
|
+
}
|
|
87
|
+
if (args.list) {
|
|
88
|
+
for (const f of files) console.log(display(f));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (args.json) {
|
|
92
|
+
console.log(JSON.stringify({ version: VERSION, filesScanned: files.length, findings }, null, 2));
|
|
93
|
+
} else {
|
|
94
|
+
const color = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
95
|
+
console.log(formatReport(findings, files.length, color));
|
|
96
|
+
}
|
|
97
|
+
if (args.failOn !== "none") {
|
|
98
|
+
const threshold = SEVERITY_RANK[args.failOn];
|
|
99
|
+
if (findings.some((f) => SEVERITY_RANK[f.severity] >= threshold)) process.exitCode = 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
main();
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function isConfigFile(path: string): boolean;
|
|
2
|
+
/** Recursively find config files under `root`, skipping dependency and build folders. */
|
|
3
|
+
export declare function findConfigFiles(root: string): string[];
|
|
4
|
+
export interface StagedFile {
|
|
5
|
+
path: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}
|
|
8
|
+
/** Staged config files, read from the git index: exactly what is about to be committed. */
|
|
9
|
+
export declare function stagedConfigFiles(cwd?: string): StagedFile[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { scanSource, scanFile, makeSnippet, IGNORE_MARK } from "./scan.js";
|
|
2
|
+
export { findConfigFiles, isConfigFile, stagedConfigFiles } from "./files.js";
|
|
3
|
+
export { formatReport } from "./report.js";
|
|
4
|
+
export { LINE_RULES } from "./rules.js";
|
|
5
|
+
export type { LineRule, LineMatch } from "./rules.js";
|
|
6
|
+
export { SEVERITY_RANK } from "./types.js";
|
|
7
|
+
export type { Finding, Severity, FileKind } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IGNORE_MARK,
|
|
3
|
+
LINE_RULES,
|
|
4
|
+
SEVERITY_RANK,
|
|
5
|
+
findConfigFiles,
|
|
6
|
+
formatReport,
|
|
7
|
+
isConfigFile,
|
|
8
|
+
makeSnippet,
|
|
9
|
+
scanFile,
|
|
10
|
+
scanSource,
|
|
11
|
+
stagedConfigFiles
|
|
12
|
+
} from "./chunk-72XI7S6P.js";
|
|
13
|
+
export {
|
|
14
|
+
IGNORE_MARK,
|
|
15
|
+
LINE_RULES,
|
|
16
|
+
SEVERITY_RANK,
|
|
17
|
+
findConfigFiles,
|
|
18
|
+
formatReport,
|
|
19
|
+
isConfigFile,
|
|
20
|
+
makeSnippet,
|
|
21
|
+
scanFile,
|
|
22
|
+
scanSource,
|
|
23
|
+
stagedConfigFiles
|
|
24
|
+
};
|
package/dist/report.d.ts
ADDED
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FileKind, Severity } from "./types.js";
|
|
2
|
+
export interface LineMatch {
|
|
3
|
+
/** 1-based column of the suspicious code. */
|
|
4
|
+
column: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LineRule {
|
|
8
|
+
id: string;
|
|
9
|
+
severity: Severity;
|
|
10
|
+
/**
|
|
11
|
+
* Whether an inline `cfgsentry-ignore` comment may silence this rule.
|
|
12
|
+
* Rules that detect *hiding* are never ignorable: an attacker who can hide
|
|
13
|
+
* code can also add an ignore comment.
|
|
14
|
+
*/
|
|
15
|
+
ignorable: boolean;
|
|
16
|
+
kinds: readonly FileKind[];
|
|
17
|
+
test(line: string): LineMatch | null;
|
|
18
|
+
}
|
|
19
|
+
/** Zero-width, bidi-override and other invisible characters (Trojan Source and friends). */
|
|
20
|
+
export declare const INVISIBLE_RE: RegExp;
|
|
21
|
+
export declare const INVISIBLE_RE_G: RegExp;
|
|
22
|
+
export declare const hiddenOffscreenCode: LineRule;
|
|
23
|
+
export declare const invisibleUnicode: LineRule;
|
|
24
|
+
export declare const codeAfterExport: LineRule;
|
|
25
|
+
export declare const longLine: LineRule;
|
|
26
|
+
export declare const dynamicCode: LineRule;
|
|
27
|
+
export declare const processSpawn: LineRule;
|
|
28
|
+
export declare const detachedProcess: LineRule;
|
|
29
|
+
export declare const networkCall: LineRule;
|
|
30
|
+
export declare const blockchainRpc: LineRule;
|
|
31
|
+
export declare const obfuscatedIdentifiers: LineRule;
|
|
32
|
+
export declare const globalTamper: LineRule;
|
|
33
|
+
export declare const escapeSequences: LineRule;
|
|
34
|
+
export declare const encodedBlob: LineRule;
|
|
35
|
+
export declare const decodeCall: LineRule;
|
|
36
|
+
export declare const LINE_RULES: readonly LineRule[];
|
|
37
|
+
/** Rules whose hits feed the file-level "loader-pattern" check. */
|
|
38
|
+
export declare const FETCH_RULES: Set<string>;
|
|
39
|
+
export declare const EXEC_RULES: Set<string>;
|
|
40
|
+
/** Blank lines in a row before code that count as "pushed out of view". */
|
|
41
|
+
export declare const HIDDEN_BELOW_BLANKS = 25;
|
|
42
|
+
export declare const LIFECYCLE_SCRIPTS: readonly ["preinstall", "install", "postinstall", "preuninstall", "uninstall", "postuninstall", "prepare", "preprepare", "postprepare", "prepublish"];
|
|
43
|
+
export declare const SUSPICIOUS_SCRIPT_RE: RegExp;
|
|
44
|
+
export declare const NON_REGISTRY_DEP_RE: RegExp;
|
package/dist/scan.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FileKind, Finding } from "./types.js";
|
|
2
|
+
export declare const IGNORE_MARK = "cfgsentry-ignore";
|
|
3
|
+
export declare function fileKind(path: string): FileKind;
|
|
4
|
+
/** Scan file contents. `file` is used for display and to pick which rules apply. */
|
|
5
|
+
export declare function scanSource(file: string, source: string): Finding[];
|
|
6
|
+
export declare function scanFile(path: string, displayPath?: string): Finding[];
|
|
7
|
+
/** Excerpt around `column`, with whitespace runs and invisible characters made visible. */
|
|
8
|
+
export declare function makeSnippet(line: string, column: number): string;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Severity = "high" | "medium" | "low";
|
|
2
|
+
export declare const SEVERITY_RANK: Record<Severity, number>;
|
|
3
|
+
/** "code" files are executed by Node (js/ts); "data" files are JSON/YAML/etc. */
|
|
4
|
+
export type FileKind = "code" | "data";
|
|
5
|
+
export interface Finding {
|
|
6
|
+
/** Rule id, e.g. "hidden-offscreen-code". */
|
|
7
|
+
rule: string;
|
|
8
|
+
severity: Severity;
|
|
9
|
+
/** Path as displayed to the user. */
|
|
10
|
+
file: string;
|
|
11
|
+
/** 1-based line number. */
|
|
12
|
+
line: number;
|
|
13
|
+
/** 1-based column number. */
|
|
14
|
+
column: number;
|
|
15
|
+
message: string;
|
|
16
|
+
/** Short printable excerpt; long whitespace runs and invisible characters are made visible. */
|
|
17
|
+
snippet: string;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cfgsentry",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scan your own config files for hidden malware: off-screen code, obfuscation, eval, child_process, network loaders and sneaky install scripts.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"security",
|
|
7
|
+
"malware",
|
|
8
|
+
"supply-chain",
|
|
9
|
+
"config",
|
|
10
|
+
"scanner",
|
|
11
|
+
"pre-commit",
|
|
12
|
+
"next.config",
|
|
13
|
+
"lint"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Jaydip Patel",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/jaydippatel83/cfgsentry.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/jaydippatel83/cfgsentry#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/jaydippatel83/cfgsentry/issues"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"cfgsentry": "dist/cli.js"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^26.6.11",
|
|
49
|
+
"tsup": "^9.0.0",
|
|
50
|
+
"typescript": "^7.0.2",
|
|
51
|
+
"vitest": "^5.1.2"
|
|
52
|
+
}
|
|
53
|
+
}
|