@vibefoundry/vibe-shield 0.0.0-stage → 1.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +571 -3
  3. package/SECURITY.md +110 -0
  4. package/SKILL.md +124 -0
  5. package/dist/bin/vibe-shield.d.ts +59 -0
  6. package/dist/bin/vibe-shield.js +541 -0
  7. package/dist/src/index.d.ts +25 -0
  8. package/dist/src/index.js +108 -0
  9. package/dist/src/init/scaffold.d.ts +122 -0
  10. package/dist/src/init/scaffold.js +573 -0
  11. package/dist/src/mcp/server.d.ts +127 -0
  12. package/dist/src/mcp/server.js +479 -0
  13. package/dist/src/mcp-guard/skill-auditor.d.ts +105 -0
  14. package/dist/src/mcp-guard/skill-auditor.js +1129 -0
  15. package/dist/src/reporter/console-reporter.d.ts +58 -0
  16. package/dist/src/reporter/console-reporter.js +254 -0
  17. package/dist/src/reporter/formatters.d.ts +38 -0
  18. package/dist/src/reporter/formatters.js +262 -0
  19. package/dist/src/reporter/patch-prompt-writer.d.ts +35 -0
  20. package/dist/src/reporter/patch-prompt-writer.js +238 -0
  21. package/dist/src/scanner/context.d.ts +51 -0
  22. package/dist/src/scanner/context.js +568 -0
  23. package/dist/src/scanner/engine.d.ts +130 -0
  24. package/dist/src/scanner/engine.js +722 -0
  25. package/dist/src/scanner/gitignore.d.ts +49 -0
  26. package/dist/src/scanner/gitignore.js +195 -0
  27. package/dist/src/scanner/lexicon.d.ts +56 -0
  28. package/dist/src/scanner/lexicon.js +357 -0
  29. package/dist/src/scanner/rules/ai-vulnerabilities.d.ts +15 -0
  30. package/dist/src/scanner/rules/ai-vulnerabilities.js +859 -0
  31. package/dist/src/scanner/rules/client-exposure.d.ts +18 -0
  32. package/dist/src/scanner/rules/client-exposure.js +410 -0
  33. package/dist/src/scanner/rules/database-exposure.d.ts +15 -0
  34. package/dist/src/scanner/rules/database-exposure.js +626 -0
  35. package/dist/src/scanner/rules/helpers.d.ts +31 -0
  36. package/dist/src/scanner/rules/helpers.js +85 -0
  37. package/dist/src/scanner/rules/index.d.ts +30 -0
  38. package/dist/src/scanner/rules/index.js +95 -0
  39. package/dist/src/scanner/rules/secret-entropy.d.ts +17 -0
  40. package/dist/src/scanner/rules/secret-entropy.js +338 -0
  41. package/dist/src/scanner/rules/shared.d.ts +100 -0
  42. package/dist/src/scanner/rules/shared.js +161 -0
  43. package/dist/src/scanner/rules/unguarded-routes.d.ts +16 -0
  44. package/dist/src/scanner/rules/unguarded-routes.js +526 -0
  45. package/dist/src/scanner/text.d.ts +90 -0
  46. package/dist/src/scanner/text.js +472 -0
  47. package/dist/src/scanner/types.d.ts +340 -0
  48. package/dist/src/scanner/types.js +195 -0
  49. package/dist/src/secrets/patterns.d.ts +63 -0
  50. package/dist/src/secrets/patterns.js +392 -0
  51. package/package.json +94 -4
