feat(security): C1 broaden token markers + scan untracked; C3 resolveVault util
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d2b208b867
commit
aa87a85d9b
@@ -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 (machine paths, IPs, personal/project names) that must never ship publicly.
|
||||||
PRIVATE_MARKERS='/Users/fil|72\.56|root@|Полезные знания|_ВХОДЯЩИЕ|TODOCUPS|ПКК|legal-practice|Adventure Book|AthenaOS|Филипп'
|
PRIVATE_MARKERS='/Users/fil|72\.56|root@|Полезные знания|_ВХОДЯЩИЕ|TODOCUPS|ПКК|legal-practice|Adventure Book|AthenaOS|Филипп'
|
||||||
# Token-like values (GitHub OAuth, OpenAI/Anthropic-style sk-, Slack xox*).
|
# Token-like values across common providers. Require realistic lengths and a
|
||||||
# Require realistic lengths and a non-word boundary before `sk-` to avoid
|
# non-word boundary before `sk-` to avoid false positives like `risk-or-x`.
|
||||||
# false positives such as `risk-or-verification`.
|
# Covers: GitHub OAuth/PAT (gho_/ghp_/ghu_/ghs_/ghr_), OpenAI/Anthropic sk-,
|
||||||
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,}'
|
# 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
|
# 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.
|
# 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
|
TRACKED_ONLY=1
|
||||||
fi
|
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() {
|
tracked_files() {
|
||||||
local files=()
|
local files=()
|
||||||
while IFS= read -r -d '' file; do
|
while IFS= read -r -d '' file; do
|
||||||
[ "$file" = "scripts/check-public-release.sh" ] && continue
|
[ "$file" = "scripts/check-public-release.sh" ] && continue
|
||||||
files+=("$ROOT/$file")
|
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[@]}"
|
printf '%s\0' "${files[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 <path> 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 <path>. Canon default is ~/Мозг.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return vault
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user