From aa87a85d9b4c06be95d2ae037bad35633b47c536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=80=D1=83=D0=B1=D0=B8=D0=BD=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BF=D0=BF?= <289370046+zarubinphil@users.noreply.github.com> Date: Thu, 18 Jun 2026 16:18:52 +0300 Subject: [PATCH] feat(security): C1 broaden token markers + scan untracked; C3 resolveVault util Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/check-public-release.sh | 16 +++++++++++----- scripts/mnemazine-paths.mjs | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 scripts/mnemazine-paths.mjs diff --git a/scripts/check-public-release.sh b/scripts/check-public-release.sh index 683d37b..498b976 100755 --- a/scripts/check-public-release.sh +++ b/scripts/check-public-release.sh @@ -5,10 +5,12 @@ ROOT="${1:-$(cd "$(dirname "$0")/.." && pwd)}" # Private markers (machine paths, IPs, personal/project names) that must never ship publicly. PRIVATE_MARKERS='/Users/fil|72\.56|root@|Полезные знания|_ВХОДЯЩИЕ|TODOCUPS|ПКК|legal-practice|Adventure Book|AthenaOS|Филипп' -# Token-like values (GitHub OAuth, OpenAI/Anthropic-style sk-, Slack xox*). -# Require realistic lengths and a non-word boundary before `sk-` to avoid -# false positives such as `risk-or-verification`. -TOKEN_MARKERS='gho_[A-Za-z0-9_]{20,}|(^|[^A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,}' +# Token-like values across common providers. Require realistic lengths and a +# non-word boundary before `sk-` to avoid false positives like `risk-or-x`. +# Covers: GitHub OAuth/PAT (gho_/ghp_/ghu_/ghs_/ghr_), OpenAI/Anthropic sk-, +# Slack xox*, AWS access key (AKIA/ASIA), GitLab PAT (glpat-), Google API +# (AIza), JWT (eyJ.header.payload), and PEM private-key blocks. +TOKEN_MARKERS='gh[opusr]_[A-Za-z0-9_]{20,}|(^|[^A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,}|(AKIA|ASIA)[A-Z0-9]{16}|glpat-[A-Za-z0-9_-]{20,}|AIza[A-Za-z0-9_-]{30,}|eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}|-----BEGIN [A-Z ]*PRIVATE KEY-----' # Pick a scanner. Prefer ripgrep; fall back to POSIX grep so the gate still runs # on machines without rg. A missing scanner must HARD-FAIL, never silently pass. @@ -26,12 +28,16 @@ if git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then TRACKED_ONLY=1 fi +# Files that could ship publicly: everything git tracks PLUS untracked files +# not covered by .gitignore (a staged-but-uncommitted secret would otherwise +# slip past a tracked-only scan). Ignored runtime noise (.mnemazine, backups) +# is correctly skipped — it never reaches a public push. tracked_files() { local files=() while IFS= read -r -d '' file; do [ "$file" = "scripts/check-public-release.sh" ] && continue files+=("$ROOT/$file") - done < <(git -C "$ROOT" ls-files -z) + done < <(git -C "$ROOT" ls-files -z --cached --others --exclude-standard) printf '%s\0' "${files[@]}" } diff --git a/scripts/mnemazine-paths.mjs b/scripts/mnemazine-paths.mjs new file mode 100644 index 0000000..1775456 --- /dev/null +++ b/scripts/mnemazine-paths.mjs @@ -0,0 +1,20 @@ +import fsSync from 'node:fs' +import path from 'node:path' +import os from 'node:os' + +// Single source of truth for the live knowledge vault. +// Canon (per personal constitution structure.md): ~/Мозг. +// Override with --vault or MNEMAZINE_VAULT. Fail loud when the resolved +// directory does not exist — silently writing into a missing/wrong tree loses data. +export const DEFAULT_VAULT = path.join(os.homedir(), 'Мозг') + +export function resolveVault({ cli, env = process.env.MNEMAZINE_VAULT, requireExists = true } = {}) { + const vault = path.resolve(cli || env || DEFAULT_VAULT) + if (requireExists && !fsSync.existsSync(vault)) { + throw new Error( + `Vault not found: ${vault}\n` + + `Set MNEMAZINE_VAULT or pass --vault . Canon default is ~/Мозг.`, + ) + } + return vault +}