|
1 | 1 | // Single source of truth for the miner package's secret-shape detector. |
2 | 2 | // |
3 | | -// scripts/check-miner-package.mjs uses this to reject any packed miner file that embeds a secret-like value, and |
4 | | -// the AMS MCP contract test (test/unit/miner-mcp-contract.test.ts) reuses the SAME pattern to assert no MCP tool |
5 | | -// response ever leaks one — importing it here rather than hand-duplicating the regex keeps the two byte-for-byte in |
6 | | -// sync instead of relying on manual vigilance. |
7 | | -export const FORBIDDEN_CONTENT = |
8 | | - /(BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY|github_pat_[A-Za-z0-9_]+|gh[pousr]_[A-Za-z0-9_]+|gts_[0-9a-f]{64}|[A-Z0-9_]*(TOKEN|SECRET|PRIVATE_KEY)=)/; |
| 3 | +// scripts/check-miner-package.mjs + scripts/check-mcp-package.mjs use this to reject any packed miner/mcp file |
| 4 | +// that embeds a secret-like value, and the AMS MCP contract test (test/unit/miner-mcp-contract.test.ts) reuses |
| 5 | +// the SAME pattern to assert no MCP tool response ever leaks one — importing it here rather than hand-duplicating |
| 6 | +// the regex keeps every consumer byte-for-byte in sync instead of relying on manual vigilance. |
| 7 | +// |
| 8 | +// The concrete provider-key shapes below are hand-copied (#7433) from the exact regex bodies of the entries in |
| 9 | +// src/review/secret-patterns.ts's SECRET_PATTERNS that are in its HARD_SECRET_KINDS set (the "near-zero |
| 10 | +// false-positive" subset). They are NOT imported directly: this file is a plain `.mjs` run via `node` |
| 11 | +// (test:miner-pack / test:mcp-pack), and secret-patterns.ts is TypeScript with no runtime `.js` sibling on this |
| 12 | +// path — a runtime `import` of it from node would fail, so the exact bodies are copied per the issue's stated |
| 13 | +// fallback. `jwt`, `seed_or_mnemonic`, and `bittensor_key` are deliberately NOT included: jwt is out of scope |
| 14 | +// for #7433, and seed_or_mnemonic/bittensor_key are documented in secret-patterns.ts as weak, false-positive- |
| 15 | +// prone heuristics intentionally excluded from HARD_SECRET_KINDS (an ordinary `coldkey:` / `hotkey =` line or |
| 16 | +// the word "mnemonic" in Bittensor docs is not a leaked credential). |
| 17 | +export const FORBIDDEN_CONTENT = new RegExp( |
| 18 | + [ |
| 19 | + // Already covered before #7433 (unchanged shapes): |
| 20 | + "BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY", |
| 21 | + "github_pat_[A-Za-z0-9_]+", |
| 22 | + "gh[pousr]_[A-Za-z0-9_]+", |
| 23 | + "gts_[0-9a-f]{64}", |
| 24 | + "[A-Z0-9_]*(TOKEN|SECRET|PRIVATE_KEY)=", |
| 25 | + // Added #7433 — exact bodies from secret-patterns.ts HARD_SECRET_KINDS entries: |
| 26 | + "\\bAKIA[0-9A-Z]{16}\\b", // aws_access_key |
| 27 | + "\\bxox[baprs]-[A-Za-z0-9-]{10,}\\b", // slack_token |
| 28 | + "\\bAIza[0-9A-Za-z_-]{35}\\b", // google_api_key |
| 29 | + "\\bglpat-[0-9A-Za-z_-]{20}(?![0-9A-Za-z_-])", // gitlab_token |
| 30 | + "\\bnpm_[A-Za-z0-9]{36}\\b", // npm_token |
| 31 | + "\\b(?:sk|rk)_live_[0-9A-Za-z]{24,}\\b", // stripe_secret_key |
| 32 | + "\\bSG\\.[A-Za-z0-9_-]{22}\\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])", // sendgrid_key |
| 33 | + "\\bhf_[A-Za-z0-9]{34}\\b", // huggingface_token |
| 34 | + "\\b(?:pa|al)-[A-Za-z0-9]{20,}(?![A-Za-z0-9_-])", // voyage_api_key |
| 35 | + "\\bfc-[A-Za-z0-9]{16,}(?![A-Za-z0-9_-])", // firecrawl_api_key |
| 36 | + "\\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{20,}T3BlbkFJ[A-Za-z0-9_-]{20,}\\b", // openai_api_key |
| 37 | + "\\bsk-ant-api03-[A-Za-z0-9_-]{93}AA\\b", // anthropic_api_key |
| 38 | + ].join("|"), |
| 39 | +); |
0 commit comments