diff --git a/src/openultrasast/search/oracles.py b/src/openultrasast/search/oracles.py index 72aca91f..51bce394 100644 --- a/src/openultrasast/search/oracles.py +++ b/src/openultrasast/search/oracles.py @@ -190,6 +190,13 @@ class SSRFOracle(OutputOracle): self.process.stdout.close() +def _stderr_excerpt(stderr: str) -> str: + """The start of chromium's output, where its cause is printed, and the end of a long crash trace.""" + if len(stderr) <= 500: + return stderr + return stderr[:400] + " ... " + stderr[-100:] + + class BrowserExecutor: """Run captured HTML with a verifier-owned alert canary. @@ -279,7 +286,8 @@ class BrowserExecutor: except subprocess.SubprocessError as exc: raise OSError("headless chromium failed") from exc if done.returncode or "alert("ousast-xss")', "nonce") +def test_browser_error_names_the_first_line_of_chromium_output(monkeypatch): + # chromium prints its cause first ("No usable sandbox!"), then a stack trace and a register dump. + stderr = "FATAL:zygote_host_impl_linux.cc:144] No usable sandbox!\n" + "#0 0x0000000000000000\n" * 400 + "[end of stack trace]" + + def run(*args, **kwargs): + return subprocess.CompletedProcess(args, 1, "", stderr) + + monkeypatch.setattr(subprocess, "run", run) + with pytest.raises(OSError, match="No usable sandbox"): + BrowserExecutor(binary="/fake/chromium")('', "nonce") + + @pytest.mark.skipif(not (shutil.which("chromium") or shutil.which("chromium-browser")), reason="chromium not installed") @pytest.mark.sandbox def test_real_browser_executes_not_reflects():