Skip to content

fix(browser): keep browser-use-managed profiles off the OS keychain - #6059

Open
FanouZeng-TT wants to merge 1 commit into
browser-use:mainfrom
FanouZeng-TT:fix/managed-profile-mock-keychain
Open

FanouZeng-TT wants to merge 1 commit into
browser-use:mainfrom
FanouZeng-TT:fix/managed-profile-mock-keychain

Conversation

@FanouZeng-TT

@FanouZeng-TT FanouZeng-TT commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes #5415.

Chromium synchronously reaches the OS credential store (macOS Keychain, Linux Secret Service) while it initialises a profile. For a browser-use-managed throwaway profile there is nothing to decrypt and, under headless/CI/containers, no interactive session to answer the prompt — so Chromium hangs at startup and never opens its CDP port. LocalBrowserWatchdog.on_BrowserLaunchEvent then never returns and the caller sees an opaque TimeoutError. On an interactive machine this instead surfaces as a Keychain prompt on every fresh profile launch, including the first uv run pytest tests/ci after a fresh clone.

#3225 removed --use-mock-keychain and --password-store=basic from the global defaults because a real, pre-existing Chrome profile passed via user_data_dir genuinely needs the real keychain to decrypt saved cookies and passwords. That fix is still correct for that scenario and is preserved here.

Fix

Apply the two flags only when the profile directory is one browser-use owns:

  • the throwaway temp dir created for user_data_dir=None;
  • any directory still carrying a browser-use temp prefix;
  • the launch watchdog's browseruse-tmp-* fallback directory.

They are never applied to a copy of a caller-supplied Chrome profile: _copy_profile() copies such a profile into a temp dir before launch, but that copy still holds the caller's saved credentials, so it must keep real keychain access (#3225).

Managed-ness is evaluated on every get_args() call rather than captured once at construction. This matters because user_data_dir can change after init — most notably LocalBrowserWatchdog._launch_browser, which retries a failed launch in a fresh browseruse-tmp-* directory — and the flags must track the directory the browser actually launches with. A profile whose user_data_dir is reassigned to a real Chrome profile after construction likewise drops the flags.

Bug verification

Before the fix, a managed profile's get_args() contains neither flag. After the fix the same profile includes them, and each caller-supplied / copied / reassigned-real-profile case still excludes them. The new test file exercises both directions:

  • test_default_profile_gets_mock_keychain — fails before, passes after;
  • test_explicit_user_profile_keeps_real_keychain, test_copied_user_profile_is_not_treated_as_managed, test_default_config_profile_dir_is_not_managed — guard the #3225 behavior;
  • test_managed_profile_keeps_mock_keychain_after_temp_fallback, test_reassigned_real_profile_dir_drops_mock_keychain — cover user_data_dir changing after construction.

