Files
Open_Ultra_SAST/tests/test_search_browser.py
T
Marius Ciepluch f756099c9d fix(search-with-proof): a chromium failure names the first line of its output, where its cause is
The CI run on 1721b58 (run 46191667349) failed
tests/test_search_browser.py::test_real_browser_executes_not_reflects with
"headless chromium did not produce a document:" and a register dump. On
2026-11-24 the same test failed for the opposite reason: chromium printed
"FATAL ... No usable sandbox!" and did not exit, and the launch timed out. Since
c4720ba the test skips on that evidence in the launch error's cause. In the run
of 2026-11-28 chromium returned, and the error carried the last 500 characters
of its stderr only, the end of the dump. The skip could not see the cause, so
the test failed.

What changed
- src/openultrasast/search/oracles.py: the error of a chromium run without a
  document now carries the whole stderr up to 500 characters. For a longer
  output it carries the first 400 characters, " ... ", and the last 100
  (_stderr_excerpt). chromium prints its cause first.
- tests/test_search_browser.py: one new test. A chromium that prints a cause and
  then a long trace raises an error that names the cause.

Checks
- s10_ci3_red.out: the new test at HEAD 1721b58: 1 failed, 4 passed.
- s10_ci3_green.out: after the change, the six test files whose text names the
  oracles or BrowserExecutor (browser, control, demo_replay, isolation, probe,
  verify): 113 passed in the project environment and 113 passed in a separate
  environment made from the lockfile.
- s10_ci3_exits.txt: the gates with label ci3, ten zeros. s10_ci3_diffcheck.out:
  two files, +21 -1; git diff --check exits 0.
- The s10 files are under /tmp/opencode, outside the repository.

Not verified
- The run on GitHub. The start of chromium's output on the runner is in no log.
  It may be the same "No usable sandbox!", another fatal line of the sandbox
  code, or error lines that push the cause past the first 400 characters: the
  error names a cause only within its first 400 characters or its last 100. The
  runner image does not explain the failure. The same register dump failed the
  release job of 2026-11-06, and the two runs before this one that evening did
  not fail this test.
- tests/test_search_probe.py::test_task_boundary_probe_executes_packaged_pairs[real]
  failed on the runner in two runs with a status whose cause the output cut,
  and passed in the third. Its record is printed since 1721b58 if it fails again.

Review.
Read-only, with independent reruns under /tmp/opencode/s10_rev_ci3/. Both logs hold the
core of the story: on 2026-11-24 the launch timed out and the stderr of its cause starts
with the fatal line (s10_ci0_checks_job.log:2644, 2657); in run 46191667349 chromium
returned and oracles.py:282 kept the last 500 characters, registers only
(s10_ci3_checks_plain.log:983-989). The new test, run against the oracles.py of 1721b58,
fails as recorded (AssertionError at line 27, 1 failed, 4 passed, pytest exit 1); with
the change the file gives 5 passed. The image does not explain the failure: the same
register dump is in the release job of 2026-11-06 (s9_c9_job_failed.out:966), and the two
runs before it that evening did not fail this test. Not verified: the start of chromium's
output there. A cause is named only within its first 400 characters or its last 100.
2026-11-28 23:17:59 +01:00

69 lines
3.0 KiB
Python

import html
import shutil
import subprocess
import pytest
from openultrasast.search.oracles import BrowserExecutor
def test_browser_launch_failure_is_not_negative(monkeypatch):
def fail(*args, **kwargs):
return subprocess.CompletedProcess(args, 1, "", "failed")
monkeypatch.setattr(subprocess, "run", fail)
with pytest.raises(OSError):
BrowserExecutor(binary="/fake/chromium")('<script>alert("ousast-xss")</script>', "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")('<script>alert("ousast-xss")</script>', "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():
browser = BrowserExecutor()
payload = '<script>alert("ousast-xss")</script>'
try:
observed = browser(payload, "nonce")
except OSError as exc:
# A present binary is insufficient on restricted hosts. Only known
# host permission denials skip; ordinary browser failures remain failures.
# oracles.py raises a fixed message `from` the launch error: the cause carries the evidence.
cause = exc.__cause__ or exc
evidence = " ".join(str(part) for part in (cause, getattr(cause, "stderr", None)))
denied = next((text for text in ("No usable sandbox", "Operation not permitted", "Permission denied") if text in evidence), None)
if denied:
pytest.skip("host denies browser isolation/socket setup: " + denied)
raise
assert observed
assert not browser(html.escape(payload), "nonce")
assert not browser("<p>nonce</p>", "nonce")
@pytest.mark.parametrize("executed", [False, True])
@pytest.mark.sandbox
def test_marker_is_dom_attribute_not_source_text(monkeypatch, executed):
import re
from urllib.parse import unquote
def run(command, **kwargs):
assert "--headless" in command and "--dump-dom" in command
assert "--unshare-all" in command and "--no-sandbox" not in command
document = unquote(command[-1].split(",", 1)[1])
attr, value = re.search(r'setAttribute\("([^"]+)","([^"]+)"\)', document).groups()
root = f'<html {attr}="{value}">' if executed else "<html>"
return subprocess.CompletedProcess(command, 0, root + document + "</html>", "")
monkeypatch.setattr(subprocess, "run", run)
assert BrowserExecutor(binary="/usr/bin/chromium")("<p>reflected nonce</p>", "nonce") is executed