Skip to content

Automate browser based workflows with AI

Exclude login-cookie sidecars from fresh browser profiles (start_fresh cross-org leak) (#8001)

Celal Zamanoğlu83e353cd4bea
diff --git a/skyvern/forge/sdk/routes/browser_profiles.py b/skyvern/forge/sdk/routes/browser_profiles.py
index a2cc54b76..86cbc4d20 100644
--- a/skyvern/forge/sdk/routes/browser_profiles.py
+++ b/skyvern/forge/sdk/routes/browser_profiles.py
@@ -42,7 +42,7 @@ from skyvern.forge.sdk.workflow.browser_session_persistence import retrieve_pers
from skyvern.schemas.proxy_pinning import apply_proxy_pin_update as _apply_proxy_pin_update
from skyvern.schemas.proxy_pinning import should_generate_proxy_session_id
from skyvern.schemas.runs import ProxyLocation, ProxyLocationInput
-from skyvern.webeye.browser_profile_utils import DEFAULT_PROFILE_COPY_IGNORE, valid_operator_profile_generation
+from skyvern.webeye.browser_profile_utils import FRESH_PROFILE_COPY_IGNORE, valid_operator_profile_generation
LOG = structlog.get_logger()
@@ -582,7 +582,7 @@ def _clear_directory(directory: FilePath) -> None:
def _copy_browser_profile_template(source_dir: FilePath, destination_dir: FilePath) -> None:
for source_child in source_dir.iterdir():
- if source_child.name in DEFAULT_PROFILE_COPY_IGNORE:
+ if source_child.name in FRESH_PROFILE_COPY_IGNORE:
continue
destination_child = destination_dir / source_child.name
diff --git a/skyvern/webeye/browser_profile_utils.py b/skyvern/webeye/browser_profile_utils.py
index 976f3f62e..f33546197 100644
--- a/skyvern/webeye/browser_profile_utils.py
+++ b/skyvern/webeye/browser_profile_utils.py
@@ -3,6 +3,9 @@ import os
import stat
import tempfile
+from skyvern.webeye.profile_cookie_merge import BANKED_COOKIES_FILENAME
+from skyvern.webeye.session_cookies import SESSION_COOKIES_FILENAME
+
DEFAULT_PROFILE_COPY_IGNORE = {
"Snapshots",
"GrShaderCache",
@@ -23,6 +26,12 @@ DEFAULT_PROFILE_COPY_IGNORE = {
"DevToolsActivePort",
}
+# A base template is cloned into every fresh browser dir AND every new empty (API-created) profile, so it
+# must never carry Skyvern's login-cookie sidecars — a contaminated template would restore another run's
+# (cross-org) session cookies into a "fresh" browser, or bake them permanently into a stored profile.
+# Reuse paths that return a profile dir directly never go through a copy, so they keep their cookies.
+FRESH_PROFILE_COPY_IGNORE = DEFAULT_PROFILE_COPY_IGNORE | {SESSION_COOKIES_FILENAME, BANKED_COOKIES_FILENAME}
+
def operator_profile_generation(path: str) -> str | None:
digest = hashlib.sha256()
diff --git a/tests/unit/test_copy_browser_profile_template.py b/tests/unit/test_copy_browser_profile_template.py
new file mode 100644
index 000000000..fa88c7b9a
--- /dev/null
+++ b/tests/unit/test_copy_browser_profile_template.py
@@ -0,0 +1,26 @@
+from pathlib import Path
+
+from skyvern.forge.sdk.routes.browser_profiles import _copy_browser_profile_template
+from skyvern.webeye.profile_cookie_merge import BANKED_COOKIES_FILENAME
+from skyvern.webeye.session_cookies import SESSION_COOKIES_FILENAME
+
+
+def test_copy_browser_profile_template_excludes_cookie_sidecars(tmp_path: Path) -> None:
+ # A new empty (API-created) profile is seeded from a base template; it must never inherit login-cookie
+ # sidecars, or a contaminated template bakes another run's (cross-org) cookies permanently into it.
+ source = tmp_path / "template"
+ (source / "Default").mkdir(parents=True)
+ (source / "Default" / "Preferences").write_text("{}")
+ (source / "Local State").write_text("{}")
+ (source / SESSION_COOKIES_FILENAME).write_text("[]")
+ (source / BANKED_COOKIES_FILENAME).write_text("[]")
+
+ dest = tmp_path / "profile"
+ dest.mkdir()
+ _copy_browser_profile_template(source, dest)
+
+ copied = {p.name for p in dest.iterdir()}
+ assert SESSION_COOKIES_FILENAME not in copied
+ assert BANKED_COOKIES_FILENAME not in copied
+ assert "Local State" in copied # a normal file still copies, so the exclusion is targeted
+ assert (dest / "Default" / "Preferences").exists()