Independently, launching the exact Chromium binary browser-use uses with otherwise identical argument lists showed the flip: without the two flags the CDP port never opens (no curl http://127.0.0.1:<port>/json/version reply even after 8s); with them it responds within ~1s.

Validation

  • uv run pytest -q tests/ci/test_managed_profile_keychain_args.py — 6 passed
  • uv run pytest -q tests/ci --ignore=tests/ci/browser --ignore=tests/ci/interactions --ignore=tests/ci/integrations --ignore=tests/ci/infrastructure — 342 passed, 12 skipped, 1 pre-existing failure unrelated to this change (test_beta_agent_constructor_type_hints_match_browser_use_core_params; the same assertion fails on unmodified main, a module-import-ordering issue)
  • uv run ruff check, uv run ruff format --check — clean
  • uv run pyright browser_use/browser/profile.py tests/ci/test_managed_profile_keychain_args.py — 0 errors
  • uv run pre-commit run --files … — all hooks passed

Relation to earlier attempts

Supersedes the earlier attempts at this same fix (#5446, #5430, #5417), which were closed by the stale bot. The difference here is the per-launch evaluation of managed-ness described above, so the watchdog's temp-dir fallback and any post-construction user_data_dir reassignment are handled rather than evaluated once at init.


Summary by cubic

Fixes #5415: Chromium hangs at startup under headless/CI/containers when launching a browser-use-managed throwaway profile, because Chromium blocks on the OS credential store (macOS Keychain, Linux Secret Service) before opening its CDP port. On interactive machines this surfaced as a Keychain prompt on every fresh profile launch.

--use-mock-keychain and --password-store=basic, removed globally by #3225, are now applied only when browser-use owns the profile directory — the temp dir created for user_data_dir=None, any dir still carrying a browser-use temp prefix, and the launch watchdog's fallback dir. Caller-supplied profiles, including copies made by _copy_profile(), keep real keychain access so saved cookies and passwords can still be decrypted. Managed-ness is evaluated on every get_args() call rather than captured at construction, so the flags track user_data_dir reassignments after init, such as the watchdog retrying in a fresh temp dir.

Written for commit dfb104c. Summary will update on new commits.

View guided diff

Chromium synchronously reaches the OS credential store (macOS Keychain,
Linux Secret Service) while initialising a profile. On a browser-use-managed
throwaway profile there is nothing to decrypt and, under headless/CI/
containers, no interactive session to answer the prompt -- Chromium hangs at
startup and never opens its CDP port, and the caller sees an opaque
TimeoutError. Reportedly also a surprise Keychain prompt on a local machine.

browser-use#3225 removed --use-mock-keychain/--password-store=basic globally because a
real user profile passed via user_data_dir needs the real keychain to decrypt
saved cookies and passwords. That fix is preserved here: the flags are applied
only when the profile directory is one browser-use owns (the temp dir made for
user_data_dir=None, any browser-use temp prefix, or the launch watchdog's
temp-dir fallback), and never to a copy of a caller-supplied Chrome profile.

Managed-ness is evaluated on each get_args() call rather than captured once at
construction, so a profile whose user_data_dir changes later -- the watchdog
retrying in a browseruse-tmp-* directory, or a caller reassigning the field --
is judged by the directory it actually launches with.

Fixes browser-use#5415.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="browser_use/browser/profile.py">

<violation number="1" location="browser_use/browser/profile.py:877">
P2: The copied-profile marker overrides the live directory check, so a copied profile's `browseruse-tmp-*` watchdog fallback still uses the OS keychain. Check the fallback directory before honoring the copied-profile marker.</violation>

<violation number="2" location="browser_use/browser/profile.py:882">
P2: This substring check matches any path component, so a caller-owned Chrome profile beneath a directory named `browser-use-user-data-dir-...` gets mock-keychain flags and may no longer decrypt saved credentials. Match the generated prefix on the user-data directory's basename instead.</violation>

<violation number="3" location="browser_use/browser/profile.py:945">
P1: Passing a copied Chrome profile through `BrowserSession` loses this private provenance marker during `model_dump()`/reconstruction, so `get_args()` applies mock-keychain flags to the copied credentials. Preserve the copied-profile provenance when merging the session profile, or avoid rebuilding it.</violation>
</file>

Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.

View guided diff | Re-trigger cubic

logger.info(f'Created new profile ({self.profile_directory}) in temp directory: {temp_dir}')

self.user_data_dir = temp_dir
self._copied_from_caller_profile = True

@cubic-dev-ai cubic-dev-ai Bot Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Passing a copied Chrome profile through BrowserSession loses this private provenance marker during model_dump()/reconstruction, so get_args() applies mock-keychain flags to the copied credentials. Preserve the copied-profile provenance when merging the session profile, or avoid rebuilding it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At browser_use/browser/profile.py, line 945:

<comment>Passing a copied Chrome profile through `BrowserSession` loses this private provenance marker during `model_dump()`/reconstruction, so `get_args()` applies mock-keychain flags to the copied credentials. Preserve the copied-profile provenance when merging the session profile, or avoid rebuilding it.</comment>

<file context>
@@ -902,6 +942,7 @@ def _copy_profile(self) -> None:
 			logger.info(f'Created new profile ({self.profile_directory}) in temp directory: {temp_dir}')
 
 		self.user_data_dir = temp_dir
+		self._copied_from_caller_profile = True
 
 	def get_args(self) -> list[str]:
</file context>
Fix with cubic

if self.user_data_dir is None:
return True
user_data_str = str(self.user_data_dir).lower()
return 'browser-use-user-data-dir-' in user_data_str or 'browseruse-tmp-' in user_data_str

@cubic-dev-ai cubic-dev-ai Bot Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This substring check matches any path component, so a caller-owned Chrome profile beneath a directory named browser-use-user-data-dir-... gets mock-keychain flags and may no longer decrypt saved credentials. Match the generated prefix on the user-data directory's basename instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At browser_use/browser/profile.py, line 882:

<comment>This substring check matches any path component, so a caller-owned Chrome profile beneath a directory named `browser-use-user-data-dir-...` gets mock-keychain flags and may no longer decrypt saved credentials. Match the generated prefix on the user-data directory's basename instead.</comment>

<file context>
@@ -841,6 +860,27 @@ def validate_highlight_elements_conflict(self) -> Self:
+		if self.user_data_dir is None:
+			return True
+		user_data_str = str(self.user_data_dir).lower()
+		return 'browser-use-user-data-dir-' in user_data_str or 'browseruse-tmp-' in user_data_str
+
 	def model_post_init(self, __context: Any) -> None:
</file context>
Suggested change
return 'browser-use-user-data-dir-' in user_data_str or 'browseruse-tmp-' in user_data_str
user_data_name = Path(user_data_str).name
return user_data_name.startswith('browser-use-user-data-dir-') or user_data_name.startswith('browseruse-tmp-')
Fix with cubic

caller reassigning the field -- is judged by the directory it actually launches
with.
"""
if self._copied_from_caller_profile:

@cubic-dev-ai cubic-dev-ai Bot Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The copied-profile marker overrides the live directory check, so a copied profile's browseruse-tmp-* watchdog fallback still uses the OS keychain. Check the fallback directory before honoring the copied-profile marker.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At browser_use/browser/profile.py, line 877:

<comment>The copied-profile marker overrides the live directory check, so a copied profile's `browseruse-tmp-*` watchdog fallback still uses the OS keychain. Check the fallback directory before honoring the copied-profile marker.</comment>

<file context>
@@ -841,6 +860,27 @@ def validate_highlight_elements_conflict(self) -> Self:
+		caller reassigning the field -- is judged by the directory it actually launches
+		with.
+		"""
+		if self._copied_from_caller_profile:
+			return False
+		if self.user_data_dir is None:
</file context>
Suggested change
if self._copied_from_caller_profile:
if self._copied_from_caller_profile and 'browseruse-tmp-' not in str(self.user_data_dir).lower():
Fix with cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: BrowserSession hangs / prompts for OS keychain access on startup without --use-mock-keychain (regression side-effect of #3225)

1 participant