fusiontest 0.2.47__tar.gz → 0.2.48__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fusiontest-0.2.47 → fusiontest-0.2.48}/PKG-INFO +1 -1
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/security.py +163 -10
- fusiontest-0.2.48/fusiontest/bench/suites/billing-security-spa.yaml +89 -0
- fusiontest-0.2.48/fusiontest/security/browser_auth.py +452 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/security/checks.py +326 -57
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/security/config.py +10 -1
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/PKG-INFO +1 -1
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/SOURCES.txt +2 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/pyproject.toml +1 -1
- {fusiontest-0.2.47 → fusiontest-0.2.48}/README.md +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/agent/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/agent/mcp_server.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/agent/verify.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/sites/shop/bugs.js +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/sites/shop/help.html +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/sites/shop/index.html +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/billing-security.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/diffs/order-retry.diff +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/diffs/sale-banner.diff +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/diffs/stock-check.diff +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/shop-hard.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/shop-intent.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/cli.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/action_model.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/app_errors.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/bugs.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/goal_verifier.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/promise_checker.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/replay.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/reproduce.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/runner.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/secrets.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/shared_traces.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/desktop/playwright_adapter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/discovery/goal_generator.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/discovery/intent.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/security/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/security/engine.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/security/findings.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/requires.txt +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.47 → fusiontest-0.2.48}/setup.cfg +0 -0
|
@@ -23,6 +23,7 @@ planted vulnerability found, no decoy reported, on two models.
|
|
|
23
23
|
|
|
24
24
|
from __future__ import annotations
|
|
25
25
|
|
|
26
|
+
import base64
|
|
26
27
|
import functools
|
|
27
28
|
import html
|
|
28
29
|
import http.cookies
|
|
@@ -67,6 +68,8 @@ class SecurityAccount:
|
|
|
67
68
|
name: str
|
|
68
69
|
role: str
|
|
69
70
|
login: str # a sign-in goal, as in `security.accounts` (ADR-011 §3)
|
|
71
|
+
auth: str = "auto"
|
|
72
|
+
logout: str = ""
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
@dataclass
|
|
@@ -81,6 +84,7 @@ class SecuritySuite:
|
|
|
81
84
|
description: str = ""
|
|
82
85
|
platform: str = "playwright"
|
|
83
86
|
kind: str = "security"
|
|
87
|
+
path: str = "" # extra path on the fixture URL, e.g. /spa/
|
|
84
88
|
|
|
85
89
|
|
|
86
90
|
SITES = ("billing",)
|
|
@@ -100,8 +104,10 @@ def load_security_suite(data: dict, source: str) -> SecuritySuite:
|
|
|
100
104
|
raw = raw or {}
|
|
101
105
|
if not raw.get("role") or not raw.get("login"):
|
|
102
106
|
raise bad(f"account {acct_name!r} needs a role and a login goal")
|
|
103
|
-
accounts.append(SecurityAccount(
|
|
104
|
-
|
|
107
|
+
accounts.append(SecurityAccount(
|
|
108
|
+
name=str(acct_name), role=str(raw["role"]), login=str(raw["login"]),
|
|
109
|
+
auth=str(raw.get("auth") or "auto"), logout=str(raw.get("logout") or ""),
|
|
110
|
+
))
|
|
105
111
|
if len(accounts) < 2 or len({a.role for a in accounts}) < 2:
|
|
106
112
|
raise bad("needs at least two accounts and two roles, or access and roles checks can't run")
|
|
107
113
|
|
|
@@ -141,7 +147,8 @@ def load_security_suite(data: dict, source: str) -> SecuritySuite:
|
|
|
141
147
|
raise bad(f"vulnerabilities never planted in a variant: {sorted(unplanted)}")
|
|
142
148
|
return SecuritySuite(name=name, site=site, accounts=accounts, vulns=vulns, variants=variants,
|
|
143
149
|
decoys=decoys, version=int(data.get("version", 1)),
|
|
144
|
-
description=str(data.get("description", ""))
|
|
150
|
+
description=str(data.get("description", "")),
|
|
151
|
+
path=str(data.get("path") or ""))
|
|
145
152
|
|
|
146
153
|
|
|
147
154
|
def _ambiguous(specs: list[PlantedVuln]) -> tuple[str, str] | None:
|
|
@@ -310,8 +317,11 @@ def engine_checker(engine, backend: str, judge: str = "", headless: bool = True)
|
|
|
310
317
|
from fusiontest.security.engine import SecurityTarget
|
|
311
318
|
|
|
312
319
|
def check(url: str, suite: SecuritySuite) -> SecurityReport:
|
|
320
|
+
target_url = urllib.parse.urljoin(url, suite.path) if suite.path else url
|
|
313
321
|
return engine(SecurityTarget(
|
|
314
|
-
url=
|
|
322
|
+
url=target_url,
|
|
323
|
+
accounts=[Account(name=a.name, role=a.role, login=a.login,
|
|
324
|
+
auth=a.auth, logout=a.logout) for a in suite.accounts],
|
|
315
325
|
checks=list(CHECKS), allowed_hosts=["127.0.0.1"], read_only=True,
|
|
316
326
|
backend=backend, judge=judge, headless=headless))
|
|
317
327
|
return check
|
|
@@ -398,6 +408,10 @@ class _BillingHandler(http.server.BaseHTTPRequestHandler):
|
|
|
398
408
|
path, query = parsed.path, urllib.parse.parse_qs(parsed.query)
|
|
399
409
|
if path == "/app.js":
|
|
400
410
|
return self._send(200, "text/javascript", self._bundle())
|
|
411
|
+
if path in ("/spa", "/spa/"):
|
|
412
|
+
return self._send(200, "text/html; charset=utf-8", self._spa_html())
|
|
413
|
+
if path == "/spa/app.js":
|
|
414
|
+
return self._send(200, "text/javascript", self._spa_bundle())
|
|
401
415
|
if path == "/login":
|
|
402
416
|
return self._page("Sign in", self._login_form(), user=None)
|
|
403
417
|
user = self._user()
|
|
@@ -430,8 +444,24 @@ class _BillingHandler(http.server.BaseHTTPRequestHandler):
|
|
|
430
444
|
|
|
431
445
|
def do_POST(self) -> None: # noqa: N802
|
|
432
446
|
length = int(self.headers.get("Content-Length") or 0)
|
|
433
|
-
|
|
447
|
+
raw = self.rfile.read(length).decode()
|
|
434
448
|
path = urllib.parse.urlsplit(self.path).path
|
|
449
|
+
if path == "/api/token":
|
|
450
|
+
try:
|
|
451
|
+
payload = json.loads(raw) if raw else {}
|
|
452
|
+
except json.JSONDecodeError:
|
|
453
|
+
payload = {}
|
|
454
|
+
email = str(payload.get("email") or "").strip().lower()
|
|
455
|
+
password = str(payload.get("password") or "")
|
|
456
|
+
user = USERS.get(email)
|
|
457
|
+
if not user or user.password != password:
|
|
458
|
+
return self._json(401, {"error": "Wrong email or password."})
|
|
459
|
+
sid = secrets.token_urlsafe(24)
|
|
460
|
+
self.sessions[sid] = user.email
|
|
461
|
+
token = _bearer_token(sid)
|
|
462
|
+
self.sessions[token] = user.email
|
|
463
|
+
return self._json(200, {"access_token": token}, cookie=self._cookie(sid))
|
|
464
|
+
form = urllib.parse.parse_qs(raw)
|
|
435
465
|
if path == "/login":
|
|
436
466
|
email = (form.get("email") or [""])[0].strip().lower()
|
|
437
467
|
password = (form.get("password") or [""])[0]
|
|
@@ -444,8 +474,15 @@ class _BillingHandler(http.server.BaseHTTPRequestHandler):
|
|
|
444
474
|
return self._redirect("/invoices", cookie=self._cookie(sid))
|
|
445
475
|
if path == "/logout":
|
|
446
476
|
sid = self._sid()
|
|
447
|
-
|
|
448
|
-
|
|
477
|
+
token = self._bearer()
|
|
478
|
+
if "session-after-logout" not in self.vulns:
|
|
479
|
+
if sid:
|
|
480
|
+
self.sessions.pop(sid, None)
|
|
481
|
+
if token:
|
|
482
|
+
self.sessions.pop(token, None)
|
|
483
|
+
sid_from_token = _sid_from_token(token)
|
|
484
|
+
if sid_from_token:
|
|
485
|
+
self.sessions.pop(sid_from_token, None)
|
|
449
486
|
return self._redirect("/login", cookie=self._cookie("", expire=True))
|
|
450
487
|
self._page("Not found", "<p>That page doesn't exist.</p>", self._user(), status=404)
|
|
451
488
|
|
|
@@ -577,8 +614,9 @@ if (rows) {
|
|
|
577
614
|
f"<script src='/app.js'></script></body></html>")
|
|
578
615
|
self._send(status, "text/html; charset=utf-8", doc)
|
|
579
616
|
|
|
580
|
-
def _json(self, status: int, payload) -> None:
|
|
581
|
-
|
|
617
|
+
def _json(self, status: int, payload, cookie: str = "") -> None:
|
|
618
|
+
extra = {"Set-Cookie": cookie} if cookie else None
|
|
619
|
+
self._send(status, "application/json", json.dumps(payload), extra=extra)
|
|
582
620
|
|
|
583
621
|
def _redirect(self, location: str, cookie: str = "") -> None:
|
|
584
622
|
self.send_response(303)
|
|
@@ -589,12 +627,16 @@ if (rows) {
|
|
|
589
627
|
self.send_header("Content-Length", "0")
|
|
590
628
|
self.end_headers()
|
|
591
629
|
|
|
592
|
-
def _send(self, status: int, content_type: str, body: str) -> None:
|
|
630
|
+
def _send(self, status: int, content_type: str, body: str, extra: dict | None = None) -> None:
|
|
593
631
|
data = body.encode()
|
|
594
632
|
self.send_response(status)
|
|
595
633
|
self.send_header("Content-Type", content_type)
|
|
596
634
|
self.send_header("Content-Length", str(len(data)))
|
|
597
635
|
self.send_header("Cache-Control", "no-store")
|
|
636
|
+
if extra:
|
|
637
|
+
for key, value in extra.items():
|
|
638
|
+
if value:
|
|
639
|
+
self.send_header(key, value)
|
|
598
640
|
self._security_headers()
|
|
599
641
|
self.end_headers()
|
|
600
642
|
self.wfile.write(data)
|
|
@@ -622,14 +664,125 @@ if (rows) {
|
|
|
622
664
|
jar = http.cookies.SimpleCookie(self.headers.get("Cookie") or "")
|
|
623
665
|
return jar["sid"].value if "sid" in jar else ""
|
|
624
666
|
|
|
667
|
+
def _bearer(self) -> str:
|
|
668
|
+
header = self.headers.get("Authorization") or ""
|
|
669
|
+
if header.lower().startswith("bearer "):
|
|
670
|
+
return header.split(" ", 1)[1].strip()
|
|
671
|
+
return ""
|
|
672
|
+
|
|
625
673
|
def _user(self) -> _User | None:
|
|
626
674
|
email = self.sessions.get(self._sid())
|
|
675
|
+
if not email:
|
|
676
|
+
token = self._bearer()
|
|
677
|
+
email = self.sessions.get(token) if token else None
|
|
678
|
+
if not email and token:
|
|
679
|
+
email = self.sessions.get(_sid_from_token(token) or "")
|
|
627
680
|
return USERS.get(email) if email else None
|
|
628
681
|
|
|
682
|
+
def _spa_html(self) -> str:
|
|
683
|
+
return (
|
|
684
|
+
"<!doctype html><html lang='en'><head><meta charset='utf-8'>"
|
|
685
|
+
f"<title>Acme Billing</title><style>{_STYLE}</style></head>"
|
|
686
|
+
"<body><div id='root'></div><script src='/spa/app.js'></script></body></html>"
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
def _spa_bundle(self) -> str:
|
|
690
|
+
keys = [f'const STRIPE_PUBLISHABLE = "{_PUBLISHABLE}";',
|
|
691
|
+
f'const STRIPE_TEST_SECRET = "{_TEST_SECRET}"; // local dev only']
|
|
692
|
+
if "leaked-key" in self.vulns:
|
|
693
|
+
keys.append(f'const STRIPE_SECRET = "{_LIVE_SECRET}";')
|
|
694
|
+
return "\n".join(keys) + r"""
|
|
695
|
+
const root = document.getElementById("root");
|
|
696
|
+
const token = localStorage.getItem("access_token");
|
|
697
|
+
const auth = token ? {Authorization: "Bearer " + token} : {};
|
|
698
|
+
|
|
699
|
+
function renderLogin() {
|
|
700
|
+
root.innerHTML = "<h1>Sign in</h1>" +
|
|
701
|
+
"<p><label>Email <input id='email' type='email' autocomplete='username'></label></p>" +
|
|
702
|
+
"<p><label>Password <input id='password' type='password'></label></p>" +
|
|
703
|
+
"<p><button type='button' id='signin'>Sign in</button></p>";
|
|
704
|
+
document.getElementById("signin").onclick = async () => {
|
|
705
|
+
const r = await fetch("/api/token", {
|
|
706
|
+
method: "POST",
|
|
707
|
+
headers: {"Content-Type": "application/json"},
|
|
708
|
+
body: JSON.stringify({
|
|
709
|
+
email: document.getElementById("email").value,
|
|
710
|
+
password: document.getElementById("password").value
|
|
711
|
+
})
|
|
712
|
+
});
|
|
713
|
+
const data = await r.json();
|
|
714
|
+
if (data.access_token) {
|
|
715
|
+
localStorage.setItem("access_token", data.access_token);
|
|
716
|
+
location.hash = "";
|
|
717
|
+
location.reload();
|
|
718
|
+
} else {
|
|
719
|
+
root.insertAdjacentHTML("afterbegin", "<p role='alert'>Wrong email or password.</p>");
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function nav(email, role) {
|
|
725
|
+
const admin = role === "admin" ? "<a href='/admin'>Admin</a>" : "";
|
|
726
|
+
return "<nav><a href='/invoices'>Invoices</a><a href='/account'>Account</a>" +
|
|
727
|
+
"<a href='/handbook'>Handbook</a>" + admin +
|
|
728
|
+
"<button type='button' id='signout'>Sign out</button>" +
|
|
729
|
+
"<span>Signed in as " + email + "</span></nav>";
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (!token) {
|
|
733
|
+
renderLogin();
|
|
734
|
+
} else {
|
|
735
|
+
fetch("/api/invoices", {headers: auth}).then(r => r.json()).then(list => {
|
|
736
|
+
if (!Array.isArray(list)) { renderLogin(); return; }
|
|
737
|
+
const rows = list.map(i =>
|
|
738
|
+
"<tr><td><a href='/invoices/" + i.id + "'>#" + i.id + "</a></td><td>" +
|
|
739
|
+
i.description + "</td><td>$" + i.amount + "</td></tr>").join("") ||
|
|
740
|
+
"<tr><td>No invoices yet</td></tr>";
|
|
741
|
+
root.innerHTML = nav("", "") + "<h1>Your invoices</h1>" +
|
|
742
|
+
"<table><thead><tr><th>Invoice</th><th>Description</th><th>Amount</th></tr></thead>" +
|
|
743
|
+
"<tbody id='invoice-rows'>" + rows + "</tbody></table>" +
|
|
744
|
+
"<form action='/search'><label>Search invoices <input name='q'></label> " +
|
|
745
|
+
"<button>Search</button></form>";
|
|
746
|
+
fetch("/api/admin/users", {headers: auth}).catch(() => {});
|
|
747
|
+
fetch("/account", {headers: auth}).then(r => r.text()).then(html => {
|
|
748
|
+
const m = html.match(/Signed in as ([^<]+)/);
|
|
749
|
+
if (m) {
|
|
750
|
+
const span = root.querySelector("nav span");
|
|
751
|
+
if (span) span.textContent = "Signed in as " + m[1];
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
const out = document.getElementById("signout");
|
|
755
|
+
if (out) out.onclick = async () => {
|
|
756
|
+
await fetch("/logout", {method: "POST", headers: auth});
|
|
757
|
+
localStorage.removeItem("access_token");
|
|
758
|
+
location.reload();
|
|
759
|
+
};
|
|
760
|
+
}).catch(() => renderLogin());
|
|
761
|
+
}
|
|
762
|
+
"""
|
|
763
|
+
|
|
629
764
|
def log_message(self, *args) -> None: # keep benchmark output clean
|
|
630
765
|
pass
|
|
631
766
|
|
|
632
767
|
|
|
768
|
+
def _bearer_token(sid: str) -> str:
|
|
769
|
+
payload = json.dumps({"sid": sid}, separators=(",", ":")).encode()
|
|
770
|
+
middle = base64.urlsafe_b64encode(payload).decode().rstrip("=")
|
|
771
|
+
return "eyJhbGciOiJub25lIn0." + middle + ".sig"
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
def _sid_from_token(token: str) -> str:
|
|
775
|
+
parts = token.split(".")
|
|
776
|
+
if len(parts) != 3:
|
|
777
|
+
return ""
|
|
778
|
+
pad = "=" * (-len(parts[1]) % 4)
|
|
779
|
+
try:
|
|
780
|
+
data = json.loads(base64.urlsafe_b64decode(parts[1] + pad))
|
|
781
|
+
except Exception: # noqa: BLE001
|
|
782
|
+
return ""
|
|
783
|
+
return str(data.get("sid") or "")
|
|
784
|
+
|
|
785
|
+
|
|
633
786
|
@contextmanager
|
|
634
787
|
def serve_billing(vulns: tuple[str, ...] | list[str] = ()) -> Iterator[str]:
|
|
635
788
|
"""Serve Acme Billing on 127.0.0.1 with `vulns` planted; yields its base URL."""
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Same planted vulnerabilities as billing-security, against the JavaScript
|
|
2
|
+
# front end at /spa/ (empty HTML, token in localStorage, JSON login).
|
|
3
|
+
name: billing-security-spa
|
|
4
|
+
kind: security
|
|
5
|
+
version: 1
|
|
6
|
+
description: Security checks on the Acme Billing SPA (browser sign-in, ADR-011)
|
|
7
|
+
platform: playwright
|
|
8
|
+
site: billing
|
|
9
|
+
path: /spa/
|
|
10
|
+
|
|
11
|
+
accounts:
|
|
12
|
+
admin:
|
|
13
|
+
role: admin
|
|
14
|
+
auth: browser
|
|
15
|
+
login: "Sign in with email admin@acme.test and password admin-pass"
|
|
16
|
+
alice:
|
|
17
|
+
role: member
|
|
18
|
+
auth: browser
|
|
19
|
+
login: "Sign in with email alice@acme.test and password alice-pass"
|
|
20
|
+
bob:
|
|
21
|
+
role: member
|
|
22
|
+
auth: browser
|
|
23
|
+
login: "Sign in with email bob@acme.test and password bob-pass"
|
|
24
|
+
|
|
25
|
+
vulnerabilities:
|
|
26
|
+
idor-page:
|
|
27
|
+
check: access
|
|
28
|
+
paths: [/invoices]
|
|
29
|
+
description: "Any member can open another member's invoice page at /invoices/<id>"
|
|
30
|
+
idor-api:
|
|
31
|
+
check: access
|
|
32
|
+
paths: [/api/invoices]
|
|
33
|
+
description: "Any member can read another member's invoice from /api/invoices/<id>"
|
|
34
|
+
admin-route:
|
|
35
|
+
check: roles
|
|
36
|
+
paths: [/admin, /api/admin]
|
|
37
|
+
description: "Members can open /admin and /api/admin/users; only the nav link is hidden"
|
|
38
|
+
session-after-logout:
|
|
39
|
+
check: session
|
|
40
|
+
rule: session-after-logout
|
|
41
|
+
description: "Sign out clears the cookie but the server keeps the session, so the old cookie still works"
|
|
42
|
+
weak-cookie:
|
|
43
|
+
check: session
|
|
44
|
+
rule: cookie-flags
|
|
45
|
+
description: "The sid session cookie has no HttpOnly or SameSite"
|
|
46
|
+
no-csp:
|
|
47
|
+
check: exposure
|
|
48
|
+
rule: missing-csp
|
|
49
|
+
description: "No Content-Security-Policy header (framing is still blocked by X-Frame-Options)"
|
|
50
|
+
leaked-key:
|
|
51
|
+
check: exposure
|
|
52
|
+
rule: secret-in-js
|
|
53
|
+
match: [sk_live_]
|
|
54
|
+
description: "A live Stripe secret key is shipped in /spa/app.js"
|
|
55
|
+
stack-trace:
|
|
56
|
+
check: exposure
|
|
57
|
+
rule: stack-trace
|
|
58
|
+
description: "An empty search returns a 500 page with a Python traceback"
|
|
59
|
+
|
|
60
|
+
decoys:
|
|
61
|
+
shared-handbook:
|
|
62
|
+
check: access
|
|
63
|
+
paths: [/handbook]
|
|
64
|
+
description: "The team handbook is the same page for every member, by design"
|
|
65
|
+
public-profile:
|
|
66
|
+
check: access
|
|
67
|
+
paths: [/u]
|
|
68
|
+
description: "Public profiles show a display name to every signed-in member, and say so"
|
|
69
|
+
protected-audit:
|
|
70
|
+
check: roles
|
|
71
|
+
paths: [/admin/audit]
|
|
72
|
+
description: "The audit log link is hidden from members and the server also refuses them"
|
|
73
|
+
framing-via-csp:
|
|
74
|
+
check: exposure
|
|
75
|
+
rule: missing-frame-protection
|
|
76
|
+
description: "No X-Frame-Options, because CSP frame-ancestors 'none' covers framing"
|
|
77
|
+
publishable-key:
|
|
78
|
+
check: exposure
|
|
79
|
+
rule: secret-in-js
|
|
80
|
+
match: [pk_live_, sk_test_]
|
|
81
|
+
description: "A publishable pk_live key and a test-mode sk_test key in /spa/app.js belong there"
|
|
82
|
+
|
|
83
|
+
variants:
|
|
84
|
+
- name: clean
|
|
85
|
+
vulnerabilities: []
|
|
86
|
+
- name: pages
|
|
87
|
+
vulnerabilities: [idor-page, admin-route, weak-cookie, no-csp]
|
|
88
|
+
- name: api
|
|
89
|
+
vulnerabilities: [idor-api, session-after-logout, leaked-key, stack-trace]
|