https://arxiv.org/abs/2606.28344. The end of web parsing. The beginning of scalable pixel-native search. link: https://pixelrag.ai/
fix(security): resolve chrome sandbox escapes and prompt injections (#138)
chalbi youssef69cddbc9c3c3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex b34d49c..349677e 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -85,6 +85,14 @@ jobs:run: uv run pixelshot install-chrome- name: Run tests+ env:+ # Chrome's sandbox cannot initialise on the hosted runner (no user+ # namespaces, no SUID helper), so every render test fails to launch+ # Chrome at all: "Failed to connect to Chrome on port 12000".+ # Opt out here rather than weakening sandbox_args(): the runner is a+ # disposable VM rendering known fixtures, while real users -- who+ # point this at pages they do not control -- keep the sandbox on.+ PIXELSHOT_NO_SANDBOX: "1"run: uv run pytest tests/ -vplugin-validate:diff --git a/eval/lib/screenshot.py b/eval/lib/screenshot.pyindex 9425da5..87f458f 100644--- a/eval/lib/screenshot.py+++ b/eval/lib/screenshot.py@@ -54,10 +54,13 @@ def setup_driver(window_width=1024, window_height=2000, device_scale_factor=1):if chrome_binary:options.binary_location = chrome_binary+ from pixelrag_render.chrome import sandbox_args+options.add_argument("--headless=new")options.add_argument("--disable-gpu")options.add_argument(f"--window-size={window_width},{window_height}")- options.add_argument("--no-sandbox")+ for arg in sandbox_args():+ options.add_argument(arg)options.add_argument("--disable-dev-shm-usage")options.add_argument("--disable-extensions")options.add_argument("--disable-setuid-sandbox")diff --git a/render/src/pixelrag_render/backends/cdp.py b/render/src/pixelrag_render/backends/cdp.pyindex 14b6018..6192483 100644--- a/render/src/pixelrag_render/backends/cdp.py+++ b/render/src/pixelrag_render/backends/cdp.py@@ -35,6 +35,7 @@ from pathlib import Pathfrom PIL import Image+from ..chrome import sandbox_argsfrom .page_metrics import CONTENT_BOTTOM_JS, truncation_reasonlogger = logging.getLogger("pixelrag_render.backends.cdp")@@ -57,7 +58,7 @@ _GPU_ARGS = ()BROWSER_ARGS = ["--disable-dev-shm-usage",- "--no-sandbox",+ *sandbox_args(),"--disable-renderer-backgrounding","--disable-backgrounding-occluded-windows","--disable-background-networking",diff --git a/render/src/pixelrag_render/backends/fast_cdp.py b/render/src/pixelrag_render/backends/fast_cdp.pyindex a4a92bf..98de2ec 100644--- a/render/src/pixelrag_render/backends/fast_cdp.py+++ b/render/src/pixelrag_render/backends/fast_cdp.py@@ -34,6 +34,7 @@ import timeimport urllib.requestfrom pathlib import Path+from ..chrome import sandbox_argsfrom .page_metrics import CONTENT_BOTTOM_JS, truncation_reasonlogger = logging.getLogger("pixelrag_render.backends.fast_cdp")@@ -51,7 +52,7 @@ _GPU_ARGS = (else ["--disable-gpu"])CHROME_ARGS = [- "--no-sandbox",+ *sandbox_args(),"--disable-dev-shm-usage",*_GPU_ARGS,"--disable-renderer-backgrounding",diff --git a/render/src/pixelrag_render/chrome.py b/render/src/pixelrag_render/chrome.pyindex bcae582..54b1b91 100644--- a/render/src/pixelrag_render/chrome.py+++ b/render/src/pixelrag_render/chrome.py@@ -14,6 +14,7 @@ Programmatic:"""import json+import loggingimport osimport platformimport re@@ -26,6 +27,9 @@ from pathlib import PathINSTALL_DIR = Path.home() / ".cache" / "pixelrag" / "chrome"VERSION_FILE = "version.json"+logger = logging.getLogger(__name__)++_SANDBOX_WARNING_EMITTED = False# Update these when releasing a new buildCHROME_VERSION = "150.0.7844.0"@@ -35,6 +39,29 @@ RELEASE_URL_TEMPLATE = ()+def sandbox_args() -> list[str]:+ """Return Chrome sandbox arguments, adding ``--no-sandbox`` only when needed."""++ global _SANDBOX_WARNING_EMITTED++ args: list[str] = []+ force_no_sandbox = os.environ.get("PIXELSHOT_NO_SANDBOX") == "1"+ running_as_root = (+ platform.system() == "Linux" and hasattr(os, "getuid") and os.getuid() == 0+ )++ if force_no_sandbox or running_as_root:+ args.append("--no-sandbox")+ if running_as_root and not _SANDBOX_WARNING_EMITTED:+ logger.warning(+ "Running Chrome as root on Linux; adding --no-sandbox to avoid crashes. "+ "Set PIXELSHOT_NO_SANDBOX=1 to force this behavior."+ )+ _SANDBOX_WARNING_EMITTED = True++ return args++def _playwright_revision(path: str) -> int:"""Integer Playwright Chromium revision embedded in ``path``.diff --git a/render/src/pixelrag_render/strategies/cdp_overlap.py b/render/src/pixelrag_render/strategies/cdp_overlap.pyindex 59704a3..96dd63d 100644--- a/render/src/pixelrag_render/strategies/cdp_overlap.py+++ b/render/src/pixelrag_render/strategies/cdp_overlap.py@@ -21,6 +21,7 @@ import timeimport urllib.requestfrom dataclasses import dataclass+from ..chrome import sandbox_argsfrom .base import ArticleCapture, TileCapture, article_urlfrom .connection import WebsocketConnection, pick_page_ws_url@@ -61,7 +62,7 @@ async def _launch_two_tabs(chrome_path: str, port: int, headless_shell: bool = Fif not headless_shell:args.append("--headless=new")args += [- "--no-sandbox",+ *sandbox_args(),"--disable-dev-shm-usage","--enable-gpu-rasterization","--force-gpu-rasterization",diff --git a/render/src/pixelrag_render/strategies/cdp_pipelined_dc.py b/render/src/pixelrag_render/strategies/cdp_pipelined_dc.pyindex 9bcc9c9..1f06bd4 100644--- a/render/src/pixelrag_render/strategies/cdp_pipelined_dc.py+++ b/render/src/pixelrag_render/strategies/cdp_pipelined_dc.py@@ -20,6 +20,7 @@ import timeimport urllib.requestfrom dataclasses import dataclass+from ..chrome import sandbox_argsfrom .base import ArticleCapture, TileCapture, article_urlfrom .connection import WebsocketConnection, pick_page_ws_url@@ -80,7 +81,7 @@ async def launch_two_tab(if not headless_shell:args.append("--headless=new")args += [- "--no-sandbox",+ *sandbox_args(),"--disable-dev-shm-usage","--enable-gpu-rasterization","--force-gpu-rasterization",diff --git a/render/src/pixelrag_render/strategies/cdp_pipelined_tabs.py b/render/src/pixelrag_render/strategies/cdp_pipelined_tabs.pyindex 87cb056..75aa5f5 100644--- a/render/src/pixelrag_render/strategies/cdp_pipelined_tabs.py+++ b/render/src/pixelrag_render/strategies/cdp_pipelined_tabs.py@@ -18,6 +18,7 @@ import osimport timefrom dataclasses import dataclass+from ..chrome import sandbox_argsfrom .base import ArticleCapture, TileCapture, article_urlfrom .connection import WebsocketConnection, pick_page_ws_url@@ -80,7 +81,7 @@ class CDPPipelinedTabsStrategy:args = [self.chrome_path,f"--remote-debugging-port={port}",- "--no-sandbox",+ *sandbox_args(),"--disable-dev-shm-usage",]if not self.headless_shell:diff --git a/render/src/pixelrag_render/strategies/connection.py b/render/src/pixelrag_render/strategies/connection.pyindex e096017..4b279b6 100644--- a/render/src/pixelrag_render/strategies/connection.py+++ b/render/src/pixelrag_render/strategies/connection.py@@ -9,8 +9,10 @@ import signalimport subprocessimport urllib.request+from ..chrome import sandbox_args+CHROME_ARGS = [- "--no-sandbox",+ *sandbox_args(),"--disable-dev-shm-usage","--enable-gpu-rasterization","--force-gpu-rasterization",diff --git a/serve/src/pixelrag_serve/render_ondemand.py b/serve/src/pixelrag_serve/render_ondemand.pyindex 8f53313..9dc084c 100644--- a/serve/src/pixelrag_serve/render_ondemand.py+++ b/serve/src/pixelrag_serve/render_ondemand.py@@ -23,6 +23,8 @@ import timeimport urllib.requestfrom urllib.parse import quote+from pixelrag_render.chrome import sandbox_args+_render_lock = threading.Lock() # one Chrome render at a time per process# Hard timeout (seconds) for a single page render subprocess._RENDER_TIMEOUT = float(os.environ.get("PIXELRAG_RENDER_TIMEOUT", "120"))@@ -96,8 +98,8 @@ class OnDemandTiles:chrome,f"--remote-debugging-port={port}","--headless=new",- "--no-sandbox","--disable-gpu",+ *sandbox_args(),f"--user-data-dir={self._chrome_udd}","about:blank",],