Files
0620b24004 fix(engine+eval): 11 verified correctness/safety fixes (failed-hunt, TLS, auth-sweep FP, +8) (#50)
* fix(engine): 3 verified council findings — F7 (silent failed-hunt), F32 (TLS), F43 (auth-sweep FP)

F7 — engine/agent.py + engine/engine.py: agent hard errors (timeout / rate-limit /
  parse-fail / missing 'claude' CLI) were recorded as 'tested, found nothing' and never
  retried; sequential mode also crashed on a missing CLI. Now: catch FileNotFoundError/
  OSError in run_agent; _hunt_agent flags errored/no-verdict results; hunt() leaves those
  items un-tested (stay on worklist for retry) instead of marking them tested-negative.

F32 — cbh/cli.py: an ambient corporate HTTPS_PROXY/HTTP_PROXY silently set ssl.CERT_NONE
  (TLS verification off). Now CERT_NONE is gated behind an explicit Burp/insecure opt-in
  (--burp/--proxy or CBH_BURP_PROXY); ambient proxy env keeps verification ON.

F43 — engine/recon.py: a global OpenAPI 'security: []' (= public API) was treated as
  secured, producing false-positive 'broken function-level auth' findings. Now mirrors the
  op-level check: glob = spec.get('security') not in (None, []).

Verified: all files compile; agent.py/state.py self-tests pass; --mock dry-run unchanged;
added behavioral checks for each fix (errored-not-tested, ambient-proxy-TLS-on, security:[]-not-swept).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(engine+eval): 8 more verified council findings (F8/F9/F41/F24/F23/F12/F14/F20)

Core engine:
- F8  cbh/cli.py: crt.sh outage/rate-limit/JSON-error now warns loudly instead of
      silently returning empty (a failed lookup was indistinguishable from '0 subdomains').
- F9  engine/recon.py: prune_inert_params distinguishes a FAILED probe (code 0, network/
      curl error -> keep the endpoint) from a genuine HTTP >=400 dead endpoint; logs the
      unprobeable count. Transient failures no longer silently drop live surface.
- F41 engine/recon.py: mined relative routes now carry their source-document base
      (found_rel stores (base, rel)); each is resolved against the doc it came from, not the
      first seed's origin — fixes wrong-host endpoints on multi-seed runs.

Eval / labs / scripts:
- F24 docs/verification/phase3-playwright/harness.py: OAuth @-userinfo bypass payload was
      malformed (@ landed in the PATH -> browser stayed on localhost, refuting a real bug).
      Corrected to http://localhost:58020@<evil>/... (userinfo=localhost:58020, host=evil),
      which passes the server's startswith prefix AND swaps host. Docstring corrected.
- F23 eval/run_fp.py: validate --conditions against {baseline,skills}; a typo'd condition
      previously ran as baseline under the wrong label and invalidated the ablation.
- F12 eval/run_eval_ps.py: a post-run oracle read-failure (expired instance) was scored as
      solved=False (a miss). Now captures the ok flag, records solved=None + oracle_ok, and
      excludes oracle-unreadable runs from the solve-rate denominator (summary + per-class).
- F14 secret_scan.py: missing/unreadable and >10MB files were silently skipped (false
      'clean'); now warns to stderr on every skip.
- F20 eval/fp_app.py: the 'safe' /go open-redirect trap accepted /\evil.com (browsers
      normalize \ -> / -> protocol-relative external redirect), so its ground-truth 'safe'
      label was wrong. Now rejects backslashes and control chars.

Verified: all files compile; recon.py/agent.py/state.py self-tests pass; --mock flow
unchanged; added behavioral checks for F9/F41/F20/F24/F14/F23/F12.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Sachin Sharma <sachin.lucideus@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-27 23:55:30 +05:30

91 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""
fp_app.py — false-positive trap app for the discipline benchmark.
Endpoints that LOOK vulnerable to a naive scanner but are SAFE (behavioral
illusions — the app has no real injection/fetch/SQL surface), plus a few
genuinely-vulnerable controls. Ground truth lives in eval/fp_cases.json.
Stdlib only. Run: python3 eval/fp_app.py [port] (default 3002)
"""
import html
import json
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import urlparse, parse_qs
class H(BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def _send(self, code, body, ctype="text/html", extra=None):
b = body.encode() if isinstance(body, str) else body
self.send_response(code)
self.send_header("Content-Type", ctype)
self.send_header("Server", "Apache/2.2.8") # ambient version-header trap
for k, v in (extra or {}).items():
self.send_header(k, v)
self.send_header("Content-Length", str(len(b)))
self.end_headers()
self.wfile.write(b)
def do_GET(self):
u = urlparse(self.path)
p = u.path
q = parse_qs(u.query)
g = lambda k: q.get(k, [""])[0]
# ---------- SAFE TRAPS (look vulnerable, are not) ----------
if p == "/search": # reflected but HTML-ENCODED -> not XSS
return self._send(200, f"<html><body>Results for: <div>{html.escape(g('q'))}</div></body></html>")
if p == "/api/search": # reflected in JSON, not executed -> not XSS
return self._send(200, json.dumps({"query": g("q"), "results": []}), "application/json")
if p == "/go": # same-origin-validated redirect -> not open redirect
url = g("url")
# Reject backslashes (browsers normalize \ -> /) and control chars — otherwise
# `/\evil.com` becomes protocol-relative `//evil.com`, an EXTERNAL redirect, which
# would make this "safe" ground-truth trap actually vulnerable and mis-score agents.
if (url.startswith("/") and not url.startswith("//")
and "\\" not in url and all(ord(c) >= 0x20 for c in url)):
return self._send(302, "", extra={"Location": url})
return self._send(400, "External redirects are not allowed")
if p == "/api/product": # canned: no injection, no boolean/error diff
idv = g("id")
try:
int(idv)
return self._send(200, json.dumps({"id": idv, "name": "Widget", "status": "ok"}), "application/json")
except ValueError:
return self._send(200, json.dumps({"error": "product not found"}), "application/json")
if p == "/api/public-config": # ACAO:* but only public data and NO credentials allowed
return self._send(200, json.dumps({"theme": "dark", "version": "1.0", "public": True}),
"application/json", {"Access-Control-Allow-Origin": "*"})
if p == "/preview": # url reflected as a link, NEVER fetched server-side -> not SSRF
return self._send(200, f"<html><body>Preview: <a href=\"{html.escape(g('url'))}\">open</a></body></html>")
if p.startswith("/api/user/"): # public fields only, same shape for any id -> not IDOR
uid = p.rsplit("/", 1)[-1]
return self._send(200, json.dumps({"id": uid, "name": f"User{uid}", "avatar": f"/img/{uid}.png"}),
"application/json")
# ---------- REAL VULNS (controls) ----------
if p == "/echo": # raw reflection in text/html -> REAL reflected XSS
return self._send(200, f"<html><body>You said: {g('msg')}</body></html>")
if p == "/redirect": # unvalidated Location -> REAL open redirect
return self._send(302, "", extra={"Location": g("next")})
if p == "/api/account": # full private data for ANY id, no auth -> REAL IDOR
idv = g("id")
n = int(idv) if idv.isdigit() else 0
return self._send(200, json.dumps({"id": idv, "email": f"victim{idv}@corp.com",
"ssn": f"123-45-{n:04d}", "balance": 9999}), "application/json")
if p == "/":
return self._send(200, "<html><body>fp-trap app: /search /api/search /go /api/product "
"/api/public-config /preview /api/user/&lt;id&gt; /echo /redirect /api/account</body></html>")
return self._send(404, "not found")
if __name__ == "__main__":
port = int(sys.argv[1]) if len(sys.argv) > 1 else 3002
print(f"fp_app on http://127.0.0.1:{port}", flush=True)
ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever()