From 67f9eb08742744c69d69a45b4981f33725d83d85 Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 16:52:53 +0530 Subject: [PATCH 1/6] =?UTF-8?q?fix(cbh):=20triage=20gate=20=E2=80=94=20rea?= =?UTF-8?q?l=20request-target=20for=20Q1,=20scope-negation=20for=20Q3,=20c?= =?UTF-8?q?lickjacking=20for=20Q7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cbh/cli.py | 35 ++++++++++++++++++-- tests/test_triage.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/cbh/cli.py b/cbh/cli.py index 97089a8e..0052401d 100755 --- a/cbh/cli.py +++ b/cbh/cli.py @@ -638,9 +638,15 @@ def cmd_classify(args: argparse.Namespace) -> int: # ============================================================ # triage — run the 7-Question Gate against a finding markdown # ============================================================ +# Q1 asks for a real request, so a bare method word only counts when a +# request-target (a path or URL) follows it. Plain substrings like "GET " used +# to match inside prose ("tarGET application", "inPUT validation"), letting an +# untested finding answer Q1 YES. +_REQUEST_LINE = re.compile(r"\b(?:get|post|put|patch|delete)[ \t]+(?:/|https?://)") + TRIAGE_QUESTIONS = [ ("Q1", "Can an attacker use this RIGHT NOW with a real HTTP request?", - ["curl ", "POST ", "GET ", "HTTP/1.1", "PUT ", "DELETE ", "PATCH "]), + ["curl ", "http/1.1", _REQUEST_LINE]), ("Q2", "Is the impact on the program's accepted-impact list?", ["impact:", "severity:", "p1", "p2", "p3", "p4", "critical", "high", "medium", "low"]), ("Q3", "Is the asset in scope?", @@ -653,9 +659,30 @@ def cmd_classify(args: argparse.Namespace) -> int: ["leaked", "exfiltrated", "rce", "data:", "credential", "session-id", "cookie:", "admin email", "production", "oob callback", "interactsh"]), ("Q7", "Is this not on the never-submit list?", - ["self-xss", "rate-limit only", "click-jacking", "csrf on logout", "missing security headers"]), + ["self-xss", "rate-limit only", "click-jacking", "clickjacking", + "csrf on logout", "missing security headers"]), ] +# Q3 disqualifiers: scope/asset wording is not affirmative evidence when the +# finding itself says the asset is unverified, unknown, or out of scope. Only a +# scope/asset line may negate Q3 — "Impact: unclear" or "previously unknown" +# must not. +_Q3_NEGATIONS = ["out of scope", "not in scope", "not verified", "unverified", + "unknown", "possibly", "maybe", "unclear"] +_Q3_SCOPE_WORDS = ("scope", "target:", "asset:") + + +def _signal_hit(signal, text: str) -> bool: + """One triage signal: a compiled pattern searches, a string is a substring.""" + if isinstance(signal, re.Pattern): + return signal.search(text) is not None + return signal.lower() in text + + +def _q3_scope_negated(text: str) -> bool: + scope_lines = [ln for ln in text.splitlines() if any(w in ln for w in _Q3_SCOPE_WORDS)] + return any(neg in ln for ln in scope_lines for neg in _Q3_NEGATIONS) + def cmd_triage(args: argparse.Namespace) -> int: finding_path = Path(args.finding) @@ -671,7 +698,9 @@ def cmd_triage(args: argparse.Namespace) -> int: answers = [] for qid, question, signals in TRIAGE_QUESTIONS: # Q7 is INVERTED: presence of a "never-submit" signal = answer is "NO" (kill) - hit = any(s.lower() in text for s in signals) + hit = any(_signal_hit(s, text) for s in signals) + if qid == "Q3" and hit and _q3_scope_negated(text): + hit = False # scope words present, but the finding disavows the scope if qid == "Q7": answer = "NO — finding matches never-submit category" if hit else "YES" ok = not hit diff --git a/tests/test_triage.py b/tests/test_triage.py index 4dbaf94d..764aa5c2 100644 --- a/tests/test_triage.py +++ b/tests/test_triage.py @@ -1,5 +1,6 @@ import argparse import io +import re from pathlib import Path import tempfile import unittest @@ -7,6 +8,18 @@ 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): @@ -96,6 +109,70 @@ def test_downgrade_verdict_when_only_severity_fails(self): 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) + + # ---- #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_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() From 1c7ee3c1e7759f60e8e47d76f0d17ed23f535121 Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 16:53:30 +0530 Subject: [PATCH 2/6] 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 --- cbh/cli.py | 1 + tests/test_report_utf8_bom.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/test_report_utf8_bom.py diff --git a/cbh/cli.py b/cbh/cli.py index 0052401d..1858fe9f 100755 --- a/cbh/cli.py +++ b/cbh/cli.py @@ -759,6 +759,7 @@ def parse_finding_metadata(text: str) -> dict: """Best-effort parse of YAML-ish frontmatter + section content.""" md = {"title": "", "severity": "Medium", "asset": "", "endpoint": "", "summary": "", "steps": "", "impact": "", "remediation": ""} + text = text.lstrip("") # a UTF-8 BOM would push `---` off the start (#200) # YAML frontmatter m = re.match(r"^---\n(.*?)\n---\n(.*)", text, re.S) body = text diff --git a/tests/test_report_utf8_bom.py b/tests/test_report_utf8_bom.py new file mode 100644 index 00000000..a50240a0 --- /dev/null +++ b/tests/test_report_utf8_bom.py @@ -0,0 +1,27 @@ +"""A UTF-8 BOM before the YAML frontmatter must not break metadata parsing. + +Editors on Windows (and some export tools) prepend a BOM (\\ufeff). The +frontmatter regex anchors on `^---`, which the BOM pushes off the start of the +string, so severity/asset silently fell back to defaults. Reported in #200. +""" +import unittest + +from cbh import cli + + +class ReportUtf8BomTests(unittest.TestCase): + def test_bom_prefixed_frontmatter_still_parses(self): + finding = ( + "---\nseverity: Low\nasset: example.test\n---\n" + "# Sample report\n\n## Summary\nA formatting example.\n" + ) + for prefix in ("", ""): + with self.subTest(bom=bool(prefix)): + md = cli.parse_finding_metadata(prefix + finding) + self.assertEqual(md["severity"], "Low") + self.assertEqual(md["asset"], "example.test") + self.assertEqual(md["title"], "Sample report") + + +if __name__ == "__main__": + unittest.main() From e590b8176d94908a14b9c9c01731005dc716362a Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 16:54:29 +0530 Subject: [PATCH 3/6] 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 --- cbh/cli.py | 8 +++++++ scripts/setup_harness_mcp.py | 7 ++++++ tests/test_cbh_windows_encoding.py | 34 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/test_cbh_windows_encoding.py diff --git a/cbh/cli.py b/cbh/cli.py index 1858fe9f..e9ed9da9 100755 --- a/cbh/cli.py +++ b/cbh/cli.py @@ -994,6 +994,14 @@ def cmd_surface(args: argparse.Namespace) -> int: # Main dispatcher # ============================================================ def main() -> int: + # Windows/non-UTF-8 consoles default stdout to the code page (cp1252), which + # crashes on the check/cross/arrow/em-dash glyphs the CLI prints. Force UTF-8 + # (matches engine/engine.py:main). + for _stream in (sys.stdout, sys.stderr): + try: + _stream.reconfigure(encoding="utf-8") + except (AttributeError, ValueError): + pass parser = argparse.ArgumentParser( prog="cbh", description=("claude-bughunter CLI — terminal-native deterministic runner.\n" diff --git a/scripts/setup_harness_mcp.py b/scripts/setup_harness_mcp.py index 2bd1895f..e4f38743 100755 --- a/scripts/setup_harness_mcp.py +++ b/scripts/setup_harness_mcp.py @@ -227,6 +227,13 @@ def _wire(name, cmd, args, env, a): def main(): + # Windows/non-UTF-8 consoles default stdout to cp1252, which crashes on the + # check/cross/arrow glyphs this script prints. Force UTF-8 (see #180). + for _stream in (sys.stdout, sys.stderr): + try: + _stream.reconfigure(encoding="utf-8") + except (AttributeError, ValueError): + pass ap = argparse.ArgumentParser() ap.add_argument("--burp", action="store_true", help="wire the Burp MCP (default if no server flag given)") ap.add_argument("--hackerone", action="store_true", help="wire the in-repo HackerOne MCP") diff --git a/tests/test_cbh_windows_encoding.py b/tests/test_cbh_windows_encoding.py new file mode 100644 index 00000000..bec8db2a --- /dev/null +++ b/tests/test_cbh_windows_encoding.py @@ -0,0 +1,34 @@ +"""Regression test for #180 (cbh UnicodeEncodeError on non-UTF-8 consoles). + +The cbh CLI prints the glyphs the gate uses — the check/cross marks and the +arrow — throughout its output. On a Windows console the default code page is +cp1252, which cannot encode them, so a bare print() raised UnicodeEncodeError +and the command died mid-run. We reproduce that deterministically on any host by +forcing an ASCII default encoding (PYTHONUTF8=0 + PYTHONCOERCECLOCALE=0 + +LC_ALL=C), which is what Windows hits with cp1252. +""" +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +_ASCII_ENV = dict(os.environ, PYTHONUTF8="0", PYTHONCOERCECLOCALE="0", LC_ALL="C") + + +class CbhWindowsEncodingTests(unittest.TestCase): + def test_triage_survives_ascii_locale(self): + with tempfile.TemporaryDirectory() as tmp: + finding = Path(tmp) / "finding.md" + finding.write_text("# clickjacking on logout page\n", encoding="utf-8") + r = subprocess.run( + [sys.executable, "cbh/cli.py", "triage", str(finding)], + cwd=_REPO, env=_ASCII_ENV, capture_output=True, text=True, encoding="utf-8") + self.assertNotIn("UnicodeEncodeError", r.stderr, + f"cbh crashed under ASCII locale:\n{r.stderr}") + + +if __name__ == "__main__": + unittest.main() From c1dd6e846519261e197ba9c6d8cdda38dd35afbd Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 16:55:58 +0530 Subject: [PATCH 4/6] 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:", 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 --- .../offensive-osint/scripts/h1_reference.py | 44 ++++++++++++----- tests/test_h1_reference.py | 47 +++++++++++++++++++ 2 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 tests/test_h1_reference.py diff --git a/skills/offensive-osint/scripts/h1_reference.py b/skills/offensive-osint/scripts/h1_reference.py index bc811bed..951f7b74 100644 --- a/skills/offensive-osint/scripts/h1_reference.py +++ b/skills/offensive-osint/scripts/h1_reference.py @@ -129,11 +129,12 @@ def gql_vars(query: str, variables: dict) -> dict: def lookup_program(handle: str) -> Optional[str]: data = gql_vars(TEAM_LOOKUP_QUERY, {"handle": handle}) - team = data.get("data", {}).get("team") + team = (data.get("data") or {}).get("team") if not team: print(f"[!] Program '{handle}' not found or is private", file=sys.stderr) return None - print(f"[+] {team['handle']} → id={team['_id']}, name={team['name']}") + # Progress goes to stderr so --json stdout stays clean and pipeable (jq). + print(f"[+] {team['handle']} → id={team['_id']}, name={team['name']}", file=sys.stderr) return team["_id"] @@ -141,21 +142,37 @@ def build_page_query(args, after: Optional[str] = None) -> str: """ Build an inline GraphQL query for one page of results. - H1 crash rules (discovered empirically): + H1 crash/schema rules (discovered empirically): - substate filter + sort + report fields → CRASH - disclosed_at field + substate filter → CRASH - named variables + substate filter + report fields → CRASH + - terms: {team_id: ...} is no longer searchable on CompleteHacktivityReportIndex Strategy: + - Program filter (--program): query_string "team_handle:" (supports sort + pagination) - Pure sort (no --program): no substate filter, sort works fine - - Program filter: substate filter, no sort, client-side sort + - Default: substate filter, no sort """ has_sort = args.top_voted or args.top_bounty has_program = bool(args.program_id) after_str = f', after: "{_escape(after)}"' if after else "" - if has_sort and not has_program: + if has_program: + # H1 dropped team_id filtering; query_string with team_handle works and + # still accepts sort + pagination. + sort_str = "" + if has_sort: + sort_field = "votes" if args.top_voted else "total_awarded_amount" + sort_str = f', sort: {{field: "{sort_field}", direction: DESC}}' + qs = _escape(f"team_handle:{args.program}") + return ( + f'{{ search(index: CompleteHacktivityReportIndex, ' + f'query_string: "{qs}", ' + f'first: {PAGE_SIZE}{after_str}{sort_str}) ' + f'{{ total_count pageInfo {{ endCursor }} nodes {{ {REPORT_FIELDS} }} }} }}' + ) + elif has_sort: # Sort-only mode: no substate filter, works without crashing sort_field = "votes" if args.top_voted else "total_awarded_amount" return ( @@ -164,14 +181,10 @@ def build_page_query(args, after: Optional[str] = None) -> str: f'{{ total_count pageInfo {{ endCursor }} nodes {{ {REPORT_FIELDS} }} }} }}' ) else: - # Filter mode: substate + optional team filter, no sort - filter_parts = ['terms: {substate: ["resolved"]}'] - if has_program: - filter_parts.append(f'terms: {{team_id: ["{_escape(str(args.program_id))}"]}}') - filter_str = ", ".join(f"{{{p}}}" for p in filter_parts) + # Default filter mode: substate only, no sort return ( f'{{ search(index: CompleteHacktivityReportIndex, ' - f'query: {{bool: {{filter: [{filter_str}]}}}}, ' + f'query: {{bool: {{filter: [{{terms: {{substate: ["resolved"]}}}}]}}}}, ' f'first: {PAGE_SIZE}{after_str}) ' f'{{ total_count pageInfo {{ endCursor }} nodes {{ {REPORT_FIELDS} }} }} }}' ) @@ -359,8 +372,13 @@ def main(): return args.program_id = None - if args.program: - args.program_id = lookup_program(args.program) + if args.program is not None: + handle = args.program.strip() + if not handle: + print("[!] --program requires a non-empty handle", file=sys.stderr) + sys.exit(1) + args.program = handle + args.program_id = lookup_program(handle) if not args.program_id: sys.exit(1) diff --git a/tests/test_h1_reference.py b/tests/test_h1_reference.py new file mode 100644 index 00000000..a456a73b --- /dev/null +++ b/tests/test_h1_reference.py @@ -0,0 +1,47 @@ +"""build_page_query must filter programs with query_string:team_handle, not the +team_id terms filter the H1 schema no longer accepts (#206, #202). + +No network: build_page_query is a pure string builder over an args namespace. +""" +import argparse +import importlib.util +import os +import unittest + +_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +_H1 = os.path.join(_REPO, "skills", "offensive-osint", "scripts", "h1_reference.py") +_spec = importlib.util.spec_from_file_location("h1_reference", _H1) +h1 = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(h1) + + +def _args(program=None, program_id=None, top_voted=False, top_bounty=False): + return argparse.Namespace(program=program, program_id=program_id, + top_voted=top_voted, top_bounty=top_bounty) + + +class BuildPageQueryTests(unittest.TestCase): + def test_program_uses_team_handle_not_team_id(self): + q = h1.build_page_query(_args(program="acme", program_id="123")) + self.assertIn("query_string:", q) + self.assertIn("team_handle:acme", q) + self.assertNotIn("team_id", q) + + def test_program_with_sort_adds_server_side_sort(self): + q = h1.build_page_query(_args(program="acme", program_id="123", top_voted=True)) + self.assertIn("team_handle:acme", q) + self.assertIn('field: "votes"', q) + + def test_sort_only_has_no_substate_filter(self): + q = h1.build_page_query(_args(top_bounty=True)) + self.assertIn('field: "total_awarded_amount"', q) + self.assertNotIn("substate", q) + + def test_default_mode_filters_resolved_without_team_id(self): + q = h1.build_page_query(_args()) + self.assertIn('substate: ["resolved"]', q) + self.assertNotIn("team_id", q) + + +if __name__ == "__main__": + unittest.main() From 2c9de16b53d0a8b6163f5eb9c26712bfeea81326 Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 16:57:07 +0530 Subject: [PATCH 5/6] docs(changelog): record the four tooling bugfixes with reporter credits Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfaf1304..c35252e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,25 @@ versioning is loosely [SemVer](https://semver.org/) at the bundle level. remain Claude-Code-only. New guide: `docs/multi-harness.md`. ### Fixed +- **`cbh triage` 7-Question Gate — three false-verdict paths** (built in-house, reporters credited): + 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 — Q1 now requires a method + followed by a path or URL (or `curl` / `HTTP/1.1`) (reported by @dajiaohuang, #209); Q7's + never-submit list caught `click-jacking` but not `clickjacking` (reported by @Ethereal49, #197); + Q3 answered YES on scope 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 (reported by + @Ethereal49, #197). +- **`cbh report` dropped frontmatter behind a UTF-8 BOM** — a BOM written by some Windows editors + sat before the `---` fence, so severity/asset fell back to defaults. `parse_finding_metadata` + now strips a leading BOM at the shared chokepoint. Reported by @jazzpher (#200). +- **`cbh` / `setup_harness_mcp.py` crashed on non-UTF-8 Windows consoles** — the gate glyphs + (✓/✗/→/—) raised `UnicodeEncodeError` under cp1252. Both entrypoints now reconfigure stdout/stderr + to UTF-8, matching `engine/engine.py`. Reported by @Sahilkumar-r (#180). +- **`h1_reference.py --program` returned nothing** — `CompleteHacktivityReportIndex` no longer + accepts `terms: {team_id: ...}`; switched to `query_string: "team_handle:"`, which filters + correctly and composes with `--top-voted`/`--top-bounty`. Lookup progress moved to stderr so + `--json` stdout stays pipeable. Two independent reports converged here: @roonnnnyyyyyy (#206) and + @flipcyde101 (#202). - `hunt-clickjacking`, `hunt-html-injection`: quoted the `description` — an unquoted `: ` (`Targets:`, `surfaces:`) broke strict YAML / Codex. Also genericized lab/harness-specific language in the new skills for cross-harness portability. From 5ac9f54b742a70a8d5d749591c46a0cb5da46a67 Mon Sep 17 00:00:00 2001 From: Sachin Sharma Date: Sun, 22 Nov 2026 17:02:07 +0530 Subject: [PATCH 6/6] =?UTF-8?q?fix(cbh,osint):=20review=20follow-ups=20?= =?UTF-8?q?=E2=80=94=20Q3=20negation,=20Q1=20markdown,=20CRLF,=20canonical?= =?UTF-8?q?=20handle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cbh/cli.py | 40 ++++++++++++++----- .../offensive-osint/scripts/h1_reference.py | 16 +++++--- tests/test_h1_reference.py | 16 ++++++++ tests/test_report_utf8_bom.py | 9 +++++ tests/test_triage.py | 39 ++++++++++++++++++ 5 files changed, 104 insertions(+), 16 deletions(-) diff --git a/cbh/cli.py b/cbh/cli.py index e9ed9da9..c473dfea 100755 --- a/cbh/cli.py +++ b/cbh/cli.py @@ -641,8 +641,14 @@ def cmd_classify(args: argparse.Namespace) -> int: # Q1 asks for a real request, so a bare method word only counts when a # request-target (a path or URL) follows it. Plain substrings like "GET " used # to match inside prose ("tarGET application", "inPUT validation"), letting an -# untested finding answer Q1 YES. -_REQUEST_LINE = re.compile(r"\b(?:get|post|put|patch|delete)[ \t]+(?:/|https?://)") +# untested finding answer Q1 YES. The separator class allows the markdown a PoC +# is usually written in — backticks and bold/italic around the method or path +# (`GET /x`, **GET** /x, GET `/x`). +# ponytail: heuristic ceiling — prose like "an attacker can get /admin" still +# reads as a request. Requiring HTTP/ or a scheme after the path would reject +# the common bare "GET /path?x=1" PoC (see test_lowercase_request_line), so a +# method+path match is the accepted floor; the human reads the verdict. +_REQUEST_LINE = re.compile(r"\b(?:get|post|put|patch|delete)[ \t`*_]+(?:/|https?://)") TRIAGE_QUESTIONS = [ ("Q1", "Can an attacker use this RIGHT NOW with a real HTTP request?", @@ -664,12 +670,16 @@ def cmd_classify(args: argparse.Namespace) -> int: ] # Q3 disqualifiers: scope/asset wording is not affirmative evidence when the -# finding itself says the asset is unverified, unknown, or out of scope. Only a -# scope/asset line may negate Q3 — "Impact: unclear" or "previously unknown" -# must not. -_Q3_NEGATIONS = ["out of scope", "not in scope", "not verified", "unverified", - "unknown", "possibly", "maybe", "unclear"] -_Q3_SCOPE_WORDS = ("scope", "target:", "asset:") +# finding itself disavows the asset. Two kinds of disavowal: +# - STRONG phrases ("out of scope", "excluded from scope") are unambiguous on +# any line, including prose ("this asset is out of scope"). +# - WEAK words ("unknown", "unclear", "maybe") only disavow when they sit on a +# scope/asset/target line — otherwise "Impact: unclear scope of exposure" or +# "previously unknown" would wrongly kill an in-scope finding. +# Hyphens are normalized to spaces first, so "out-of-scope" matches "out of scope". +_Q3_STRONG = ("out of scope", "not in scope", "outside scope", "excluded from scope") +_Q3_WEAK = ("not verified", "unverified", "unknown", "possibly", "maybe", "unclear") +_Q3_SCOPE_KEYS = ("scope", "asset", "target", "affected asset", "in scope", "out of scope") def _signal_hit(signal, text: str) -> bool: @@ -680,8 +690,14 @@ def _signal_hit(signal, text: str) -> bool: def _q3_scope_negated(text: str) -> bool: - scope_lines = [ln for ln in text.splitlines() if any(w in ln for w in _Q3_SCOPE_WORDS)] - return any(neg in ln for ln in scope_lines for neg in _Q3_NEGATIONS) + for ln in text.splitlines(): + norm = ln.replace("-", " ").lower() + if any(phrase in norm for phrase in _Q3_STRONG): + return True + key = norm.split(":", 1)[0].strip("*`•# ").strip() + if key in _Q3_SCOPE_KEYS and any(w in norm for w in _Q3_WEAK): + return True + return False def cmd_triage(args: argparse.Namespace) -> int: @@ -759,7 +775,9 @@ def parse_finding_metadata(text: str) -> dict: """Best-effort parse of YAML-ish frontmatter + section content.""" md = {"title": "", "severity": "Medium", "asset": "", "endpoint": "", "summary": "", "steps": "", "impact": "", "remediation": ""} - text = text.lstrip("") # a UTF-8 BOM would push `---` off the start (#200) + # A UTF-8 BOM would push `---` off the start, and Windows CRLF line endings + # (same platform) break the `^---\n` anchor — normalize both (#200). + text = text.lstrip("").replace("\r\n", "\n") # YAML frontmatter m = re.match(r"^---\n(.*?)\n---\n(.*)", text, re.S) body = text diff --git a/skills/offensive-osint/scripts/h1_reference.py b/skills/offensive-osint/scripts/h1_reference.py index 951f7b74..9db2c366 100644 --- a/skills/offensive-osint/scripts/h1_reference.py +++ b/skills/offensive-osint/scripts/h1_reference.py @@ -127,7 +127,12 @@ def gql_vars(query: str, variables: dict) -> dict: sys.exit(1) -def lookup_program(handle: str) -> Optional[str]: +def lookup_program(handle: str) -> Optional[dict]: + """Resolve a program handle to its team record, or None if not found/private. + + Returns the team dict so the caller can use the canonical `handle` H1 stores + (TeamLookup is case-insensitive, but the hacktivity query_string is not, so + `--program Shopify` must query the canonical `shopify`, not the raw input).""" data = gql_vars(TEAM_LOOKUP_QUERY, {"handle": handle}) team = (data.get("data") or {}).get("team") if not team: @@ -135,7 +140,7 @@ def lookup_program(handle: str) -> Optional[str]: return None # Progress goes to stderr so --json stdout stays clean and pipeable (jq). print(f"[+] {team['handle']} → id={team['_id']}, name={team['name']}", file=sys.stderr) - return team["_id"] + return team def build_page_query(args, after: Optional[str] = None) -> str: @@ -377,10 +382,11 @@ def main(): if not handle: print("[!] --program requires a non-empty handle", file=sys.stderr) sys.exit(1) - args.program = handle - args.program_id = lookup_program(handle) - if not args.program_id: + team = lookup_program(handle) + if not team: sys.exit(1) + args.program = team["handle"] # canonical handle for the query_string + args.program_id = team["_id"] nodes = fetch_all_pages(args) results = apply_client_filters(nodes, args) diff --git a/tests/test_h1_reference.py b/tests/test_h1_reference.py index a456a73b..792bfff2 100644 --- a/tests/test_h1_reference.py +++ b/tests/test_h1_reference.py @@ -7,6 +7,7 @@ import importlib.util import os import unittest +from unittest.mock import patch _REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) _H1 = os.path.join(_REPO, "skills", "offensive-osint", "scripts", "h1_reference.py") @@ -43,5 +44,20 @@ def test_default_mode_filters_resolved_without_team_id(self): self.assertNotIn("team_id", q) +class LookupProgramTests(unittest.TestCase): + def test_returns_team_with_canonical_handle(self): + # TeamLookup is case-insensitive; the caller needs the canonical handle + # because the hacktivity query_string is not. + resp = {"data": {"team": {"_id": "42", "handle": "shopify", "name": "Shopify"}}} + with patch.object(h1, "gql_vars", return_value=resp): + team = h1.lookup_program("Shopify") + self.assertEqual(team["handle"], "shopify") + self.assertEqual(team["_id"], "42") + + def test_returns_none_when_private_or_missing(self): + with patch.object(h1, "gql_vars", return_value={"data": {"team": None}}): + self.assertIsNone(h1.lookup_program("nope")) + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_report_utf8_bom.py b/tests/test_report_utf8_bom.py index a50240a0..cb344876 100644 --- a/tests/test_report_utf8_bom.py +++ b/tests/test_report_utf8_bom.py @@ -22,6 +22,15 @@ def test_bom_prefixed_frontmatter_still_parses(self): self.assertEqual(md["asset"], "example.test") self.assertEqual(md["title"], "Sample report") + def test_crlf_frontmatter_still_parses(self): + """Windows line endings (CRLF) — the same platform as the BOM — must parse too.""" + finding = ( + "---\nseverity: High\nasset: crlf.test\n---\n# CRLF report\n" + ).replace("\n", "\r\n") + md = cli.parse_finding_metadata(finding) + self.assertEqual(md["severity"], "High") + self.assertEqual(md["asset"], "crlf.test") + if __name__ == "__main__": unittest.main() diff --git a/tests/test_triage.py b/tests/test_triage.py index 764aa5c2..b684d1ab 100644 --- a/tests/test_triage.py +++ b/tests/test_triage.py @@ -136,6 +136,21 @@ def test_lowercase_request_line_satisfies_q1(self): 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"): @@ -159,6 +174,30 @@ 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)