mirror of
https://github.com/elementalsouls/Claude-BugHunter.git
synced 2026-11-24 20:30:23 +01:00
* fix(cbh): triage gate — real request-target for Q1, scope-negation for Q3, clickjacking for Q7 Three false-verdict paths in the 7-Question Gate, each independently reported: - Q1 matched a bare method word anywhere in the text, so prose like "target application" (contains "get ") or "input validation" passed Q1 with no request at all. Q1 now needs a method followed by a path or URL (or curl / HTTP/1.1). Reported by @dajiaohuang (#209). - Q7's never-submit list had "click-jacking" but not "clickjacking", so the unhyphenated spelling was never killed. Reported by @Ethereal49 (#197). - Q3 answered YES on any scope/asset wording even when the finding itself said "out of scope" / "unverified". A scope/asset line carrying a negation no longer counts as in-scope evidence; non-scope lines ("Impact: unclear") still don't. Reported by @Ethereal49 (#197). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(cbh): parse finding frontmatter through a leading UTF-8 BOM A BOM (\ufeff) written by some Windows editors sits before the `---` fence, so the `^---` frontmatter regex missed it and severity/asset fell back to defaults. Strip a leading BOM in parse_finding_metadata, the shared chokepoint for every command that reads a finding, not just `cbh report`. Reported by @jazzpher (#200). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(cbh): force UTF-8 stdout so Windows cp1252 consoles don't crash cbh and setup_harness_mcp.py print the gate glyphs (check / cross / arrow / em-dash) throughout. On a Windows console (cp1252) a bare print() raised UnicodeEncodeError and the command died mid-run. Reconfigure stdout/stderr to UTF-8 at both entrypoints, the same fix engine/engine.py:main already uses, so the whole CLI is covered at one point rather than guarding every print. Reported by @Sahilkumar-r (#180). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(offensive-osint): filter h1_reference --program by team_handle, not team_id CompleteHacktivityReportIndex no longer accepts terms: {team_id: ...}, so --program silently returned nothing. Switch to query_string "team_handle:<h>", which filters correctly and still accepts sort + pagination (so --program now composes with --top-voted / --top-bounty). Also: route the lookup progress line to stderr so --json stdout stays pipeable, and reject an empty --program handle. Two independent reports converged on this fix: @roonnnnyyyyyy (#206) and @flipcyde101 (#202). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs(changelog): record the four tooling bugfixes with reporter credits Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(cbh,osint): review follow-ups — Q3 negation, Q1 markdown, CRLF, canonical handle Adversarial review of the branch surfaced five real defects: - Q3 _q3_scope_negated matched ANY line containing 'scope' plus a negation, so 'Impact: unclear scope of data exposure' wrongly killed an in-scope finding. Negation is now evaluated per line: strong phrases ('out of scope') disavow anywhere; weak words ('unknown','unclear') only on a scope/asset/ target line (the key before the colon). - Q3 negation list was space-only, so the common hyphenated 'out-of-scope' slipped through. Hyphens are normalized to spaces before matching. - Q1 required whitespace between method and path, missing the markdown a PoC is usually written in (`GET /x`, **GET** /x, GET `/x`). The separator class now allows backticks and bold/italic markers. The prose ceiling ('an attacker can get /admin') is marked, not closed — requiring HTTP/ would reject the bare 'GET /path' PoC the gate must accept. - parse_finding_metadata now also normalizes CRLF, so Windows findings (the same platform as the BOM in #200) don't skip frontmatter. - h1_reference --program queried the raw input handle; query_string is case-sensitive while TeamLookup is not, so '--program Shopify' could return nothing. lookup_program now returns the team record and main uses the canonical handle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
218 lines
7.5 KiB
Python
218 lines
7.5 KiB
Python
import argparse
|
|
import io
|
|
import re
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from contextlib import redirect_stdout
|
|
|
|
from cbh import cli
|
|
|
|
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
|
|
|
|
|
|
def _run_triage(content: str):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
p = Path(tmpdir) / "finding.md"
|
|
p.write_text(content, encoding="utf-8")
|
|
buf = io.StringIO()
|
|
with redirect_stdout(buf):
|
|
res = cli.cmd_triage(argparse.Namespace(finding=str(p)))
|
|
return res, _ANSI_RE.sub("", buf.getvalue())
|
|
|
|
|
|
class TriageGateTests(unittest.TestCase):
|
|
def test_http_request_and_curl_findings_pass(self):
|
|
samples = [
|
|
"""# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: GET /api/v1/data HTTP/1.1
|
|
- Evidence: leaked credential
|
|
""",
|
|
"""# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: POST /api/v1/data HTTP/1.1
|
|
- Evidence: leaked credential
|
|
""",
|
|
"""# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: curl http://example.com/api/v1/data
|
|
- Evidence: leaked credential
|
|
""",
|
|
]
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
for idx, content in enumerate(samples):
|
|
p = Path(tmpdir) / f"pass_{idx}.md"
|
|
p.write_text(content, encoding="utf-8")
|
|
with redirect_stdout(io.StringIO()):
|
|
res = cli.cmd_triage(argparse.Namespace(finding=str(p)))
|
|
self.assertEqual(res, 0)
|
|
|
|
def test_missing_request_evidence_fails_q1(self):
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: theoretical explanation without requests
|
|
- Evidence: leaked credential
|
|
"""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
p = Path(tmpdir) / "fail_q1.md"
|
|
p.write_text(content, encoding="utf-8")
|
|
with redirect_stdout(io.StringIO()):
|
|
res = cli.cmd_triage(argparse.Namespace(finding=str(p)))
|
|
self.assertEqual(res, 2)
|
|
|
|
def test_missing_finding_file_returns_error(self):
|
|
with redirect_stdout(io.StringIO()):
|
|
res = cli.cmd_triage(argparse.Namespace(finding="nonexistent_finding.md"))
|
|
self.assertEqual(res, 2)
|
|
|
|
def test_never_submit_signal_kills_finding(self):
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: low (impact: informational)
|
|
- Attacker: unauthenticated
|
|
- Not duplicate: novel report
|
|
- Proof: GET / HTTP/1.1
|
|
- Evidence: missing security headers
|
|
"""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
p = Path(tmpdir) / "never_submit.md"
|
|
p.write_text(content, encoding="utf-8")
|
|
with redirect_stdout(io.StringIO()):
|
|
res = cli.cmd_triage(argparse.Namespace(finding=str(p)))
|
|
self.assertEqual(res, 2)
|
|
|
|
def test_downgrade_verdict_when_only_severity_fails(self):
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Attacker: standard session
|
|
- Not duplicate: novel report
|
|
- Proof: GET /api/v1/data HTTP/1.1
|
|
- Evidence: leaked credential
|
|
"""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
p = Path(tmpdir) / "downgrade.md"
|
|
p.write_text(content, encoding="utf-8")
|
|
with redirect_stdout(io.StringIO()):
|
|
res = cli.cmd_triage(argparse.Namespace(finding=str(p)))
|
|
self.assertEqual(res, 1)
|
|
|
|
# ---- #209: Q1 wants a real request-target, not a method word in prose ----
|
|
def test_prose_method_name_is_not_q1_evidence(self):
|
|
content = """# Test Finding
|
|
- Target application: acme portal (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: the input validation looks wrong, no request captured
|
|
- Evidence: leaked credential
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertEqual(res, 2)
|
|
self.assertIn("✗ Q1", out)
|
|
|
|
def test_lowercase_request_line_satisfies_q1(self):
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: get /api/v1/data?user=7
|
|
- Evidence: leaked credential
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertEqual(res, 0)
|
|
self.assertIn("✓ Q1", out)
|
|
|
|
def test_markdown_wrapped_request_satisfies_q1(self):
|
|
"""A PoC written in markdown — backtick-wrapped or bold method — is a real request."""
|
|
for proof in ("`GET /api/v1/x`", "**GET** /api/v1/x", "GET `/api/v1/x`"):
|
|
content = f"""# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: {proof}
|
|
- Evidence: leaked credential
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertEqual(res, 0, f"proof {proof!r} should satisfy Q1")
|
|
self.assertIn("✓ Q1", out)
|
|
|
|
# ---- #197: Q7 clickjacking (no hyphen) and Q3 scope-negation ----
|
|
def test_clickjacking_variants_hit_never_submit(self):
|
|
for signal in ("clickjacking", "click-jacking"):
|
|
res, out = _run_triage(f"# {signal} on logout page\n")
|
|
self.assertEqual(res, 2)
|
|
self.assertIn("✗ Q7", out)
|
|
|
|
def test_unverified_out_of_scope_fails_q3(self):
|
|
content = """# IDOR on report endpoint
|
|
|
|
Scope: not verified, possibly out of scope
|
|
Asset: unknown, maybe staging
|
|
Proof: GET /api/v1/reports/7 HTTP/1.1
|
|
Severity: low
|
|
Impact: unclear
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertIn("✗ Q3", out)
|
|
|
|
def test_affirmative_scope_passes_q3(self):
|
|
_, out = _run_triage("- Target: http://example.com (in scope)\n")
|
|
self.assertIn("✓ Q3", out)
|
|
|
|
def test_hyphenated_out_of_scope_fails_q3(self):
|
|
"""'out-of-scope' (the common hyphenated spelling) must disavow scope too."""
|
|
content = """# IDOR on report endpoint
|
|
- Asset: staging.example.com (out-of-scope)
|
|
- Proof: GET /api/v1/reports/7 HTTP/1.1
|
|
"""
|
|
_, out = _run_triage(content)
|
|
self.assertIn("✗ Q3", out)
|
|
|
|
def test_scope_word_in_non_scope_line_does_not_fail_q3(self):
|
|
"""A negation word beside 'scope' on a non-scope line must not kill Q3."""
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: novel report
|
|
- Proof: curl http://example.com/api/v1/data
|
|
- Evidence: leaked credential
|
|
- Impact: unclear scope of data exposure
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertEqual(res, 0)
|
|
self.assertIn("✓ Q3", out)
|
|
|
|
def test_unrelated_negation_words_do_not_fail_q3(self):
|
|
content = """# Test Finding
|
|
- Target: http://example.com (in scope)
|
|
- Severity: high (impact: critical data leak)
|
|
- Attacker: low-priv session
|
|
- Not duplicate: previously unknown report
|
|
- Proof: curl http://example.com/api/v1/data
|
|
- Evidence: leaked credential
|
|
- Impact: unclear pending triage
|
|
"""
|
|
res, out = _run_triage(content)
|
|
self.assertEqual(res, 0)
|
|
self.assertIn("✓ Q3", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|