java-topology/defects/0ad-0004/bench/bench-0ad-0004-0004.py
russell@unturf.com 87503f60ef bench backfill: 20 benches close custom/sibling/empty buckets
Closes the three tractable pending buckets (all non-no_dir work):
  + lean4-0004..0007: 4 correctness/race benches (ir_interp DCL, jobreg
    IO.Ref race, g_opts thread-local leakage, process envvar hash).
    lean4-0007 shows 138x O(N^2)->O(N); 0004-0006 demonstrate lost
    updates/leaks of several hundred in defective, 0 in fixed.
  + 0ad-0001..0004: 3 CWE-407 list.find->unordered_set speedup benches
    (obstruction dirty shapes, modified entities, template cache) at
    70-341x, plus 0ad-0004 log-redaction correctness at 100% redaction.
  + activemq-0001..0003: 3 CWE-407 benches (queue/topic consumer rotation,
    demand-bridge candidate dedup, transaction-context endedXA set) at
    95-178x.
  + linux-0001..0008: 8 Python complexity-class models for the kernel
    patches. Coexist with the existing build-and-bench.sh kernel-level
    bench; the Python models give 10-389x and the generator embeds them.
  + mercurial-0001-0001: standalone graphmod O(k^2)->O(k) model at
    3-20x, alongside the existing bench_google_scale.py (which imports
    the real mercurial graphmod).

Progress: 13 -> 33 full coverage. Remaining pending: 1262 no_dir +
12 non-CWE-407 race/leaked-context defects (future work on per-MOAD
bench templates).
2026-04-23 11:48:03 -04:00

58 lines
1.8 KiB
Python

#!/usr/bin/env python3
# bench-0ad-0004-0004.py
# XmppClient + NetServer: lobby auth tokens logged verbatim. CWE-312 / MOAD-0004
# A Logged Secret. Correctness metric: does log output contain the raw token?
# Fixed path replaces token with "[REDACTED]" before logging.
import re
import sys
def emit_defective(username, token, logsink):
# Verbatim log of the token — the defect.
logsink.append(f"XmppClient: Received lobby auth: {token} from {username}")
def emit_fixed(username, token, logsink):
# Redacted log — the fix.
logsink.append(f"XmppClient: Received lobby auth: [REDACTED] from {username}")
def count_leaks(logsink, tokens):
"""Return the number of log lines that contain a raw token value."""
leaks = 0
for line in logsink:
for tok in tokens:
if tok in line:
leaks += 1
break
return leaks
def run():
lines = []
header = "=== 0ad-0004-0004: lobby auth token log redaction (correctness) ==="
print(header); lines.append(header)
# Simulate N auth events with random-looking tokens
cases = [100, 1000, 10000]
for n in cases:
tokens = [f"tok_{i:08x}" for i in range(n)]
users = [f"user{i}" for i in range(n)]
sink_def = []
sink_fix = []
for u, t in zip(users, tokens):
emit_defective(u, t, sink_def)
emit_fixed(u, t, sink_fix)
leaks_def = count_leaks(sink_def, tokens)
leaks_fix = count_leaks(sink_fix, tokens)
line = (f"N={n:<5}: defective_leaks={leaks_def:>5} fixed_leaks={leaks_fix:>5}"
f" redaction_rate={(n - leaks_fix) / n * 100:.1f}%")
print(line); lines.append(line); sys.stdout.flush()
return lines
if __name__ == "__main__":
run()