package/SECURITY.md ADDED
@@ -0,0 +1,110 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ | Version | Supported |
6
+ | --- | --- |
7
+ | 1.x | ✅ |
8
+ | < 1.0 | ❌ |
9
+
10
+ ## Reporting a vulnerability
11
+
12
+ **Do not open a public issue for a security problem.**
13
+
14
+ Email **security@vibefoundry.dev** with:
15
+
16
+ - a description of the issue and its impact
17
+ - the affected version (`npx github:avivgerz-hue/vibe-shield version`)
18
+ - a minimal reproduction (a snippet, a repository, or a failing test)
19
+ - whether you intend to publish, and any deadline you are working to
20
+
21
+ You get an acknowledgement within **48 hours** and a triage decision within
22
+ **5 business days**. If the report is valid we will:
23
+
24
+ 1. confirm the severity using the CVSS v3.1 vector,
25
+ 2. ship a fix in a patch release,
26
+ 3. publish a GitHub Security Advisory crediting you (unless you prefer to stay
27
+ anonymous),
28
+ 4. request a CVE if the impact warrants one.
29
+
30
+ ## Security model
31
+
32
+ vibe-shield is a **static analyser**. It reads files and reports what it finds.
33
+ Understanding the trust boundaries matters when you run it on untrusted input.
34
+
35
+ ### What the tool does
36
+
37
+ | Behaviour | Detail |
38
+ | --- | --- |
39
+ | Network access | **None.** The runtime has zero dependencies and makes no outbound requests. There is no telemetry, no update check, no crash reporting. |
40
+ | Filesystem access | Read-only, confined to the scan root. `--cache` writes one file (`.vibe-shield-cache.json`) to the scan root; `--fix-prompt` and `--out` write exactly the paths you ask for. |
41
+ | Subprocesses | One optional `git ls-files` / `git rev-parse` call, used to determine whether a `.env` file is tracked. Disable it with `useGitIndex: false` (API) or by running outside a work tree. |
42
+ | Code execution | **None.** Scanned files are never imported, evaluated, executed or served. There is no plugin loading, no `require()` of project code, and no shell invocation derived from file content. |
43
+ | Secret handling | Secret values are matched in memory, then **redacted before they reach any output** (`redactSecret`). `SECURITY_PATCH_PROMPT.md`, JSON, SARIF and GitHub annotations all carry the masked form. The raw value never leaves the process. |
44
+
45
+ ### What it deliberately does not do
46
+
47
+ - It does not resolve dependencies or run a package manager.
48
+ - It does not follow symlinks (symlinked entries are skipped, which prevents a
49
+ scan root from being used to read outside the tree).
50
+ - It does not scan `node_modules`, build output or `.git` (pruned by name).
51
+ - It does not fetch remote rule sets. The rule catalogue is compiled into the
52
+ package and fingerprinted so a cached result can never be reused after a rule
53
+ change (`RULES_FINGERPRINT`).
54
+
55
+ ### Running it on untrusted code
56
+
57
+ Scanning a hostile repository is safe by design: nothing is executed. The two
58
+ things to be aware of are resource-related, not exploit-related:
59
+
60
+ - **Pathological input.** Rules cap match counts (`20_000` per rule per file),
61
+ brace-block extraction (`8_000` chars), and regex scan windows. Files above
62
+ 1.5 MB are skipped. A crafted file can make a rule slow; it cannot make it
63
+ hang indefinitely.
64
+ - **Output size.** A repository engineered to produce thousands of findings will
65
+ produce a large report. Use `--severity`, `--max-findings` or `--format
66
+ summary` when the input is not trusted.
67
+
68
+ ### Supply chain
69
+
70
+ - **Zero runtime dependencies.** There is no transitive package to compromise.
71
+ The only dev dependencies are `typescript` and `vitest` (+ `@vitest/coverage-v8`).
72
+ - **Lockfile committed.** CI installs with `npm ci`, not `npm install`.
73
+ - **Publishing uses provenance.** The release workflow publishes with
74
+ `--provenance` via GitHub OIDC, so the npm artefact is verifiably built from
75
+ this repository's workflow run.
76
+ - **Self-scanning.** CI runs `vibe-shield scan --fail-on high` and
77
+ `vibe-shield audit-skills --fail-on high` against this repository on every
78
+ push. The detector catalogue is the only excluded path, documented in
79
+ [`.vibe-shieldignore`](./.vibe-shieldignore).
80
+
81
+ ### Known limitations (not vulnerabilities)
82
+
83
+ - **Static by design.** Dynamic dispatch, metaprogramming and code generated at
84
+ runtime can hide a vulnerable shape from any static rule.
85
+ - **Heuristics have false positives.** Every rule is conservative about the
86
+ legitimate patterns it knows (see the FAQ in the README), but a novel
87
+ framework can still produce a finding that is not exploitable. That is a bug
88
+ report, not a security issue — please open a normal issue.
89
+ - **The auditor reads prose.** `audit-skills` flags dangerous *language* in
90
+ instruction files. It distinguishes prohibitions from instructions and
91
+ documentation from commands, but an adversarially worded skill can still
92
+ evade a regex. It is a tripwire, not a sandbox; the real defence is not
93
+ installing skills you have not read.
94
+
95
+ ## Scope
96
+
97
+ In scope:
98
+
99
+ - a rule that crashes, hangs, or reads outside the scan root
100
+ - a secret value appearing unredacted in any output stream or file
101
+ - command injection or path traversal through CLI arguments
102
+ - a `--fix-prompt` / `--out` write escaping the intended directory
103
+ - npm publish / release workflow compromise
104
+
105
+ Out of scope:
106
+
107
+ - false positives on unusual framework patterns (open a normal issue)
108
+ - false negatives on obfuscated code (static analysis is not a sandbox)
109
+ - findings in *your* repository that vibe-shield reported correctly
110
+ - vulnerabilities in `npx`'s own resolution behaviour
package/SKILL.md ADDED
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: vibe-shield
3
+ description: Audit any change for AI-introduced security bugs (leaked keys, unguarded API routes, disabled Row Level Security, SQL injection, prompt injection, poisoned MCP servers) and fix them before reporting a task as done. Use whenever you write or modify application code, API routes, server actions, database migrations, auth logic, environment variables, LLM calls, webhook handlers, agent skills or MCP configuration.
4
+ allowed-tools: Bash(npx github:avivgerz-hue/vibe-shield scan*), Bash(npx github:avivgerz-hue/vibe-shield audit-skills*), Bash(npx github:avivgerz-hue/vibe-shield explain*), Read(./**), Grep, Glob
5
+ license: MIT
6
+ metadata:
7
+ author: VibeFoundry
8
+ homepage: https://github.com/avivgerz-hue/vibe-shield
9
+ version: 1.0.0
10
+ ---
11
+
12
+ # vibe-shield
13
+
14
+ You are not allowed to say "done" until the code you just wrote passes a security audit.
15
+
16
+ AI coding agents ship a specific, repeatable class of vulnerability: a `SUPABASE_SERVICE_ROLE_KEY` behind a `NEXT_PUBLIC_` prefix, a `DELETE` route handler with no session check, a `CREATE TABLE` with no `ENABLE ROW LEVEL SECURITY`, a tool whose `execute` forwards model output into `exec`. These are not exotic — they are the default shape of code written quickly by something optimising for "it works". This skill is the second pair of eyes.
17
+
18
+ ## When to run
19
+
20
+ Run the audit **after every change that touches**:
21
+
22
+ - an API route, route handler, server action, RPC endpoint or GraphQL mutation
23
+ - authentication, session, role, permission or ownership logic
24
+ - a database migration, policy, grant, schema or Supabase table
25
+ - an environment variable, config file, `.env*` file or build config
26
+ - anything calling an LLM, a tool, a webhook, a shell command or the filesystem
27
+ - `.claude/`, `.cursor/`, `AGENTS.md`, `mcp.json` or any skill/config file
28
+
29
+ If you did not touch any of those, you do not need to run it.
30
+
31
+ ## The loop
32
+
33
+ ```bash
34
+ # 1. Scan (a whole-repo scan finishes in well under a second)
35
+ npx github:avivgerz-hue/vibe-shield scan --fail-on high
36
+
37
+ # 2. If it fails, generate the machine-readable fix list
38
+ npx github:avivgerz-hue/vibe-shield scan --fix-prompt
39
+
40
+ # 3. Read SECURITY_PATCH_PROMPT.md and fix every finding, critical first
41
+ # Each entry has the exact file:line, the vulnerable snippet, the CWE and
42
+ # the required change. Apply it literally.
43
+
44
+ # 4. Re-run until it exits 0
45
+ npx github:avivgerz-hue/vibe-shield scan --fail-on high
46
+ ```
47
+
48
+ `--fail-on high` exits non-zero while any high or critical finding exists. That is the gate.
49
+
50
+ ## Reading a finding
51
+
52
+ ```
53
+ CRITICAL 47:15 VSB-CLIENT-001 Server-only secret exposed through a public environment prefix
54
+ const key = process.env.NEXT_PUBLIC_OPENAI_API_KEY;
55
+ ```
56
+
57
+ | Part | Meaning |
58
+ | --- | --- |
59
+ | `47:15` | exact line and column to edit |
60
+ | `VSB-CLIENT-001` | rule id — use it with `explain` for full docs |
61
+ | message | why this specific line is exploitable |
62
+ | `(CWE-200)` | bug class, for a deeper search if the fix is unclear |
63
+
64
+ Need the full picture? `npx github:avivgerz-hue/vibe-shield explain VSB-CLIENT-001` prints the vulnerable shape, the fixed shape, remediation steps and references.
65
+
66
+ ## Hard rules
67
+
68
+ 1. **Fix the root cause.** Never delete an auth check, disable RLS, silence a log or add a catch-all `catch {}` to make the finding disappear.
69
+ 2. **Never suppress.** Do not add `// vibe-shield-disable`, do not edit `.vibe-shieldignore`, do not pass `--ignore`. Suppression is a decision for the human.
70
+ 3. **Rotate exposed credentials.** If the scan reported a live key, tell the user to rotate it at the provider in the same message. Removing the line does not un-leak it — the value may already be in a bundle, a cache or a git history.
71
+ 4. **Report honestly.** If you cannot fix a finding (you need a decision, a credential or a provider change), say so explicitly, name the rule id, and stop.
72
+ 5. **Re-verify.** A fix is not finished until the gate exits 0.
73
+
74
+ ## Agent surface audit
75
+
76
+ When you add or modify a skill, rule file, MCP server or instruction file, also run:
77
+
78
+ ```bash
79
+ npx github:avivgerz-hue/vibe-shield audit-skills
80
+ ```
81
+
82
+ Twelve `VSB-AGENT-*` rules check for hidden Unicode (zero-width and bidi characters used to smuggle instructions past review), `curl`/`wget` exfiltration of environment variables, credential-harvesting instructions (`.env`, `~/.ssh`, `~/.aws`), registry-tag or remote MCP servers, literal tokens in an `env` block, safety-override language, over-broad tool permissions, base64 `eval` payloads, remote-instruction fetching, wildcard `allowed-tools`, and shell injection in skill scripts.
83
+
84
+ Each finding carries a `triage` field: `block` means refuse and escalate, `review` means ask the user, `report` means mention it and continue. Do not blanket-refuse a repository because a rule fired — read the triage.
85
+
86
+ ## Flags worth knowing
87
+
88
+ | Flag | Effect |
89
+ | --- | --- |
90
+ | `--format json` | full machine-readable report (schemaVersion 1) |
91
+ | `--format sarif` | SARIF 2.1.0 for GitHub code scanning |
92
+ | `--format compact` | one line per finding |
93
+ | `--format github` | inline GitHub Actions annotations |
94
+ | `--severity high` | only report high and critical |
95
+ | `--fail-on medium` | stricter gate |
96
+ | `--include-tests` | include test and fixture files |
97
+ | `--cache` | reuse results between runs |
98
+ | `--quiet` | one-line verdict (ideal for piping) |
99
+ | `rules` | list every rule |
100
+ | `explain <RULE_ID>` | full documentation for one rule |
101
+
102
+ If the repository has a `.mcp.json`, the same three capabilities are also
103
+ available as MCP tools — `vibe_shield_scan`, `vibe_shield_audit_skills` and
104
+ `vibe_shield_explain_rule`. Prefer those when they are listed, because they
105
+ return structured findings instead of text you have to parse.
106
+
107
+ ## Definition of done
108
+
109
+ - [ ] `npx github:avivgerz-hue/vibe-shield scan --fail-on high` exits `0`
110
+ - [ ] `npx github:avivgerz-hue/vibe-shield audit-skills` exits `0` if you touched agent files
111
+ - [ ] every credential the scan surfaced has been flagged to the user for rotation
112
+ - [ ] no suppression directive was added
113
+ - [ ] the feature still works and the existing tests still pass
114
+
115
+ ## Install it into a repository
116
+
117
+ ```bash
118
+ npx github:avivgerz-hue/vibe-shield init
119
+ ```
120
+
121
+ That writes this file to `.claude/skills/vibe-shield/SKILL.md`, appends a security
122
+ gate section to `AGENTS.md`, adds a `.cursor/rules/vibe-shield.mdc`, and installs a
123
+ GitHub Actions workflow that fails the pull request on new high or critical
124
+ findings. Every future task in that repository starts guarded.
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * vibe-shield :: command line
4
+ * ---------------------------
5
+ * vibe-shield scan [paths] scan a project (default: `.`)
6
+ * vibe-shield audit-skills [paths] audit agent skills / MCP config
7
+ * vibe-shield init install the Agent Skill + CI gate
8
+ * vibe-shield rules list every rule
9
+ * vibe-shield explain <RULE_ID> full documentation for one rule
10
+ * vibe-shield version | help
11
+ *
12
+ * The module exports `run(argv, io)` and only executes when invoked directly,
13
+ * which is what lets the test suite drive the real CLI without a build step.
14
+ */
15
+ /** Everything the CLI needs from the outside world (injectable for tests). */
16
+ export interface CliIo {
17
+ stdout: {
18
+ write(chunk: string): unknown;
19
+ isTTY?: boolean;
20
+ columns?: number;
21
+ };
22
+ stderr: {
23
+ write(chunk: string): unknown;
24
+ isTTY?: boolean;
25
+ columns?: number;
26
+ };
27
+ cwd: string;
28
+ env: NodeJS.ProcessEnv;
29
+ }
30
+ export declare const defaultIo: () => CliIo;
31
+ /** Exit codes: 0 clean, 1 findings at/above `--fail-on`, 2 usage error. */
32
+ export declare const EXIT_OK = 0;
33
+ export declare const EXIT_FINDINGS = 1;
34
+ export declare const EXIT_USAGE = 2;
35
+ declare const HELP = "vibe-shield \u2014 security scanner for AI-generated code\n\nUSAGE\n vibe-shield <command> [options]\n\nCOMMANDS\n scan [paths...] Scan the project (default: current directory).\n audit-skills [paths...] Audit agent skills, Cursor rules, AGENTS.md and MCP configs.\n init Install the Agent Skill, AGENTS.md section and CI workflow.\n rules List every detection rule.\n explain <RULE_ID> Show full documentation for a rule.\n mcp Serve the Model Context Protocol tools over stdio.\n version Print the version.\n help Print this help.\n\nSCAN OPTIONS\n --format <fmt> console | compact | summary | json | sarif | github (console)\n --out <file> Write the report to a file instead of stdout.\n --fix-prompt Write SECURITY_PATCH_PROMPT.md with exact fix instructions.\n --fail-on <severity> Exit 1 when a finding at/above this severity exists. (critical)\n --severity <severity> Only report findings at/above this severity.\n --rules <ids> Comma-separated rule ids/slugs (supports VSB-DB-*).\n --ignore <glob> Extra gitignore-style pattern (repeatable).\n --include-tests Include test, spec and fixture files.\n --include-docs Include Markdown and docs/.\n --cache Reuse .vibe-shield-cache.json between runs.\n --max-findings <n> Limit the console list (0 = all). (50)\n --quiet Print only the verdict line and the exit code.\n --no-color Disable ANSI colour.\n --no-shield-ignore Ignore .vibe-shieldignore (e.g. to scan excluded fixtures).\n --json Shorthand for --format json.\n\nINIT OPTIONS\n --target <dir> Repository to install into. (cwd)\n --agent <kind> claude | cursor | generic | all. (all)\n --no-workflow Skip the GitHub Actions workflow.\n --force Overwrite existing files.\n --yes Accepted for non-interactive CI use (init never prompts).\n\nEXAMPLES\n npx github:avivgerz-hue/vibe-shield scan\n npx github:avivgerz-hue/vibe-shield scan --fail-on high --format github\n npx github:avivgerz-hue/vibe-shield scan --fix-prompt\n npx github:avivgerz-hue/vibe-shield init\n npx github:avivgerz-hue/vibe-shield explain VSB-DB-001\n npx github:avivgerz-hue/vibe-shield audit-skills .claude\n";
36
+ interface ParsedArgs {
37
+ command: string;
38
+ positionals: string[];
39
+ flags: Map<string, string | boolean>;
40
+ unknown: string[];
41
+ }
42
+ /** Parse `argv` without any dependency. Supports `--flag=value` and repeats. */
43
+ export declare function parseArgs(argv: readonly string[]): ParsedArgs;
44
+ declare function commandScan(parsed: ParsedArgs, io: CliIo): Promise<number>;
45
+ declare function commandAuditSkills(parsed: ParsedArgs, io: CliIo): Promise<number>;
46
+ declare function commandInit(parsed: ParsedArgs, io: CliIo): Promise<number>;
47
+ declare function commandRules(parsed: ParsedArgs, io: CliIo): number;
48
+ declare function commandExplain(parsed: ParsedArgs, io: CliIo): number;
49
+ /**
50
+ * Serve MCP over stdio.
51
+ *
52
+ * Nothing but JSON-RPC may reach stdout here — a banner or progress line would
53
+ * corrupt the client session — so the one diagnostic permitted (an explicit
54
+ * note that the server is ready) goes to stderr.
55
+ */
56
+ declare function commandMcp(parsed: ParsedArgs, io: CliIo): Promise<number>;
57
+ /** Run the CLI. Returns the process exit code. */
58
+ export declare function run(argv: readonly string[], io?: CliIo): Promise<number>;
59
+ export { HELP as HELP_TEXT, commandScan, commandAuditSkills, commandInit, commandRules, commandExplain, commandMcp };