safe-anything 1.1.0 → 1.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
@@ -20,8 +20,8 @@ Every finding comes with the line, the reason and the fix.</p>
20
20
  <a href="https://github.com/erkamyaman/safe-anything"><img src="https://img.shields.io/github/stars/erkamyaman/safe-anything?style=social" alt="GitHub stars"></a>
21
21
  </p>
22
22
 
23
- <p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 92 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>
24
- Made in Türkiye 🇹🇷 by <a href="https://github.com/erkamyaman">erKam Yaman</a>, who also made <a href="https://github.com/erkamyaman/rust-anything">rust-anything</a> · <a href="https://github.com/sponsors/erkamyaman">❤️ Sponsor me</a> · Sponsored by <a href="https://coderabbit.link/er-kam">CodeRabbit</a></p>
23
+ <p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 112 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>
24
+ Made in Türkiye 🇹🇷 by <a href="https://github.com/erkamyaman">erKam Yaman</a>, who also made <a href="https://github.com/erkamyaman/rust-anything">rust-anything</a> · <a href="https://github.com/sponsors/erkamyaman">❤️ Sponsor me</a> · Sponsored by <a href="https://coderabbit.link/er-kam">CodeRabbit</a> and <a href="https://www.atakdomain.com/">Atak Domain</a></p>
25
25
 
26
26
  <p align="center">
27
27
  <img src="docs/assets/terminal.gif" alt="safe-anything scans OWASP Juice Shop: 1,195 files in 0.03 s, 67 findings including the SQL injection in routes/login.ts, eval in routes/userProfile.ts, seeded passwords and a token in localStorage. Then it scans an AI agent setup: a GitHub token in .mcp.json, bypassPermissions, pre-approved Bash, curl piped to sh in a hook, a skill that reads ~/.ssh, invisible Unicode, unpinned MCP servers." width="820">
@@ -33,11 +33,11 @@ Made in Türkiye 🇹🇷 by <a href="https://github.com/erkamyaman">erKam Yaman
33
33
  <tr>
34
34
  <td width="25%" valign="top">
35
35
  <b>Your code</b><br>
36
- SQL and command injection, XSS, <code>eval</code>, SSRF, path traversal, unsafe deserialization, weak crypto. Nine languages and SQL.
36
+ SQL and command injection, XSS, <code>eval</code>, SSRF, path traversal, unsafe deserialization, weak crypto. Ten languages and SQL.
37
37
  </td>
38
38
  <td width="25%" valign="top">
39
39
  <b>Your secrets</b><br>
40
- Cloud and AI keys, tokens, private keys, passwords, and <code>.env</code> mistakes: committed env files, real values in <code>.env.example</code>, secrets behind <code>NEXT_PUBLIC_</code> or <code>VITE_</code>. Always redacted in the output.
40
+ Cloud and AI keys, tokens, private keys, passwords, and <code>.env</code> mistakes: committed env files, real values in <code>.env.example</code>, secrets behind <code>NEXT_PUBLIC_</code> or <code>VITE_</code>. The secrets it recognises are masked in the output.
41
41
  </td>
42
42
  <td width="25%" valign="top">
43
43
  <b>Your stack</b><br>
@@ -58,7 +58,11 @@ safe-anything .
58
58
  ```
59
59
 
60
60
  That's it. No config, no account, no upload. It exits with 1 when something high or critical is
61
- found, so it works as a pre-commit or CI check as is.
61
+ found, so it works as a pre-commit or CI check as is. It exits with 2 when the scan did not finish:
62
+ the dependency check failed (OSV.dev unreachable, blocked or timed out), a lockfile was too large
63
+ or binary to read, or a file or folder could not be read. The report then says "the scan did not
64
+ finish" and names why, instead of "No problems found." `--fail-on never` keeps the exit code 0 and
65
+ still prints the reason.
62
66
 
63
67
  ```bash
64
68
  safe-anything . --json # machine-readable report
@@ -71,23 +75,40 @@ safe-anything . --include-tests # also report findings in tests and fixtures
71
75
  safe-anything --list-rules
