mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-18 04:29:27 +00:00
search-with-proof: ecosystem-aware build recipes and stderr in build failures
The agent passes a manifest file or project directory; pip uses -r for requirements files and the directory for pyproject/setup, npm ci/install runs in the directory, composer/maven/gradle likewise. Build and verify failures carry phase, exit code and a sanitised stderr tail. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
bf243e6680
commit
3866e2771b
@@ -9,6 +9,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import tomllib
|
||||
from pathlib import Path, PurePosixPath
|
||||
from typing import Any, cast
|
||||
|
||||
@@ -145,6 +146,75 @@ def checkout_path(value: Any) -> str:
|
||||
return value
|
||||
|
||||
|
||||
_MANIFESTS = {
|
||||
"pip": ("pyproject.toml", "setup.py", "setup.cfg"),
|
||||
"npm": ("package.json", "package-lock.json"),
|
||||
"composer": ("composer.json", "composer.lock"),
|
||||
"maven": ("pom.xml",),
|
||||
"gradle": ("build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts", "gradlew"),
|
||||
}
|
||||
|
||||
|
||||
def build_project(recipe: str, path: Path, checkout: Path) -> Path:
|
||||
"""Validate the recipe ecosystem against actual checkout files."""
|
||||
|
||||
def manifest(candidate: Path) -> bool:
|
||||
return candidate.name in _MANIFESTS[recipe] or (recipe == "pip" and candidate.match("requirements*.txt"))
|
||||
|
||||
def contained(candidate: Path) -> bool:
|
||||
return candidate.resolve().is_relative_to(checkout.resolve())
|
||||
|
||||
if not contained(path):
|
||||
raise ValueError("recipe input outside checkout")
|
||||
if path.is_file():
|
||||
if not manifest(path):
|
||||
raise ValueError("recipe input is not an ecosystem manifest")
|
||||
return path.parent
|
||||
if path.is_dir() and any(p.is_file() and contained(p) and manifest(p) for p in path.iterdir()):
|
||||
return path
|
||||
raise ValueError("recipe input must be an ecosystem manifest or project directory")
|
||||
|
||||
|
||||
def preparation_command(recipe: str, path: Path, checkout: Path, products: Path) -> tuple[list[str], Path]:
|
||||
project = build_project(recipe, path, checkout)
|
||||
if recipe == "pip":
|
||||
requirements = path if path.is_file() and path.match("requirements*.txt") else None
|
||||
pyproject = project / "pyproject.toml"
|
||||
backend = False
|
||||
if requirements is None and pyproject.is_file():
|
||||
if not pyproject.resolve().is_relative_to(checkout.resolve()):
|
||||
raise ValueError("recipe input outside checkout")
|
||||
backend = bool(tomllib.loads(pyproject.read_text()).get("build-system", {}).get("build-backend"))
|
||||
if requirements is None and not backend and not (project / "setup.py").is_file():
|
||||
fallback = project / "requirements.txt"
|
||||
if fallback.is_file():
|
||||
requirements = fallback
|
||||
target = requirements or project
|
||||
if not target.resolve().is_relative_to(checkout.resolve()):
|
||||
raise ValueError("recipe input outside checkout")
|
||||
return [
|
||||
"python3",
|
||||
"-I",
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"--no-deps",
|
||||
"--target",
|
||||
str(products / "packages"),
|
||||
*(["-r", str(target)] if requirements else [str(target)]),
|
||||
], project
|
||||
if recipe == "npm":
|
||||
return ["npm", "ci" if (project / "package-lock.json").is_file() else "install", "--ignore-scripts"], project
|
||||
if recipe == "composer":
|
||||
return ["composer", "install", "--no-interaction", "--no-plugins", "--no-scripts"], project
|
||||
if recipe == "maven":
|
||||
return ["mvn", "-q", "-DskipTests", "package", "-f", str(project / "pom.xml")], project
|
||||
wrapper = project / "gradlew"
|
||||
if not wrapper.is_file() or not wrapper.resolve().is_relative_to(checkout.resolve()):
|
||||
raise ValueError("missing or external Gradle wrapper")
|
||||
return ["/bin/sh", str(wrapper), "--no-daemon", "--project-dir", str(project), "assemble"], project
|
||||
|
||||
|
||||
def _text(value: Any, names: set[str]) -> str:
|
||||
if not isinstance(value, str) or "\0" in value or len(value.encode()) > MAX_VALUE_BYTES:
|
||||
raise ValueError("invalid or oversized value")
|
||||
@@ -163,7 +233,7 @@ def _arguments(value: Any, names: set[str]) -> None:
|
||||
_text(arg, names)
|
||||
|
||||
|
||||
def validate_demo(value: Any) -> dict[str, Any]:
|
||||
def validate_demo(value: Any, *, checkout: Path | None = None) -> dict[str, Any]:
|
||||
try:
|
||||
encoded = json.dumps(value, allow_nan=False).encode()
|
||||
except (ValueError, TypeError, RecursionError) as exc:
|
||||
@@ -186,8 +256,10 @@ def validate_demo(value: Any) -> dict[str, Any]:
|
||||
else:
|
||||
if len(args) != 1:
|
||||
raise ValueError("recipe requires one checkout path")
|
||||
if not (recipe in ("npm", "composer", "gradle") and args[0] == "."):
|
||||
if args[0] != ".":
|
||||
checkout_path(args[0])
|
||||
if checkout is not None:
|
||||
build_project(recipe, checkout / args[0], checkout)
|
||||
_keys(start, {"runtime", "path", "arguments", "mode"}, {"port"})
|
||||
if not isinstance(start["runtime"], str) or start["runtime"] not in RUNTIMES:
|
||||
raise ValueError("unknown runtime")
|
||||
|
||||
@@ -269,12 +269,12 @@ class InProcessExecutor:
|
||||
"isolation_mode": self.isolation_mode,
|
||||
"exit_code": result.exit_code,
|
||||
"stdout": result.stdout[:16384],
|
||||
"stderr": task_storage.diagnostic(result.stderr, maximum=4000),
|
||||
"stderr": task_storage.diagnostic(result.stderr, maximum=1500),
|
||||
"timed_out": result.timed_out,
|
||||
"truncated": len(result.stdout) > 16384 or len(result.stderr) > 16384,
|
||||
}
|
||||
|
||||
def _task_run(self, argv: list[str], timeout: float, limits: dict[str, Any]) -> dict[str, Any]:
|
||||
def _task_run(self, argv: list[str], timeout: float, limits: dict[str, Any], *, cwd: Path | None = None) -> dict[str, Any]:
|
||||
process_limit = None
|
||||
try:
|
||||
uid = os.getuid()
|
||||
@@ -311,7 +311,7 @@ class InProcessExecutor:
|
||||
self.phase = "spawn"
|
||||
with tempfile.TemporaryFile() as out, tempfile.TemporaryFile() as err:
|
||||
proc = subprocess.Popen(
|
||||
argv, cwd=self.repo, env=clean_environment(), stdout=out, stderr=err, start_new_session=True, preexec_fn=constrain
|
||||
argv, cwd=cwd or self.repo, env=clean_environment(), stdout=out, stderr=err, start_new_session=True, preexec_fn=constrain
|
||||
)
|
||||
self.phase = "run"
|
||||
timed_out = False
|
||||
@@ -358,7 +358,7 @@ class InProcessExecutor:
|
||||
proc.wait()
|
||||
out.seek(0)
|
||||
err.seek(max(0, os.fstat(err.fileno()).st_size - 16384))
|
||||
stderr = task_storage.diagnostic(err.read().decode(errors="replace"), maximum=4000)
|
||||
stderr = task_storage.diagnostic(err.read().decode(errors="replace"), maximum=1500)
|
||||
phase = "scratch guard" if disk_exceeded else "timeout" if timed_out else self.phase
|
||||
if disk_exceeded:
|
||||
self.stopped = True
|
||||
@@ -389,14 +389,14 @@ class InProcessExecutor:
|
||||
"""Build and export through the host-scoped output URL, never a model URL."""
|
||||
import shutil
|
||||
|
||||
from .demo import BUILD_RECIPES, validate_demo
|
||||
from .demo import preparation_command, validate_demo
|
||||
from .verify import _tree
|
||||
from .verify_task import pack_checkout, validate_spec
|
||||
|
||||
if not self.task_boundary or not self.prepared_put_url:
|
||||
raise ValueError("preparation requires an executor task output")
|
||||
spec = copy.deepcopy(spec)
|
||||
validate_demo(spec["demo"])
|
||||
validate_demo(spec["demo"], checkout=self.repo)
|
||||
recipe = spec["demo"]["build"]
|
||||
spec["demo"]["build"] = {"recipe": "none", "arguments": []}
|
||||
validate_spec(spec)
|
||||
@@ -406,22 +406,16 @@ class InProcessExecutor:
|
||||
products.mkdir()
|
||||
if recipe["recipe"] != "none":
|
||||
path = self._path(recipe["arguments"][0])
|
||||
argv = [
|
||||
arg.replace("/scratch", str(products))
|
||||
for arg in BUILD_RECIPES[recipe["recipe"]]
|
||||
if arg not in {"--offline", "--no-index"}
|
||||
]
|
||||
argv.append(str(path))
|
||||
if recipe["recipe"] == "maven":
|
||||
argv += ["package", "-DskipTests"]
|
||||
elif recipe["recipe"] == "gradle":
|
||||
# The project pins its Gradle version through its wrapper.
|
||||
# Invoke with sh because checkout archives may lose execute bits.
|
||||
wrapper = self._path(str(path.relative_to(self.repo) / "gradlew"))
|
||||
argv = ["/bin/sh", str(wrapper), "--no-daemon", "--project-dir", str(path), "assemble"]
|
||||
built = self._task_run(argv, self._remaining(), {"disk_bytes": task_storage.DEFAULT_SCRATCH_BYTES, **limits})
|
||||
argv, project = preparation_command(recipe["recipe"], path, self.repo, products)
|
||||
self.phase = "build"
|
||||
built = self._task_run(argv, self._remaining(), {"disk_bytes": task_storage.DEFAULT_SCRATCH_BYTES, **limits}, cwd=project)
|
||||
if built.get("disk_limit_exceeded") or built["exit_code"] or built["timed_out"]:
|
||||
return {**built, "status": "could_not_build"}
|
||||
return {
|
||||
**built,
|
||||
"status": "could_not_build",
|
||||
"phase": "build",
|
||||
"stderr": task_storage.diagnostic(built.get("stderr", ""), maximum=1500),
|
||||
}
|
||||
# Validate internal generated links before materializing them as
|
||||
# regular archive members. No host/external files may be exported.
|
||||
_tree(self.repo, generated_links=True)
|
||||
|
||||
@@ -15,16 +15,16 @@ import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
from dataclasses import asdict
|
||||
from dataclasses import asdict, replace
|
||||
from importlib.resources import files
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from . import _sandbox
|
||||
from .demo import FAMILY_ORACLES
|
||||
from .demo import FAMILY_ORACLES, load_demo
|
||||
from .oracles import BrowserExecutor
|
||||
from .task_storage import exception_reason
|
||||
from .verify import Side, verify
|
||||
from .verify import Side, VerificationRecord, verify, verify_side_task
|
||||
|
||||
FAMILIES = ("sql", "path", "command", "ssrf", "xss")
|
||||
PAYLOADS = {
|
||||
@@ -105,6 +105,55 @@ def namespace_facts() -> dict[str, Any]:
|
||||
return facts
|
||||
|
||||
|
||||
def _verify_task_pair(sides: tuple[Side, Side], demo: Path, family: str) -> VerificationRecord:
|
||||
"""Exercise the task executor on packaged toys only, not arbitrary checkouts.
|
||||
|
||||
Repetitions get fresh scratch, but share this probe task's outer boundary.
|
||||
This is an instrument self-test, not a fresh-task dispatcher for evidence.
|
||||
"""
|
||||
started = time.monotonic()
|
||||
records = []
|
||||
try:
|
||||
load_demo(demo)
|
||||
except (OSError, ValueError) as exc:
|
||||
return VerificationRecord(
|
||||
"inconclusive",
|
||||
(),
|
||||
time.monotonic() - started,
|
||||
"invalid declarative demo: " + exception_reason(exc),
|
||||
isolation_mode="task-boundary",
|
||||
)
|
||||
search_family = next(f for f, kinds in FAMILY_ORACLES.items() if family in kinds)
|
||||
for side in sides:
|
||||
runs = [verify_side_task(side, demo, search_family) for _ in range(3)]
|
||||
first = next((run for run in runs if run.outcome != "observed"), runs[0])
|
||||
records.append(
|
||||
replace(
|
||||
first,
|
||||
runs=tuple(observation for run in runs for observation in run.runs),
|
||||
elapsed_seconds=sum(run.elapsed_seconds for run in runs),
|
||||
build_seconds=sum(run.build_seconds for run in runs),
|
||||
ready_seconds=sum(run.ready_seconds for run in runs),
|
||||
run_seconds=sum(run.run_seconds for run in runs),
|
||||
scratch_peak_bytes=max(run.scratch_peak_bytes for run in runs),
|
||||
reason=first.reason if first.outcome != "observed" else "three probe task executions completed",
|
||||
)
|
||||
)
|
||||
demonstrated = (
|
||||
all(side.outcome == "observed" and len(side.runs) == 3 for side in records)
|
||||
and all(run.observed for run in records[0].runs)
|
||||
and not any(run.observed for run in records[1].runs)
|
||||
)
|
||||
return VerificationRecord(
|
||||
"demonstrated" if demonstrated else "inconclusive",
|
||||
tuple(records),
|
||||
time.monotonic() - started,
|
||||
"owned effect in 3/3 affected runs and 0/3 safe runs" if demonstrated else "no consistent differential effect",
|
||||
isolation_mode="task-boundary",
|
||||
chromium_no_sandbox=any(side.chromium_no_sandbox for side in records),
|
||||
)
|
||||
|
||||
|
||||
def probe(root: Path) -> dict[str, Any]:
|
||||
record: dict[str, Any] = {
|
||||
"status": "ok",
|
||||
@@ -114,26 +163,54 @@ def probe(root: Path) -> dict[str, Any]:
|
||||
"isolation_check": None,
|
||||
"isolation_mode": _sandbox.isolation_mode(),
|
||||
}
|
||||
namespaces = record["namespaces"]
|
||||
if namespaces and all(namespaces[name]["exit_code"] != 0 for name in ("user", "pid", "net", "ipc", "uts", "mount")):
|
||||
record["isolation_mode"] = "task-boundary"
|
||||
task_boundary = record["isolation_mode"] == "task-boundary"
|
||||
if task_boundary:
|
||||
# Real verification still needs fresh side tasks; only these packaged
|
||||
# self-test applications share the probe task's boundary.
|
||||
record["requires_fresh_side_tasks"] = True
|
||||
start = time.monotonic()
|
||||
try:
|
||||
_sandbox.isolation_check()
|
||||
record["isolation_check"] = {"status": "ok", "input_bytes": len(b"isolation-ready\n")}
|
||||
if task_boundary:
|
||||
record["isolation_check"] = {"status": "skipped", "reason": "task-boundary"}
|
||||
else:
|
||||
_sandbox.isolation_check()
|
||||
record["isolation_check"] = {"status": "ok", "input_bytes": len(b"isolation-ready\n")}
|
||||
for family in FAMILIES:
|
||||
sides, demos = materialise(root / family, family)
|
||||
results: dict[str, Any] = {}
|
||||
record["oracles"][family] = results
|
||||
for name, demo in demos.items():
|
||||
result = verify(
|
||||
*sides,
|
||||
demo,
|
||||
next(f for f, kinds in FAMILY_ORACLES.items() if family in kinds),
|
||||
browser=BrowserExecutor() if family == "xss" else None,
|
||||
)
|
||||
search_family = next(f for f, kinds in FAMILY_ORACLES.items() if family in kinds)
|
||||
if task_boundary:
|
||||
tick = time.monotonic()
|
||||
try:
|
||||
result = _verify_task_pair(sides, demo, family)
|
||||
except Exception as exc:
|
||||
result = VerificationRecord(
|
||||
"inconclusive", (), time.monotonic() - tick, exception_reason(exc), isolation_mode="task-boundary"
|
||||
)
|
||||
else:
|
||||
result = verify(
|
||||
*sides,
|
||||
demo,
|
||||
search_family,
|
||||
oracle=family,
|
||||
browser=BrowserExecutor() if family == "xss" else None,
|
||||
)
|
||||
results[name] = asdict(result)
|
||||
if task_boundary and (result.outcome == "demonstrated") != (name == "real") and record["status"] == "ok":
|
||||
expected = "demonstrated" if name == "real" else "not demonstrated"
|
||||
record.update(
|
||||
status="instrument_failure",
|
||||
exception=f"{family}/{name}: expected {expected}, got {result.outcome}",
|
||||
)
|
||||
# SSRF/browser need additional namespace capabilities beyond the
|
||||
# generic preflight. These failures must not look like oracle misses.
|
||||
for side in result.sides:
|
||||
if side.reason.startswith("verification unavailable or refused:"):
|
||||
if not task_boundary and side.reason.startswith("verification unavailable or refused:"):
|
||||
raise _sandbox.IsolationUnavailable(f"{family}/{name}: {side.reason}")
|
||||
except Exception as exc:
|
||||
record.update(status="instrument_failure", exception=exception_reason(exc))
|
||||
|
||||
@@ -106,8 +106,12 @@ def diagnostic(value: object, *, maximum: int = 300, private: tuple[str, ...] =
|
||||
text = re.sub(r"(?i)bearer\s+[^\s,;\"']+", "Bearer [redacted]", text)
|
||||
text = re.sub(r"(?i)(?:https?|s3)://[^\s<>\"']+", "[redacted-url]", text)
|
||||
text = re.sub(
|
||||
r"(?i)([\w-]*(?:authorization|signature|credential|token|secret|password|key))\s*[:=]\s*[^\s,;&\"']+", r"\1=[redacted]", text
|
||||
r"(?i)([\w-]*(?:authorization|signature|credential|token|secret|password|key))[\"']?\s*[:=]\s*[\"']?[^\s,;&\"']+",
|
||||
r"\1=[redacted]",
|
||||
text,
|
||||
)
|
||||
text = re.sub(r"\b(?:gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|npm_[A-Za-z0-9]+)\b", "[redacted]", text)
|
||||
text = re.sub(r"\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b", "[redacted]", text)
|
||||
for name in sorted(set(private), key=len, reverse=True):
|
||||
if name:
|
||||
text = text.replace(name, "[repository]")
|
||||
@@ -125,3 +129,14 @@ def exception_reason(exc: BaseException, *, private: tuple[str, ...] = ()) -> st
|
||||
half = max(0, (maximum - 2) // 2)
|
||||
return prefix + diagnostic(original, maximum=half, private=private) + "; " + diagnostic(cleanup, maximum=half, private=private)
|
||||
return prefix + diagnostic(exc, maximum=maximum, private=private)
|
||||
|
||||
|
||||
class CommandFailure(ValueError):
|
||||
"""Transport a bounded command diagnostic without dropping stderr."""
|
||||
|
||||
def __init__(self, phase: str, exit_code: int | None, stderr: str, reason: str = "") -> None:
|
||||
self.phase = phase
|
||||
self.exit_code = exit_code
|
||||
self.stderr = diagnostic(stderr, maximum=1500)
|
||||
summary = diagnostic(reason) if reason else f"{phase}: exit code {exit_code}"
|
||||
super().__init__(summary + (": " + self.stderr if self.stderr else ""))
|
||||
|
||||
@@ -30,7 +30,7 @@ from . import _sandbox, task_storage
|
||||
from .budget import SearchBudget
|
||||
from .demo import BUILD_RECIPES, FAMILY_ORACLES, RUNTIMES, capture_output, load_demo, substitute, validate_oracle
|
||||
from .oracles import BrowserExecutor, Canary, Oracle, oracle_for
|
||||
from .task_storage import exception_reason
|
||||
from .task_storage import CommandFailure, diagnostic, exception_reason
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -62,6 +62,9 @@ class SideRecord:
|
||||
scratch_peak_bytes: int = 0
|
||||
isolation_mode: str = field(default_factory=_sandbox.isolation_mode)
|
||||
chromium_no_sandbox: bool = False
|
||||
phase: str = ""
|
||||
exit_code: int | None = None
|
||||
stderr: str = ""
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -133,18 +136,19 @@ def _tree(root: Path, *, generated_links: bool = False) -> str:
|
||||
# Executed as verifier-owned code inside the same network sandbox as the app.
|
||||
# Redirects are refused: only the configured loopback application is reachable.
|
||||
_HTTP_DRIVER = r"""
|
||||
import http.client, importlib.util, json, os, socket, subprocess, sys, time
|
||||
import http.client, importlib.util, json, os, socket, subprocess, sys, tempfile, time
|
||||
spec = importlib.util.spec_from_file_location('demo', '/verifier-demo.py')
|
||||
demo = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(demo)
|
||||
config = json.load(sys.stdin)
|
||||
schema = config['schema']
|
||||
app = subprocess.Popen(config['command'], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
app_errors = tempfile.TemporaryFile()
|
||||
app = subprocess.Popen(config['command'], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=app_errors)
|
||||
try:
|
||||
until = time.monotonic() + config['timeout'] / 2
|
||||
while True:
|
||||
if app.poll() is not None:
|
||||
raise RuntimeError('HTTP application exited during readiness')
|
||||
raise SystemExit(app.returncode or 1)
|
||||
try:
|
||||
connection = socket.create_connection(('127.0.0.1', schema['start']['port']), timeout=0.1)
|
||||
connection.close()
|
||||
@@ -183,6 +187,9 @@ finally:
|
||||
except subprocess.TimeoutExpired:
|
||||
app.kill()
|
||||
app.wait()
|
||||
app_errors.seek(max(0, app_errors.seek(0, 2) - 16384))
|
||||
sys.stderr.write(app_errors.read().decode(errors="replace"))
|
||||
app_errors.close()
|
||||
"""
|
||||
|
||||
|
||||
@@ -223,7 +230,12 @@ def _http_steps(
|
||||
acknowledged = True
|
||||
result = future.result()
|
||||
if not acknowledged or result.exit_code or result.timed_out:
|
||||
raise ValueError("HTTP application/steps failed or readiness not acknowledged: " + result.stderr[-2000:])
|
||||
raise CommandFailure(
|
||||
"start" if not acknowledged else "run",
|
||||
result.exit_code,
|
||||
result.stderr,
|
||||
"HTTP application/steps failed or readiness not acknowledged",
|
||||
)
|
||||
outputs = json.loads(result.stdout)
|
||||
if not isinstance(outputs, list) or len(outputs) != len(schema["steps"]) or not all(isinstance(value, str) for value in outputs):
|
||||
raise ValueError("invalid HTTP driver output")
|
||||
@@ -249,18 +261,21 @@ def _side(side: Side, demo: Path, family: str, timeout: int, browser: BrowserExe
|
||||
if root is not None:
|
||||
disk_peak = max(disk_peak, sum(p.lstat().st_blocks * 512 for p in root.rglob("*")))
|
||||
|
||||
def record(outcome: str, reason: str) -> SideRecord:
|
||||
def record(outcome: str, reason: str, phase: str = "", result: Any = None) -> SideRecord:
|
||||
return SideRecord(
|
||||
outcome,
|
||||
tuple(observations),
|
||||
time.monotonic() - started,
|
||||
reason,
|
||||
diagnostic(reason, maximum=1500),
|
||||
timings["build"],
|
||||
timings["ready"],
|
||||
timings["run"],
|
||||
disk_peak,
|
||||
isolation_mode="task-boundary" if task_boundary else _sandbox.isolation_mode(),
|
||||
chromium_no_sandbox=bool(getattr(browser, "no_sandbox", False)),
|
||||
phase=phase,
|
||||
exit_code=result.exit_code if result is not None else None,
|
||||
stderr=diagnostic(result.stderr, maximum=1500) if result is not None else "",
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -305,7 +320,7 @@ def _side(side: Side, demo: Path, family: str, timeout: int, browser: BrowserExe
|
||||
command += ("assemble",)
|
||||
compiled = timed("build", runner, job(command), scratch=products, mounts=mounts, writable_checkout=True)
|
||||
if compiled.exit_code or compiled.timed_out:
|
||||
return record("could_not_build", "build recipe failed: " + compiled.stderr[-2000:])
|
||||
return record("could_not_build", "build recipe failed", "build", compiled)
|
||||
if tuple(_tree(p) for p in immutable) != before:
|
||||
return record("inconclusive", "build changed immutable inputs")
|
||||
product_hash = _tree(products, generated_links=True)
|
||||
@@ -354,7 +369,7 @@ def _side(side: Side, demo: Path, family: str, timeout: int, browser: BrowserExe
|
||||
namespace_pid=oracle.namespace_pid,
|
||||
)
|
||||
if ready.exit_code or ready.timed_out:
|
||||
return record("could_not_run", "app readiness failed: " + ready.stderr[-2000:])
|
||||
return record("could_not_run", "app readiness failed", "start", ready)
|
||||
if family == "ssrf" and oracle.observe()[0]:
|
||||
return record("inconclusive", "readiness triggered the SSRF oracle")
|
||||
# Readiness cannot supply the attack's evidence or leave a command marker.
|
||||
@@ -401,7 +416,7 @@ def _side(side: Side, demo: Path, family: str, timeout: int, browser: BrowserExe
|
||||
if result.timed_out:
|
||||
return record("inconclusive", "app attack timed out")
|
||||
if result.exit_code:
|
||||
return record("could_not_run", "app invocation failed")
|
||||
return record("could_not_run", "app invocation failed", "run", result)
|
||||
timed("run", oracle.capture, result.stdout)
|
||||
capture_output(step, result.stdout, captures, canary.nonce)
|
||||
observed, evidence = timed("run", oracle.observe)
|
||||
@@ -416,6 +431,8 @@ def _side(side: Side, demo: Path, family: str, timeout: int, browser: BrowserExe
|
||||
finally:
|
||||
oracle.close()
|
||||
return record("observed", "fresh task run completed" if task_boundary else "three fresh runs completed")
|
||||
except CommandFailure as exc:
|
||||
return record("could_not_run", str(exc), exc.phase, exc)
|
||||
except task_storage.ScratchLimit as exc:
|
||||
return record("could_not_build", exception_reason(exc))
|
||||
except (OSError, ValueError, AssertionError, KeyError, IndexError, TypeError) as exc:
|
||||
@@ -437,10 +454,11 @@ def _run_task(
|
||||
the filesystem/network boundary. Its launch manifest must contain no keys.
|
||||
"""
|
||||
translations = {"/workspace": str(job.repo_root), "/scratch": str(scratch), **{k: str(v) for k, v in (mounts or {}).items()}}
|
||||
pattern = re.compile("|".join(re.escape(key) for key in sorted(translations, key=len, reverse=True)))
|
||||
pattern = re.compile("(?:" + "|".join(re.escape(key) for key in sorted(translations, key=len, reverse=True)) + r")(?=/|$|['\"])")
|
||||
|
||||
def translate(value: str) -> str:
|
||||
# One substitution pass: host temp paths may themselves contain /scratch.
|
||||
# One pass, at path-component boundaries: /fixture/fixture.db must
|
||||
# translate its mount prefix without also rewriting the filename.
|
||||
return pattern.sub(lambda match: translations[match.group(0)], value)
|
||||
|
||||
command = tuple(translate(arg) for arg in job.command)
|
||||
@@ -471,7 +489,7 @@ def _run_task(
|
||||
os.killpg(proc.pid, signal.SIGKILL)
|
||||
proc.wait()
|
||||
out.seek(0)
|
||||
err.seek(0)
|
||||
err.seek(max(0, os.fstat(err.fileno()).st_size - 16384))
|
||||
return SandboxResult(
|
||||
proc.returncode, out.read(1048576).decode(errors="replace"), err.read(1048576).decode(errors="replace"), expired
|
||||
)
|
||||
|
||||
@@ -81,7 +81,12 @@ DEMO_GUIDE = (
|
||||
'Demo schema: {"oracle":"path","build":{"recipe":"none","arguments":[]},'
|
||||
'"start":{"runtime":"python","path":"app.py","arguments":[],"mode":"cli"},'
|
||||
'"steps":[{"type":"cli","arguments":["hello"]}]}. This is a minimal example, not evidence. '
|
||||
"Recipes: none,pip,npm,composer,maven,gradle; none takes [], others one checkout-relative manifest/project path. "
|
||||
"Recipes: none takes [], otherwise arguments[0] is a checkout-relative ecosystem manifest or project directory (a file uses "
|
||||
"its parent): pip requirements*.txt uses install -r (e.g. requirements.txt), pyproject.toml/setup.py/setup.cfg uses "
|
||||
"non-editable install of the directory with requirements.txt fallback when no build backend exists (e.g. pyproject.toml); npm uses "
|
||||
"ci with package-lock.json else install in the directory (e.g. package.json); composer uses install --no-interaction in the "
|
||||
"directory (e.g. composer.json); maven uses mvn -q -DskipTests package -f <pom> (e.g. pom.xml); gradle uses the project "
|
||||
"wrapper and directory (e.g. build.gradle). "
|
||||
"Runtimes: python,node,php,java; start.path must be a tracked checkout entrypoint. "
|
||||
"HTTP mode requires port (1024-65535) and steps {type:http,method,path,headers?,body?}; "
|
||||
"CLI mode forbids port and uses {type:cli,arguments,stdin?}. Supply 1-32 ordered steps. "
|
||||
|
||||
Reference in New Issue
Block a user