@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 16:45 UTC

arena/2d4eda07-aram
add-index-html-10623938925177053894 arena/094f314c-aram arena/2d4eda07-aram chatgpt-phase1b2-autopilot codex/adr-future-connectors-pi-v1 codex/aram-account-note-source-trace-20261031 codex/aram-actions-node24-maintenance-20261031 codex/aram-analyst-review-workbook-20261031 codex/aram-bs-candidate-statement-20261031 codex/aram-cash-flow-direct-candidate-20261031 codex/aram-clean-reference-year-integrity-20261030 codex/aram-cross-statement-controls-20261031 codex/aram-equity-changes-candidate-20261031 codex/aram-five-statement-cli-20261031 codex/aram-five-statement-integration-20261031 codex/aram-five-statement-orchestrator-20261031 codex/aram-gate3-coverage-target-guard-20261030 codex/aram-gate3-hidden-xlsx-guard-20261030 codex/aram-gate3-integration-validation-20261030 codex/aram-gate3-mapping-change-preview-20261030 codex/aram-gate3-stale-note-guard-20261030 codex/aram-income-statement-candidate-20261031 codex/aram-manifest-referential-integrity-20261031 codex/aram-mapping-source-parser-20261101 codex/aram-multidimensional-mapping-20261101 codex/aram-multistatement-mapping-20261031 codex/aram-pipeline-manifest-schema-20261031 codex/aram-readonly-mapping-coverage-20261031 codex/aram-reconciliation-review-gate-20261031 codex/aram-same-flush-fiscal-lock-20261030 codex/aram-synthetic-windows-demo-20261031 codex/aram-trial-balance-diagnostic-20261031 codex/aram-windows-background-detail-search-20261031 codex/aram-windows-detail-review-20261031 codex/aram-windows-five-statement-pilot-20261031 codex/aram-windows-statement-figures-20261031 codex/gate-2a-pilot-workbook codex/gate-2a-pilot-workbook-6864754244772568979 codex/gate3-authenticated-principal-boundary-20261030 codex/gate3-authored-draft-staging-20261030 codex/gate3-carry-forward-preview-20261023 codex/gate3-draft-staging-audit-20261030 codex/gate3-mapping-batch-freshness-20261030 codex/gate3-mapping-batch-review-20261030 codex/gate3-mapping-core codex/gate3-mapping-coverage-20261023 codex/gate3-mapping-excel-20261023 codex/gate3-note-mapping-review-20261023 codex/gate3-signed-year-scope-20261030 codex/gate3-unapproved-proposal-storage-20261030 codex/payvast-mapping-discovery-20261023 codex/phase-2a-backend-foundation codex/phase-2b-post-merge-record codex/phase-2b-source-registration codex/phase-2b-source-registration-12955190277775369594 codex/post-gate2a-control-reconciliation codex/post-pr18-acceptance-record codex/project-control-foundation codex/t1-repo-hygiene-20261023 codex/t2-ci-hardening-20261023 codex/t3-explicit-migrations-20261023 codex/t6a-readonly-diagnostics-20261023 codex/v1-01-safety-gate-hardening codex/v1-year-isolation-followup-20261023 codex/windows-native-pilot-shell-20261030 dependabot/github_actions/actions/checkout-7 dependabot/github_actions/actions/setup-node-6 dependabot/github_actions/actions/setup-python-7 dependabot/github_actions/actions/upload-artifact-7 dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1 dependabot/npm_and_yarn/frontend/vite-8.4.0 dependabot/npm_and_yarn/frontend/vitest-5.1.2 dependabot/pip/backend/mypy-gte-1.13-and-lt-3 dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8 dependabot/pip/backend/setuptools-gte-75-and-lt-85 docs/aram-master-control-plan-20261111 docs/aram-roadmap-dashboard-20261030 docs/financial-statement-reconciliation-1402-1404-20261110 feat/gate3-governed-mapping-20261101 feat/gate3-package9-1-security-20261103 feat/gate3-package9-isolated-20261103 fix/password-unicode-validation-20261111 governance/aram-5-1-3-controls-20261030 governance/role-based-operating-model jules-1168663913887856558-73b8a885 jules-gate-2b-mapping-workflow-foundation-4137724387867065330 phase-1b1-audit-report-7365389436990903239 phase-2a-backend-foundation-10237597358138521261 phase1b2-postmerge-metadata-fix refactor/drg-parent-year-id-15088443704684163304 source-data-cleanup
py 122 lines 4.2 KB
Raw
1 #!/usr/bin/env python3
2 """Churn-free secret gate: fail only on secrets that are NOT baselined.
3
4 Runs `detect-secrets scan` (respects .gitignore) over the working tree and
5 compares every finding — as a (file, plugin type, hashed line) triple — with
6 the committed `.secrets.baseline`. Only *new* triples fail the gate, so
7 editing a file that already holds a reviewed false positive (test fixtures,
8 the CI PostgreSQL dummy password, documentation SHA-256 hashes) never
9 produces churn. Line-number drift is deliberately ignored.
10
11 False positives in *new* code are escaped inline with the native detect-secrets
12 marker: # pragma: allowlist secret (or: # pragma: allowlist nextline secret)
13
14 The baseline file excludes itself from the scan (`--exclude-files`): its
15 `hashed_secret` values and `"hashed_secret":` keys are, by construction,
16 secret-shaped, so scanning it would report 22 self-referential findings the
17 moment the file becomes tracked. The baseline is a reviewed collection of
18 findings, not new leakage.
19
20 After an intentional, reviewed change to what is allowed, regenerate:
21 detect-secrets scan --exclude-files '^\\.secrets\\.baseline$' > .secrets.baseline
22 and review the diff before committing (never blanket-regenerate to silence
23 a real secret).
24
25 Usage (local or CI):
26 pip install detect-secrets
27 python scripts/check_secrets_baseline.py
28
29 Exit codes: 0 = no new secrets, 1 = new secrets found, 2 = setup problem.
30 """
31
32 from __future__ import annotations
33
34 import json
35 import subprocess
36 import sys
37 from pathlib import Path
38 from typing import Any
39
40 ROOT = Path(__file__).resolve().parent.parent
41 BASELINE = ROOT / ".secrets.baseline"
42 # The baseline must not be scanned as a normal file: its hashed_secret values
43 # and keys are secret-shaped by construction (see module docstring).
44 BASELINE_EXCLUDE = r"^\.secrets\.baseline$"
45
46
47 def _triples(results: dict[str, Any]) -> set[tuple[str, str, str]]:
48 return {
49 (filename, secret["type"], secret["hashed_secret"])
50 for filename, secrets in results.items()
51 for secret in secrets
52 }
53
54
55 def main() -> int:
56 if not BASELINE.exists():
57 print(
58 "ERROR: .secrets.baseline is missing.\n"
59 "Generate it with: detect-secrets scan "
60 "--exclude-files '^\\.secrets\\.baseline$' > .secrets.baseline\n"
61 "and commit the reviewed baseline.",
62 file=sys.stderr,
63 )
64 return 2
65 try:
66 baseline = json.loads(BASELINE.read_text(encoding="utf-8"))
67 except json.JSONDecodeError as exc:
68 print(f"ERROR: .secrets.baseline is not valid JSON: {exc}", file=sys.stderr)
69 return 2
70
71 try:
72 scan = subprocess.run(
73 ["detect-secrets", "scan", "--exclude-files", BASELINE_EXCLUDE],
74 cwd=ROOT,
75 capture_output=True,
76 text=True,
77 check=False,
78 )
79 except FileNotFoundError:
80 print(
81 "ERROR: detect-secrets is not installed. Run: pip install detect-secrets",
82 file=sys.stderr,
83 )
84 return 2
85 if scan.returncode != 0:
86 print(f"ERROR: detect-secrets scan failed:\n{scan.stderr}", file=sys.stderr)
87 return 2
88
89 fresh = json.loads(scan.stdout)
90 known = _triples(baseline.get("results", {}))
91 current = _triples(fresh.get("results", {}))
92 new = sorted(current - known)
93
94 if not new:
95 print(
96 f"Secret gate OK: {len(current)} baselined finding(s), 0 new."
97 )
98 return 0
99
100 print(f"ERROR: {len(new)} new secret finding(s) not in .secrets.baseline:", file=sys.stderr)
101 results = fresh.get("results", {})
102 for filename, secret_type, hashed in new:
103 line = next(
104 (
105 s.get("line_number", "?")
106 for s in results.get(filename, [])
107 if s["type"] == secret_type and s["hashed_secret"] == hashed
108 ),
109 "?",
110 )
111 print(f" {filename}:{line} [{secret_type}]", file=sys.stderr)
112 print(
113 "\nFix: remove the secret, or mark a reviewed false positive inline with\n"
114 "`# pragma: allowlist secret`. Do not regenerate the baseline to silence\n"
115 "a real secret.",
116 file=sys.stderr,
117 )
118 return 1
119
120
121 if __name__ == "__main__":
122 sys.exit(main())