72
76
  ```
73
77
 
74
- - `.gitignore` is respected. List more paths in `.safe-anything-ignore`; it only adds to what is
75
- skipped, it cannot bring back what is listed below.
76
- - These are never scanned, and the report only counts the files it did scan:
78
+ - `.gitignore` files inside the folder you scan are respected, nested ones too. Ignore files outside
79
+ it are not used: a `.gitignore` above the scanned folder, `.ignore`, `.git/info/exclude` and your
80
+ global gitignore never hide a finding. A file that git tracks but `.gitignore` also lists (a `.env`
81
+ committed before it was ignored) is scanned when `git` is installed and the folder is a repository.
82
+ List more paths in `.safe-anything-ignore`, in the scanned folder or below it; it only adds to what
83
+ is skipped, it cannot bring back a path `.gitignore` lists or what is listed below.
84
+ - `safe-anything mcp` starts the MCP server. To scan a folder that is called `mcp`, write `./mcp`.
85
+ - These are never scanned when found inside the folder you scan, and the report only counts the files it did scan.
86
+ Name one of the folders as the path itself (`safe-anything build/`) and it is scanned; the file rules below still apply:
77
87
  - folders `.git`, `node_modules`, `target`, `vendor`, `dist`, `build`, `.next`, `.venv`, `venv`,
78
88
  `__pycache__`, `Pods`, `.gradle` and `.claude/worktrees`, so generated code in `build/` is
79
89
  not checked
80
- - any file over 2 MB, lockfiles included, so a lockfile that large gets no dependency check
90
+ - any file over 2 MB. Lockfiles are read up to 64 MB, for the dependency check only (no code rules
91
+ past 2 MB); a larger one is named in the report as not checked
81
92
  - `*.min.js`, `*.map`, `*.jsonl` and `*.log`
82
93
  - binary files: images, fonts, archives, media and compiled files by their extension (`.png`, `.woff2`,
83
94
  `.zip`, `.mp4`, `.class`, ...), and any other file with a zero byte in its first 8 KB. A text file
84
- saved under one of those extensions is not scanned either.
95
+ saved under one of those extensions is not scanned either. UTF-16 files that start with a byte
96
+ order mark (PowerShell's `>` output) are decoded and scanned, and a UTF-8 byte order mark is
97
+ skipped; UTF-32 is not read.
85
98
  - `*.lock` files get the dependency check but no code rules
86
99
  - `safe-anything:ignore` in a comment silences that line (or the next one). Follow it with rule ids,
87
100
  `// safe-anything:ignore code.weak-hash, code.eval`, to silence only those rules. An id that is no
88
101
  rule (a typo) silences nothing, so the finding stays in the report.
89
102
  - In tests, specs and fixtures only real provider keys and private keys count, unless you pass
90
103
  `--include-tests`.
104
+ - Env files are `.env`, `.env.*`, `*.env` (`prod.env`), `*.env.example` and `.envrc`. A value in a
105
+ variable named like a secret (`*_PASSWORD`, `*_SECRET`, `*_TOKEN`, `*_API_KEY`) is reported from 8
106
+ characters on, in other credential-like names from 16; placeholders, URLs without a password and
107
+ short values made only of digits or only of lowercase letters are skipped. `NEXT_PUBLIC_`, `VITE_` and `EXPO_PUBLIC_` variables
108
+ whose name says secret, password, private key or an API, access, auth, admin, bearer, refresh or
109
+ session token are reported, because the build ships them to the browser. Plain `*_KEY` and
110
+ `*_TOKEN` names with a public prefix (`NEXT_PUBLIC_SUPABASE_ANON_KEY`, `VITE_MAPBOX_TOKEN`) are
111
+ not reported, on purpose: those keys are public by design.
91
112
 
92
113
  On a codebase that already has findings, save them once and fail only on new ones:
93
114
 
@@ -96,25 +117,31 @@ safe-anything . --write-baseline .safe-anything-baseline.json
96
117
  safe-anything . --baseline .safe-anything-baseline.json
