bug report info: the settings lines go through an allowlist too (review 2)

Variable values showed lists of the title's program hashes (LEONIDA_PAIRED_FOR and the like), program names and
URLs. A value is now shown as it is only when it is a number, true/false or a short word; a list shows its count
(<44 entries>), anything else <set>. Windows, the card, the profile, the upscaler and frame generation go word by
word through an allowlist (short words, numbers, model numbers such as A770, the (R)/(TM) marks); the resolution
must look like 1080 or 2560x1080. Tests cover the reviewer's probes and that real card names stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MoonEyes
2026-12-03 12:04:24 +01:00
parent 7cc1c18e16
commit 63baede940
2 changed files with 69 additions and 15 deletions

View File

@ -193,7 +193,7 @@ class ReportTests(unittest.TestCase):
def test_paths_in_variables_are_not_shown(self):
text = build(variables={"LEONIDA_CACHE_DIR": r"C:\Users\bob\cache", "LEONIDA_X": "/home/bob/x", "LEONIDA_Y": "2"})
self.assertNotIn("bob", text)
self.assertIn("LEONIDA_CACHE_DIR=<path>", text)
self.assertIn("LEONIDA_CACHE_DIR=<set>", text)
self.assertIn("LEONIDA_Y=2", text)
def test_commit_hash_stays(self):
@ -237,6 +237,36 @@ class LauncherTests(unittest.TestCase):
class SettingsLeakTests(unittest.TestCase):
def test_program_lists_show_only_their_count(self):
text = build(CARD_LOG, "", variables={"LEONIDA_PAIRED_FOR": ",".join(["0123456789abcdef"] * 44),
"LEONIDA_X": "PS_WaterDeep", "LEONIDA_URL": "http://x/y",
"LEONIDA_FG_LIMIT_FPS": "60", "LEONIDA_ON": "true"})
self.assertNotIn("0123456789abcdef", text)
self.assertNotIn("WaterDeep", text)
self.assertNotIn("http", text)
self.assertIn("LEONIDA_PAIRED_FOR=<44 entries>", text)
self.assertIn("LEONIDA_X=<set>", text)
self.assertIn("LEONIDA_FG_LIMIT_FPS=60", text)
self.assertIn("LEONIDA_ON=true", text)
def test_names_the_launcher_knows_go_through_the_allowlist(self):
log = 'INFO x: card="NVIDIA RTX D:\\jsmith\\x PS_y"\n'
text = build(log, "", console="series-s PS_x", args=["-Resolution", "PS_x", "-Dlss", "jsmith\\a"],
system=r"Windows 11 \\srv\jsmith")
for leak in ("PS_", "srv", "D:\\", "jsmith\\"):
self.assertNotIn(leak, text)
self.assertIn("Resolution: <set>", text)
def test_real_names_stay(self):
text = build('INFO x: card="Intel(R) Arc(TM) A770 Graphics"\n', "")
self.assertIn("GPU: Intel(R) Arc(TM) A770 Graphics", text)
self.assertIn("GPU: AMD Radeon RX 7800 XT", build('INFO y: card="AMD Radeon RX 7800 XT"\n', ""))
self.assertIn("Windows: Windows 11 (10.0.26300)", text)
self.assertIn("Console profile: series-x", text)
class StatusCodes(unittest.TestCase):
def test_windows_status_codes_are_kept_and_addresses_are_not(self):
out = info.scrub_line("exception 0xC0000409 at 0x7FF6A1B2C3D4, hr 0x887A0005, then 0x80070057; ptr 0x1234ABCD")

View File

