@arvyx/sentinel-mcp 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -8,10 +8,10 @@ Security for the apps you build with AI, inside Claude Code, Codex and CI.
8
8
 
9
9
  | Engine | Finds | Install |
10
10
  |---|---|---|
11
- | Sentinel checks (built in) | Supabase tables without RLS and `using (true)` policies, open Firebase rules, committed / un-ignored `.env` files, secrets in `NEXT_PUBLIC_` / `VITE_` / `EXPO_PUBLIC_` variables, missing security headers | nothing |
11
+ | Sentinel checks (built in) | Supabase tables without RLS and policies that let anyone change data (`using (true)` on insert/update/delete), open Firebase rules, committed / un-ignored `.env` files, secrets in `NEXT_PUBLIC_` / `VITE_` / `EXPO_PUBLIC_` variables, missing security headers | nothing |
12
12
  | [Trivy](https://github.com/aquasecurity/trivy) | Vulnerable dependencies (grouped per package, with the upgrade target), Dockerfile / Terraform / Kubernetes misconfig, dependency inventory | `brew install trivy` |
13
13
  | [Gitleaks](https://github.com/gitleaks/gitleaks) | Secrets in files **and in git history** | `brew install gitleaks` |
14
- | [Opengrep](https://github.com/opengrep/opengrep) | Insecure code patterns (Sentinel's own rules in `rules/sentinel.yml`: SQL / command injection, eval, XSS, open redirect, hard-coded JWT secrets, service-role key in client code, CORS) | see Opengrep's install script |
14
+ | [Opengrep](https://github.com/opengrep/opengrep) | Insecure code (Sentinel's own rules in `rules/sentinel.yml`): request input flowing into SQL, shell commands, eval or deserialization (taint tracking, JS/TS + Python), unsafe HTML, open redirects, hard-coded / unverified JWTs, Supabase service key in client code, CORS, weak hashes | see Opengrep's install script |
15
15
 
16
16
  Scanning runs **on your machine or CI runner**. Only results are uploaded — tool, rule, file, line, package
17
17
  and versions. Never your code, never a secret value, never commit author details. A missing engine is
package/cli.js CHANGED
@@ -27,16 +27,19 @@ Env: SENTINEL_API_KEY (required to upload), SENTINEL_API_URL, SENTINEL_TRIVY/GIT
27
27
  }
28
28
 
29
29
  const log = (m) => console.error(`[sentinel] ${m}`);
30
- try {
30
+
31
+ // Returns the exit code. The caller sets process.exitCode (never process.exit), so piped stdout is
32
+ // fully flushed before Node exits.
33
+ async function main() {
31
34
  const payload = await scan(dir, { trigger: opt("trigger", process.env.CI ? "ci" : "cli"), log });
32
35
  if (flag("no-upload")) {
33
36
  console.log(JSON.stringify(payload, null, 2));
34
- process.exit(0);
37
+ return 0;
35
38
  }
36
39
  const key = process.env.SENTINEL_API_KEY;
37
40
  if (!key) {
38
41
  log("SENTINEL_API_KEY is not set. Create one in Sentinel (Settings → API keys), or use --no-upload.");
39
- process.exit(2);
42
+ return 2;
40
43
  }
41
44
  const base = process.env.SENTINEL_API_URL || "https://sentinel-api-maa1.onrender.com";
42
45
  log(`uploading ${payload.findings.length} result(s) for ${payload.repo}…`);
@@ -45,9 +48,9 @@ try {
45
48
  const failOn = opt("fail-on", "none");
46
49
  if (shouldFail(result, failOn)) {
47
50
  log(`failing: new issue(s) at or above "${failOn}".`);
48
- process.exit(1);
51
+ return 1;
49
52
  }
50
- } catch (e) {
51
- log(`error: ${e.message}`);
52
- process.exit(2);
53
+ return 0;
53
54
  }
55
+
56
+ process.exitCode = await main().catch((e) => { log(`error: ${e.message}`); return 2; });
package/package.json CHANGED
@@ -1,16 +1,32 @@
1
1
  {
2
2
  "name": "@arvyx/sentinel-mcp",
3
- "version": "0.2.0",
4
- "description": "Sentinel by Arvyx — security scanning for the apps you build with AI, inside Claude Code / Codex and CI.",
3
+ "version": "0.2.1",
4
+ "description": "Sentinel by Arvyx \u2014 security scanning for the apps you build with AI, inside Claude Code / Codex and CI.",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
- "bin": { "sentinel-mcp": "index.js", "sentinel-scan": "cli.js" },
8
- "files": ["index.js", "cli.js", "scan.js", "rules/", "README.md"],
9
- "engines": { "node": ">=18" },
7
+ "bin": {
8
+ "sentinel-mcp": "index.js",
9
+ "sentinel-scan": "cli.js"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "cli.js",
14
+ "scan.js",
15
+ "rules/",
16
+ "README.md"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
10
21
  "license": "UNLICENSED",
11
- "publishConfig": { "access": "public" },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
12
25
  "dependencies": {
13
26
  "@modelcontextprotocol/sdk": "^1.18.0",
14
27
  "zod": "^3.23.8"
28
+ },
29
+ "scripts": {
30
+ "test:rules": "node test/score_rules.mjs"
15
31
  }
16
32
  }
@@ -27,10 +27,18 @@ rules:
27
27
  metadata: {title: "SQL query built by string concatenation", cwe: ["CWE-89"]}
28
28
  patterns:
29
29
  - pattern-either:
30
- - pattern: $DB.query("..." + $X, ...)
31
- - pattern: $DB.execute("..." + $X, ...)
32
- - pattern: $DB.raw("..." + $X, ...)
33
- - pattern: $DB.$queryRawUnsafe("..." + $X, ...)
30
+ - pattern: $DB.query($Q, ...)
31
+ - pattern: $DB.execute($Q, ...)
32
+ - pattern: $DB.raw($Q, ...)
33
+ - pattern: $DB.$queryRawUnsafe($Q, ...)
34
+ - pattern: $DB.$executeRawUnsafe($Q, ...)
35
+ - metavariable-pattern:
36
+ metavariable: $Q
37
+ patterns:
38
+ - pattern-either:
39
+ - pattern: '"..." + $X'
40
+ - pattern: '$X + "..."'
41
+ - pattern-not: '"..." + "..."'
34
42
  - id: python-sql-formatted
35
43
  languages: [python]
36
44
  severity: ERROR
@@ -78,7 +86,7 @@ rules:
78
86
  message: >-
79
87
  eval / new Function runs a string as code. If the string can contain user input, an attacker can run
80
88
  code in your app. Parse data with JSON.parse or use a lookup table instead.
81
- metadata: {title: "Dynamic code evaluation", cwe: ["CWE-95"]}
89
+ metadata: {title: "Dynamic code evaluation", cwe: ["CWE-94"]}
82
90
  patterns:
83
91
  - pattern-either:
84
92
  - pattern: eval($X)
@@ -109,10 +117,10 @@ rules:
109
117
  run scripts in your users' browsers (stealing sessions). Sanitize it (DOMPurify) or render text.
110
118
  metadata: {title: "Unsanitized HTML rendered in React", cwe: ["CWE-79"]}
111
119
  patterns:
112
- - pattern: <$EL dangerouslySetInnerHTML={{__html: $X}} />
113
- - pattern-not: <$EL dangerouslySetInnerHTML={{__html: "..."}} />
114
- - pattern-not: <$EL dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(...)}} />
115
- - pattern-not: <$EL dangerouslySetInnerHTML={{__html: sanitize(...)}} />
120
+ - pattern: '<$EL dangerouslySetInnerHTML={{__html: $X}} />'
121
+ - pattern-not: '<$EL dangerouslySetInnerHTML={{__html: "..."}} />'
122
+ - pattern-not: '<$EL dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(...)}} />'
123
+ - pattern-not: '<$EL dangerouslySetInnerHTML={{__html: sanitize(...)}} />'
116
124
  - id: open-redirect-from-request
117
125
  languages: [javascript, typescript]
118
126
  severity: WARNING
@@ -144,7 +152,20 @@ rules:
144
152
  jwt.decode() reads a token without checking its signature, so anyone can craft one. Use jwt.verify()
145
153
  (or your auth provider's server helper) before trusting the token's claims.
146
154
  metadata: {title: "JWT used without signature verification", cwe: ["CWE-347"]}
147
- pattern: $JWT.decode($T, ...)
155
+ patterns:
156
+ - pattern: $JWT.decode($T, ...)
157
+ - metavariable-regex:
158
+ metavariable: $JWT
159
+ regex: ^(jwt|jws|jsonwebtoken|jose|JWT)$
160
+ - pattern-not-inside: $V.verify(...) && $JWT.decode(...)
161
+ - pattern-not-inside: |
162
+ $V.verify($T, ...);
163
+ ...
164
+ - pattern-not-inside: |
165
+ $X = $V.verify($T, ...);
166
+ ...
167
+ - pattern-not-inside: |
168
+ if (<... $V.verify(...) ...>) { ... }
148
169
  - id: supabase-service-role-client-in-browser-code
149
170
  languages: [javascript, typescript]
150
171
  severity: ERROR
@@ -189,3 +210,184 @@ rules:
189
210
  - pattern: crypto.createHash("sha1")
190
211
  - pattern: hashlib.md5(...)
191
212
  - pattern: hashlib.sha1(...)
213
+
214
+ # ------------------------------------------------------------------ taint: request input -> dangerous call
215
+ # Follows user input through variables and string building (the usual shape of generated code:
216
+ # build a string first, run it later). Only the dangerous argument counts, so a parameterized
217
+ # query that receives user input as a bound value is not flagged.
218
+ - id: js-sql-injection-from-request
219
+ mode: taint
220
+ languages: [javascript, typescript]
221
+ severity: ERROR
222
+ message: >-
223
+ Request input reaches a SQL query string. An attacker can rewrite the query to read or change any data.
224
+ Pass the value as a bound parameter ($1 / ?) instead of building the SQL string.
225
+ metadata: {title: "SQL injection from request input", cwe: ["CWE-89"]}
226
+ pattern-sources:
227
+ - pattern-either:
228
+ - pattern: $REQ.body
229
+ - pattern: $REQ.query
230
+ - pattern: $REQ.params
231
+ - pattern: $REQ.cookies
232
+ - pattern: $REQ.headers
233
+ - pattern: $REQ.files
234
+ - pattern: await $REQ.json()
235
+ - pattern: $REQ.nextUrl.searchParams.get(...)
236
+ - pattern: $FORM.get(...)
237
+ pattern-sinks:
238
+ - patterns:
239
+ - pattern-either:
240
+ - pattern: $DB.query($Q, ...)
241
+ - pattern: $DB.execute($Q, ...)
242
+ - pattern: $DB.raw($Q, ...)
243
+ - pattern: $DB.unsafe($Q, ...)
244
+ - pattern: $DB.$queryRawUnsafe($Q, ...)
245
+ - pattern: $DB.$executeRawUnsafe($Q, ...)
246
+ - focus-metavariable: $Q
247
+ - id: js-command-injection-from-request
248
+ mode: taint
249
+ languages: [javascript, typescript]
250
+ severity: ERROR
251
+ message: >-
252
+ Request input reaches a shell command. An attacker can run any command on your server. Use
253
+ execFile/spawn with an argument array and validate the input.
254
+ metadata: {title: "Command injection from request input", cwe: ["CWE-78"]}
255
+ pattern-sources:
256
+ - pattern-either:
257
+ - pattern: $REQ.body
258
+ - pattern: $REQ.query
259
+ - pattern: $REQ.params
260
+ - pattern: $REQ.cookies
261
+ - pattern: $REQ.headers
262
+ - pattern: $REQ.files
263
+ - pattern: await $REQ.json()
264
+ - pattern: $REQ.nextUrl.searchParams.get(...)
265
+ - pattern: $FORM.get(...)
266
+ pattern-sinks:
267
+ - patterns:
268
+ - pattern-either:
269
+ - pattern: exec($CMD, ...)
270
+ - pattern: execSync($CMD, ...)
271
+ - pattern: $CP.exec($CMD, ...)
272
+ - pattern: $CP.execSync($CMD, ...)
273
+ - focus-metavariable: $CMD
274
+ - id: js-code-injection-from-request
275
+ mode: taint
276
+ languages: [javascript, typescript]
277
+ severity: ERROR
278
+ message: >-
279
+ Request input is evaluated or deserialized as code (eval, Function, vm, math evaluators,
280
+ node-serialize). An attacker can run code inside your app. Never evaluate user input; parse data with
281
+ JSON.parse.
282
+ metadata: {title: "Code injection from request input", cwe: ["CWE-94"]}
283
+ pattern-sources:
284
+ - pattern-either:
285
+ - pattern: $REQ.body
286
+ - pattern: $REQ.query
287
+ - pattern: $REQ.params
288
+ - pattern: $REQ.cookies
289
+ - pattern: $REQ.headers
290
+ - pattern: $REQ.files
291
+ - pattern: await $REQ.json()
292
+ - pattern: $REQ.nextUrl.searchParams.get(...)
293
+ - pattern: $FORM.get(...)
294
+ pattern-sinks:
295
+ - patterns:
296
+ - pattern-either:
297
+ - pattern: eval($X)
298
+ - pattern: new Function(..., $X)
299
+ - pattern: $M.eval($X, ...)
300
+ - pattern: $M.evaluate($X, ...)
301
+ - pattern: vm.$RUN($X, ...)
302
+ - pattern: $S.unserialize($X, ...)
303
+ - focus-metavariable: $X
304
+ - id: python-sql-injection-from-request
305
+ mode: taint
306
+ languages: [python]
307
+ severity: ERROR
308
+ message: >-
309
+ Request input reaches a SQL query string. An attacker can rewrite the query to read or change any data.
310
+ Use parameters: cursor.execute("... WHERE id = %s", (value,)) or the ORM's filters.
311
+ metadata: {title: "SQL injection from request input", cwe: ["CWE-89"]}
312
+ pattern-sources:
313
+ - pattern-either:
314
+ - pattern: request.GET
315
+ - pattern: request.POST
316
+ - pattern: request.args
317
+ - pattern: request.form
318
+ - pattern: request.values
319
+ - pattern: request.json
320
+ - pattern: request.data
321
+ - pattern: request.body
322
+ - pattern: request.cookies
323
+ - pattern: request.headers
324
+ - pattern: request.get_json(...)
325
+ - pattern: request.query_params
326
+ pattern-sinks:
327
+ - patterns:
328
+ - pattern-either:
329
+ - pattern: $C.execute($Q, ...)
330
+ - pattern: $C.executemany($Q, ...)
331
+ - pattern: $C.executescript($Q, ...)
332
+ - pattern: $M.objects.raw($Q, ...)
333
+ - pattern: $M.extra(where=$Q, ...)
334
+ - pattern: text($Q)
335
+ - focus-metavariable: $Q
336
+ - id: python-command-injection-from-request
337
+ mode: taint
338
+ languages: [python]
339
+ severity: ERROR
340
+ message: >-
341
+ Request input reaches a shell command. An attacker can run any command on your server. Pass an argument
342
+ list without shell=True and validate the input.
343
+ metadata: {title: "Command injection from request input", cwe: ["CWE-78"]}
344
+ pattern-sources:
345
+ - pattern-either:
346
+ - pattern: request.GET
347
+ - pattern: request.POST
348
+ - pattern: request.args
349
+ - pattern: request.form
350
+ - pattern: request.values
351
+ - pattern: request.json
352
+ - pattern: request.data
353
+ - pattern: request.body
354
+ - pattern: request.cookies
355
+ - pattern: request.headers
356
+ - pattern: request.get_json(...)
357
+ - pattern: request.query_params
358
+ pattern-sinks:
359
+ - patterns:
360
+ - pattern-either:
361
+ - pattern: os.system($CMD)
362
+ - pattern: os.popen($CMD, ...)
363
+ - pattern: subprocess.$F($CMD, ..., shell=True, ...)
364
+ - focus-metavariable: $CMD
365
+ - id: python-code-injection-from-request
366
+ mode: taint
367
+ languages: [python]
368
+ severity: ERROR
369
+ message: >-
370
+ Request input is evaluated as Python code or deserialized unsafely. An attacker can run code on your
371
+ server. Never eval user input; use json / ast.literal_eval / yaml.safe_load.
372
+ metadata: {title: "Code injection from request input", cwe: ["CWE-94"]}
373
+ pattern-sources:
374
+ - pattern-either:
375
+ - pattern: request.GET
376
+ - pattern: request.POST
377
+ - pattern: request.args
378
+ - pattern: request.form
379
+ - pattern: request.values
380
+ - pattern: request.json
381
+ - pattern: request.data
382
+ - pattern: request.body
383
+ - pattern: request.cookies
384
+ - pattern: request.headers
385
+ - pattern: request.get_json(...)
386
+ - pattern: request.query_params
387
+ pattern-sinks:
388
+ - patterns:
389
+ - pattern-either:
390
+ - pattern: eval($X, ...)
391
+ - pattern: exec($X, ...)
392
+ - pattern: render_template_string($X, ...)
393
+ - focus-metavariable: $X
package/scan.js CHANGED
@@ -148,6 +148,9 @@ async function runTrivy(ctx, bin, withSecrets, tmp) {
148
148
  }
149
149
 
150
150
  // ------------------------------------------------------------------ gitleaks
151
+ // JWTs in .env.example-style files are almost always Supabase's public local-dev demo keys. Other
152
+ // secrets in example files (real API keys pasted by mistake) are still reported.
153
+ const isTemplateJwt = (l) => l.RuleID === "jwt" && ENV_FILE.test(l.File) && ENV_TEMPLATE.test(l.File);
151
154
  async function gitleaksRun(bin, mode, target, out) {
152
155
  const r = await run(bin, [mode, "--redact", "--no-banner", "--log-level", "error", "--exit-code", "0",
153
156
  "--report-format", "json", "--report-path", out, target], { timeout: 900000 });
@@ -160,13 +163,15 @@ async function runGitleaks(ctx, bin, tmp) {
160
163
  const key = (l) => sha(`${l.RuleID}|${Number(l.Entropy || 0).toFixed(3)}`);
161
164
  const current = (await gitleaksRun(bin, "dir", ctx.root, path.join(tmp, "gl-dir.json")))
162
165
  .map((l) => ({ ...l, File: path.relative(ctx.root, path.resolve(ctx.root, l.File)).split(path.sep).join("/") }))
163
- .filter((l) => !ctx.isGit || ctx.fileSet.has(l.File)); // a gitignored local .env is correct practice
166
+ .filter((l) => !ctx.isGit || ctx.fileSet.has(l.File)) // a gitignored local .env is correct practice
167
+ .filter((l) => !isTemplateJwt(l));
164
168
  const findings = current.map((l) => ({ tool: "gitleaks", kind: "secret", rule: l.RuleID, title: l.RuleID,
165
169
  message: l.Description, path: l.File, line: l.StartLine, key: key(l) }));
166
170
  if (ctx.isGit) {
167
171
  const now = new Set(findings.map((f) => `${f.path}|${f.rule}|${f.key}`));
168
172
  const seen = new Set();
169
173
  for (const l of await gitleaksRun(bin, "git", ctx.root, path.join(tmp, "gl-git.json"))) {
174
+ if (isTemplateJwt(l)) continue;
170
175
  const id = `${l.File}|${l.RuleID}|${key(l)}`;
171
176
  if (now.has(id) || seen.has(id)) continue; // still in the tree (reported above) or a repeat
172
177
  seen.add(id);
@@ -194,11 +199,20 @@ async function runOpengrep(ctx, bin) {
194
199
  return { status: { status: "error", detail: String(fatal[0].message || fatal[0].type).slice(0, 280) } };
195
200
  }
196
201
  const findings = [];
202
+ // A taint rule and a pattern rule can flag the same bug, sometimes on adjacent lines of one
203
+ // multi-line call: report one finding per bug class (CWE) within a few lines.
204
+ // ponytail: line-window heuristic; use opengrep's dataflow trace ranges if it merges real neighbours.
205
+ const seenAt = new Map();
197
206
  for (const res of data.results || []) {
198
207
  const rel = path.relative(ctx.root, path.resolve(ctx.root, res.path)).split(path.sep).join("/");
199
208
  if (ctx.isGit && !ctx.fileSet.has(rel)) continue;
200
209
  const meta = res.extra?.metadata || {};
201
210
  const rule = String(res.check_id || "").split(".").pop();
211
+ const bugClass = `${rel}|${String([].concat(meta.cwe || [rule])[0]).split(":")[0]}`;
212
+ const line = res.start?.line || 0;
213
+ const near = seenAt.get(bugClass) || [];
214
+ if (near.some((l) => Math.abs(l - line) <= 3)) continue;
215
+ seenAt.set(bugClass, [...near, line]);
202
216
  findings.push({ tool: "opengrep", kind: "sast", rule, severity: res.extra?.severity, title: meta.title || rule,
203
217
  message: res.extra?.message, path: rel, line: res.start?.line,
204
218
  cwe: [].concat(meta.cwe || []).map((c) => String(c).split(":")[0]).slice(0, 5),
@@ -245,7 +259,10 @@ async function supabaseChecks(ctx) {
245
259
  else if (m[5]) {
246
260
  const t = tableName(m[6]).name, body = m[7] || "";
247
261
  const id = `${t}:${m[5].replace(/"/g, "")}`;
248
- if (/\busing\s*\(\s*true\s*\)|\bwith\s+check\s*\(\s*true\s*\)/i.test(body)) policies.set(id, { path: f, line });
262
+ // Public READ of catalog-style data is a normal design (and the live scan proves what anon can
263
+ // actually read); `true` on a policy that can insert/update/delete lets anyone change data.
264
+ const readOnly = /\bfor\s+select\b/i.test(body);
265
+ if (!readOnly && /\busing\s*\(\s*true\s*\)|\bwith\s+check\s*\(\s*true\s*\)/i.test(body)) policies.set(id, { path: f, line });
249
266
  else policies.delete(id);
250
267
  } else if (m[8]) policies.delete(`${tableName(m[9]).name}:${m[8].replace(/"/g, "")}`);
251
268
  }