97
118
  ```
98
119
 
99
- The baseline holds each finding's rule, path and a SHA-256 of its line, not the line itself, so it
100
- can be committed. A finding counts as known when all three match, wherever the line moved to. Paths
101
- are relative to the scanned folder, so scan the same folder you saved it from. Only files written by
102
- `--write-baseline` are read, not `--json` reports. Review changes to it like code: an entry added to
103
- it hides that finding.
120
+ The baseline holds each finding's rule, path and a SHA-256 of its whole line, not the line itself,
121
+ so it can be committed. Any secret on the line is masked as in the report before it is hashed, so
122
+ the hash of a short password cannot be guessed from the file; the other side of that is that a
123
+ secret rotated to a new value with the same first characters, on an otherwise identical line, stays
124
+ hidden. A finding counts as known when all three match, wherever the line moved to, and an edit
125
+ anywhere else on the line brings it back. Identical lines count one entry each. Paths are relative
126
+ to the scanned folder, so scan the same folder you saved it from. A baseline written by an earlier
127
+ release still works (it hashed the first 160 characters of the line); write a new one to get the
128
+ whole-line hash. `--write-baseline` refuses to write after a scan that did not finish, because the
129
+ file would leave findings out. Only files written by `--write-baseline` are read, not `--json`
130
+ reports. Review changes to it like code: an entry added to it hides that finding.
104
131
 
105
132
  ## What it finds
106
133
 
107
- 92 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
134
+ 112 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
108
135
  The full list is in [docs/rules.md](docs/rules.md).
109
136
 
110
137
  | | |
111
138
  | --- | --- |
112
- | **Code** | SQL injection, command injection, XSS (`innerHTML`, `dangerouslySetInnerHTML`, `v-html`, `echo $_GET`, `raw`), `eval` and `new Function`, path traversal, file inclusion from request input, SSRF, open redirects, unsafe deserialization (pickle, `yaml.load`, `ObjectInputStream`, `BinaryFormatter`, `unserialize`, `Marshal`), TLS checks turned off, MD5/SHA-1, DES/RC4/ECB, JWT `none`, template injection, CORS `*`, debug mode, insecure cookies, `Math.random` tokens, `GRANT ALL` and plain-text passwords in SQL files. JS/TS, Python, Go, Java, Kotlin, PHP, Ruby, C#, SQL |
113
- | **Secrets** | AWS (key ids and secret access keys), GitHub, GitLab, Slack, Stripe, Shopify, npm, PyPI, OpenAI, Anthropic, Groq, Google, Hugging Face, Mailgun, SendGrid, Telegram, DigitalOcean and Twilio keys, Google OAuth client secrets, Slack and Discord webhook URLs, private keys (also inside service-account JSON), passwords in code, credentials in connection strings, committed `.env` files, real values in `.env.example`, a `.gitignore` that misses `.env`, secrets behind public prefixes (`NEXT_PUBLIC_`, `VITE_`, `EXPO_PUBLIC_`) that ship in the client bundle |
139
+ | **Code** | SQL injection, command injection, XSS (`innerHTML`, `dangerouslySetInnerHTML`, `v-html`, `echo $_GET`, `raw`), `eval` and `new Function`, path traversal, file inclusion from request input, SSRF, open redirects, unsafe deserialization (pickle, `yaml.load`, `ObjectInputStream`, `BinaryFormatter`, `unserialize`, `Marshal`), TLS checks turned off, MD5/SHA-1, DES/RC4/ECB, JWT `none`, template injection, CORS `*`, debug mode, insecure cookies, `Math.random` tokens, `GRANT ALL` and plain-text passwords in SQL files. JS/TS, Python, Go, Rust, Java, Kotlin, Scala, PHP, Ruby, C#, SQL |
140
+ | **Secrets** | AWS (key ids and secret access keys), GitHub, GitLab, Slack, Stripe, Shopify, npm, PyPI, RubyGems, Docker Hub, OpenAI, Anthropic, Groq, Google, Hugging Face, Mailgun, SendGrid, Telegram, DigitalOcean, Heroku, Fly.io, Databricks, Perplexity, OpenRouter, Notion, Twilio, Linear, Prefect, Postman, Pulumi, HCP Terraform, Sentry, New Relic, Supabase, Grafana and Doppler keys, Google OAuth client secrets, Slack and Discord webhook URLs, private keys (also inside service-account JSON) and age keys, passwords in code, credentials in connection strings, committed `.env` files, real values in `.env.example`, a `.gitignore` that misses `.env`, secrets behind public prefixes (`NEXT_PUBLIC_`, `VITE_`, `EXPO_PUBLIC_`) that ship in the client bundle |
114
141
  | **Agent setups** | `bypassPermissions` and `--dangerously-skip-permissions`, pre-approved `Bash`, `enableAllProjectMcpServers`, MCP servers run with unpinned `npx`/`uvx`/`docker`, MCP tokens in plain text, remote MCP over `http://`, `curl \| sh` in hooks and skills, prompt-injection text, skills that read `~/.ssh` or cloud credentials, invisible Unicode in instructions. [More](docs/agent-setups.md) |