@ -194,12 +194,35 @@ def read_log_ends(path: str, head: int = 256 * 1024, tail: int = 2 * 1024 * 1024
# ---------------------------------------------------------------- the settings
SAFE_TOKEN = re.compile(r"[A-Za-z]{1,12}(?:-[A-Za-z0-9]{1,6})?|\d+(?:[.,]\d+)*x?|[A-Za-z]{1,4}\d{1,5}[A-Za-z]{0,2}")
SAFE_VALUE = re.compile(r"[-+]?\d+(?:[.,]\d+)?|true|false|on|off|yes|no|[A-Za-z]{1,12}")
RESOLUTION = re.compile(r"\d{3,5}(?:x\d{3,5})?")
VERSION = re.compile(r"(?:[0-9a-f]{7,40}(?: \d{4}-\d{2}-\d{2})?|zip copy|unknown)")
def safe_text(text: str) -> str:
"""A setting or a name the launcher knows (Windows, the card, the profile), word by word through an allowlist:
short plain words, numbers, model numbers (A770, 4070, RX); anything else is <removed>, once in a row."""
out: list[str] = []
for word in scrub_home(text).split():
core = re.sub(r"\((?:R|TM|C)\)", "", word).strip("()[],;")
kept = word if core and SAFE_TOKEN.fullmatch(core) and not HEX_WORD.fullmatch(core) else REMOVED
if kept == REMOVED and out and out[-1] == REMOVED:
continue
out.append(kept)
return " ".join(out)[:MAX_LINE]
def _shown_value(value: str) -> str:
"""A value of a setting as it goes in the block: a path is not shown (it can name the user)."""
"""A setting's value as it goes in the block: a number, true/false or a short word as it is; a list (the
per-program lists such as LEONIDA_PAIRED_FOR name the title's programs) as its count; anything else <set>."""
value = str(value).strip()
if re.match(r"^[A-Za-z]:[\\/]", value) or value.startswith(("\\\\", "/")) or "\\" in value:
return "<path>"
return scrub_home(value)
if SAFE_VALUE.fullmatch(value):
return value
parts = [p for p in re.split(r"[,;\s]+", value) if p]
if len(parts) > 1:
return f"<{len(parts)} entries>"
return "<set>"
def describe_options(args: list[str]) -> dict:
@ -232,17 +255,18 @@ def build_report(version: str, system: str, console: str, args: list[str], varia
shown = [f"{name}={_shown_value(value)}" for name, value in sorted(variables.items())]
head = [
"Leonida bug report info",
f"Version: {scrub_home(version)}",
f"Windows: {scrub_home(system)}",
f"GPU: {gpu['name'] or NOT_IN_LOG}",
f"Driver: {scrub_home(driver) if driver else NOT_IN_LOG}",
f"Version: {version if VERSION.fullmatch(str(version).strip()) else safe_text(version)}",
f"Windows: {safe_text(system)}",
f"GPU: {safe_text(gpu['name']) if gpu['name'] else NOT_IN_LOG}",
f"Driver: {safe_text(driver) if driver else NOT_IN_LOG}",
f"Video memory: {str(gpu['memory_mb']) + ' MB' if gpu['memory_mb'] else NOT_IN_LOG}",
f"Console profile: {scrub_home(console)}",
f"Resolution: {options['resolution']}",
f"Upscaler: {options['upscaler']}",
f"Frame generation: {options['frame_gen']}",
"Options: " + scrub_home(" ".join(_shown_value(a) for a in args) or "(defaults)"),
"Variables: " + (scrub_home("; ".join(shown)) if shown else "(none)"),
f"Console profile: {safe_text(console)}",
f"Resolution: {options['resolution'] if RESOLUTION.fullmatch(options['resolution']) or options['resolution'] == 'default' else '<set>'}",
f"Upscaler: {safe_text(options['upscaler'])}",
f"Frame generation: {safe_text(options['frame_gen'])}",
"Options: " + (" ".join(a if re.fullmatch(r"-[A-Za-z]{1,24}", a) else _shown_value(a) for a in args)[:MAX_LINE]
or "(defaults)"),
"Variables: " + ("; ".join(shown)[:MAX_LINE] if shown else "(none)"),
]
if log_head is None and log_tail is None:
tail = ["Last errors: no play log found (turn on Log in Settings or use Run in diagnostic mode)"]