diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml index d31bbea..7fbc2b0 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks.yml @@ -149,6 +149,24 @@ jobs: paths = ['''^backend/tests/test_tracing_guard\.py$'''] TOML fi + # The same reviewed sign-in webhook in platform history, bound to the exact + # commits that added or carried it, so any new commit on the path still fails. + if [[ "${REPOSITORY:-}" == '60xAI/ai-brain-platform' ]]; then + cat >> "$config" <<'TOML' + [[allowlists]] + description = "Reviewed sign-in webhook kept by its owner (ai-brain-platform#1601)" + condition = "AND" + targetRules = ["slack-webhook-url"] + commits = [ + "3757fbb3bfabef696925b9ee9400e1244fbb202f", + "43c569cf72e695d023c58593d3e7003a1e9bb5a9", + "9799135ec5da6b000ebbadb135052b255fd768fa", + "b83bddef41260358273cad325809e11801d2977c", + "dd8da03b435323738d8b2d93f77d108b3613af6b", + ] + paths = ['''^backend/app/api/routes/auth\.py$'''] + TOML + fi log_opts='--all --diff-merges=first-parent' if [[ "$FULL_HISTORY" != true ]]; then [[ "$BASE_SHA" =~ ^[a-f0-9]{40}$ && "$HEAD_SHA" =~ ^[a-f0-9]{40}$ ]] || { echo 'Missing valid scan range'; exit 2; } diff --git a/tests/test_secret_scan.py b/tests/test_secret_scan.py index 37d479c..ab58573 100644 --- a/tests/test_secret_scan.py +++ b/tests/test_secret_scan.py @@ -177,6 +177,32 @@ def test_pipelines_history_exceptions_only_cover_their_own_commits(self): report = json.loads((scratch/'gitleaks-findings.json').read_text()) self.assertIn({'path': filename, 'rule_id': rule}, report) + def test_platform_webhook_exception_only_covers_its_own_commits(self): + # The platform webhook exception is bound to exact historical commits, so a + # new commit on the same path must still be blocked. Synthetic, unissued value. + webhook = 'https://hooks.slack.com/services/' + 'T0SYNTHETIC/B0SYNTHETIC/' + 'abcdefghijklmnopqrstuvwx' + filename = 'backend/app/api/routes/auth.py' + with tempfile.TemporaryDirectory() as tmp: + repo = Path(tmp, 'repo'); repo.mkdir() + scratch = Path(tmp, 'runner'); scratch.mkdir() + for args in [('init', '-q'), ('config', 'user.name', 'Security Test'), + ('config', 'user.email', 'test@example.invalid')]: + self.assertEqual(run('git', *args, cwd=repo).returncode, 0) + target = repo / filename + target.parent.mkdir(parents=True) + target.write_text(f'URL = "{webhook}"\n') + self.commit(repo, 'Synthetic webhook on the excepted path') + env = os.environ | {'RUNNER_TEMP': str(scratch), + 'GITHUB_STEP_SUMMARY': str(scratch/'summary'), + 'GITHUB_OUTPUT': str(scratch/'output'), + 'FULL_HISTORY': 'true', 'BASE_SHA': '', 'HEAD_SHA': '', + 'REPOSITORY': '60xAI/ai-brain-platform'} + result = run('bash', '-c', scan_script(), cwd=repo, env=env) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn('result=10', (scratch/'output').read_text()) + report = json.loads((scratch/'gitleaks-findings.json').read_text()) + self.assertIn({'path': filename, 'rule_id': 'slack-webhook-url'}, report) + def commit(self, repo, message): self.assertEqual(run('git', 'add', '.', cwd=repo).returncode, 0) self.assertEqual(run('git', 'commit', '-qm', message, cwd=repo).returncode, 0)