115
142
  | **Mobile** | Android `debuggable`, `allowBackup`, cleartext traffic, exported content providers, WebView file access and JS bridges, world-readable files; iOS ATS turned off; tokens in UserDefaults, SharedPreferences, AsyncStorage or localStorage |
116
143
  | **Config** | Docker (unpinned base, root, secrets in `ENV`, `ADD <url>`), `curl \| sh` in scripts, Dockerfiles and workflow `run:` steps, GitHub Actions (`pull_request_target`, `write-all`, actions on `@main`, script injection from PR titles), privileged containers, `hostNetwork`, Terraform (open ingress, public buckets, S3 public access blocks turned off, public or unencrypted databases), nginx autoindex, TLS 1.0/1.1 |
117
- | **Dependencies** | every locked version in `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `pnpm-lock.yaml`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.lock`, `pdm.lock`, `Pipfile.lock`, `go.mod`, `Gemfile.lock`, `composer.lock` and `pubspec.lock`, checked against [OSV.dev](https://osv.dev), with the nearest fixed version |
144
+ | **Dependencies** | every locked version in `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.lock`, `pdm.lock`, `Pipfile.lock`, `go.mod`, `Gemfile.lock`, `composer.lock`, `pubspec.lock` and `Package.resolved`, checked against [OSV.dev](https://osv.dev), with the nearest fixed version |
118
145
 
119
146
  <p align="center">
120
147
  <img src="docs/assets/nextjs-public-env.gif" alt="safe-anything on the with-mqtt-js example from the Next.js repository: 2 high findings, an MQTT password read from a NEXT_PUBLIC_ variable in app/page.tsx and environment.d.ts, which Next.js ships in the client bundle." width="820">
@@ -139,13 +166,14 @@ Or, as a Claude Code plugin with the skill that tells the agent how to triage an
139
166
  /plugin install safe-anything@safe-anything
140
167
  ```
141
168
 
142
- Tools: `scan` (path, offline, severity, include_tests) and `list_rules`. The skill is in
169
+ Tools: `scan` (path, offline, severity, include_tests) and `list_rules`. A `scan` that did not finish
170
+ answers with `isError: true` and an `incomplete` list, not an empty result. The skill is in
143
171
  [skills/safe-anything](skills/safe-anything/SKILL.md).
144
172
 
145
173
  ## In CI
146
174
 
147
175
  ```yaml
148
- - uses: erkamyaman/safe-anything@v1.1.0
176
+ - uses: erkamyaman/safe-anything@v1.2.1
149
177
  with:
150
178
  fail-on: high
151
179
  # baseline: .safe-anything-baseline.json # fail only on findings not in it
@@ -155,7 +183,9 @@ Tools: `scan` (path, offline, severity, include_tests) and `list_rules`. The ski
155
183
  sarif_file: safe-anything.sarif
156
184
  ```
157
185
 
158
- Findings then show up in the repository's Security tab and on pull requests.
186
+ Findings then show up in the repository's Security tab and on pull requests. The job fails with
187
+ exit code 2, after the SARIF file is written, when the scan did not finish (OSV.dev unreachable, a
188
+ file that cannot be read); `fail-on: never` keeps the job green and still prints the reason.
159
189
 
160
190
  ## Measured
161
191
 
@@ -173,7 +203,7 @@ doing.
173
203
  | [anthropics/skills](https://github.com/anthropics/skills) | 392 | 6 | `innerHTML` in local review pages (5), `shell=True` in a script that runs commands by design |
174
204
  | [vercel-labs/agent-skills](https://github.com/vercel-labs/agent-skills) | 439 | 0 | |
175
205
  | [rust-anything](https://github.com/erkamyaman/rust-anything) | 3,134 | 6 | `innerHTML` in GIF demo pages (5), an action on `@master` |
176
- | safe-anything itself | 53 | 0 | checked in CI on every push |
206
+ | safe-anything itself | 83 | 0 | checked in CI on every push |
177
207
 
178
208
  <p align="center">
179
209
  <img src="docs/assets/express-clean.gif" alt="safe-anything on expressjs/express: no problems found, 216 files scanned in 0.03 s." width="820">
@@ -194,7 +224,7 @@ lockfile listed under Dependencies. Nothing is executed. The only network call i
194
224
  names and versions to OSV.dev ([privacy](docs/privacy.md)).
195
225
 
196
226
  It finds known patterns; it does not trace data through your program. A clean scan means none of
197
- these 92 problems were found, not that the code is safe. [Design notes](docs/adr).
227
+ these 112 problems were found, not that the code is safe. [Design notes](docs/adr).
198
228
 
199
229
  ## Credits
200
230
 
@@ -218,6 +248,8 @@ these 92 problems were found, not that the code is safe. [Design notes](docs/adr
218
248
 
219
249
  <p align="center"><sub>Your safety comes first: sponsors get a logo and a link here, nothing more. No paid recommendations and no setup guides for third-party AI API resellers, so nothing here steers your code, keys or data somewhere you didn't choose.</sub></p>
220
250
 
251
+ <p align="center"><sub><b>There is no safe-anything coin or token.</b> Anyone offering or selling one is not affiliated with this project or with me, so don't trust anything shady or dodgy that uses these names.</sub></p>
252
+
221
253
  <p align="center">
222
254
  <a href="https://coderabbit.link/er-kam">
223
255
  <picture>
@@ -227,11 +259,20 @@ these 92 problems were found, not that the code is safe. [Design notes](docs/adr
227
259
  </a>
228
260
  </p>
229
261
 
262
+ <p align="center">
263
+ <a href="https://www.atakdomain.com/">
264
+ <picture>
265
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/sponsors/domain-dark.svg">
266
+ <img src="docs/assets/sponsors/domain-light.svg" width="800" alt="Domain sponsor: Atak Domain">
267
+ </picture>
268
+ </a>
269
+ </p>
270
+
230
271
  <p align="center">
231
272
  <a href="https://github.com/sponsors/erkamyaman">
232
273
  <picture>
233
274
  <source media="(prefers-color-scheme: dark)" srcset="docs/assets/sponsors/sponsors-dark.svg">
234
- <img src="docs/assets/sponsors/sponsors-light.svg" width="800" alt="Sponsors: Santosh Yadav, Hakan Soytürk, Ali Yilmaz, Ashley Hunter, Fatih Uzuntaş, bugrcvi">
275
+ <img src="docs/assets/sponsors/sponsors-light.svg" width="800" alt="Sponsors: Santosh Yadav, Hakan Soytürk, Ali Yilmaz, Ashley Hunter, Fatih Uzuntaş, bugrcvi, starwish.ing, omerrgoren">
235
276
  </picture>
236
277
  </a>
237
278
  </p>
@@ -241,6 +282,13 @@ these 92 problems were found, not that the code is safe. [Design notes](docs/adr
241
282
  <a href="https://buymeacoffee.com/erkamyaman"><img src="https://img.shields.io/badge/Buy_me_a_coffee-%E2%98%95-FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=black" alt="Buy me a coffee"></a>
242
283
  </p>
243
284
 
285
+ ## Star history
286
+
287
+ <picture>
288
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/star-history-dark.svg">
289
+ <img src="docs/assets/star-history.svg" width="800" alt="Cumulative GitHub stars for safe-anything over time">
290
+ </picture>
291
+
244
292
  ## Contributing
245
293
 
246
294
  The most useful contribution is a fixture: a few lines safe-anything gets wrong. See
@@ -12,13 +12,19 @@ if (!fs.existsSync(bin)) {
12
12
  `safe-anything: no prebuilt binary for ${key}.\n` +
13
13
  'Install it with Cargo instead: cargo install safe-anything',
14
14
  )
15
- process.exit(1)
15
+ process.exit(2)
16
16
  }
17
17
 
18
18
  const result = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' })
19
19
  if (result.error) {
20
20
  console.error(`safe-anything: ${result.error.message}`)
21
- process.exit(1)
21
+ if (result.error.code === 'ENOENT') {
22
+ console.error(
23
+ 'The prebuilt binary could not start (on Alpine and other musl systems it needs glibc).\n' +
24
+ 'Install it with Cargo instead: cargo install safe-anything',
25
+ )
26
+ }
27
+ process.exit(2)
22
28
  }
23
29
  if (result.signal) {
24
30
  process.kill(process.pid, result.signal)
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safe-anything",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Find the holes before someone else does. One fast command scans code, secrets, mobile and cloud config, dependencies and AI agent setups. 100% Rust.",
5
5
  "keywords": [
6
6
  "security",