Skip to content

fix: security and correctness issues found in #4514 review#4590

Merged
sauravpanda merged 4 commits into
mainfrom
fix/pr-4514-review-fixes
Apr 2, 2026
Merged

fix: security and correctness issues found in #4514 review#4590
sauravpanda merged 4 commits into
mainfrom
fix/pr-4514-review-fixes

Conversation

@sauravpanda
Copy link
Copy Markdown
Collaborator

@sauravpanda sauravpanda commented Apr 2, 2026

Summary

Three security and correctness issues found during review of #4514, which has since been merged. All three affect the new skill_cli layer introduced by that PR.

  • BROWSER_USE_API_KEY env var silently ignored (commands/cloud.py): another big cli update #4514 dropped the env var fallback in _get_api_key() without a migration path, breaking CI/CD pipelines that set it as a secret. Restored with a deprecation warning directing users to browser-use config set api_key.

  • _install_cloudflared() downloads binary without integrity check (commands/setup.py, Linux only): Raw urllib.request.urlretrieve wrote directly to the install destination with no verification. Now downloads to a temp file, fetches the .sha256sum Cloudflare publishes alongside each release, verifies SHA256 before installing, and cleans up on failure. macOS (brew) and Windows (winget) were already safe — they verify internally.

  • write_config() not atomic (config.py): Direct path.write_text() truncates config.json on SIGKILL mid-write; read_config() catches json.JSONDecodeError and returns {}, silently wiping the API key and all settings. Now uses tempfile.mkstemp(dir=same_dir) + fsync + os.replace() — the same pattern _write_state() in daemon.py already uses correctly.

Test plan

  • BROWSER_USE_API_KEY=sk-xxx browser-use cloud connect prints deprecation warning and still authenticates
  • After browser-use config set api_key sk-xxx, commands work without the env var set
  • On Linux: cloudflared install rejects a tampered binary with a clear SHA256 mismatch error
  • SIGKILL during browser-use config set leaves config.json intact or absent, never truncated

🤖 Generated with Claude Code

…ly ignoring it

The CLI previously accepted the env var as a fallback; this PR dropped it
without a migration path, breaking CI/CD pipelines that set it as a secret.
Restore backwards-compat by checking the env var after config.json and
printing a deprecation warning with the migration command.
…inux

Downloads to a temp file, fetches the .sha256sum file Cloudflare publishes
alongside each release, and verifies before moving to the install destination.
Protects against MITM/CDN tampering. Temp file is cleaned up on failure.
…ta loss

A SIGKILL mid-write truncates config.json; read_config() catches
json.JSONDecodeError and returns {}, silently wiping the API key and
all other settings. Mirror the pattern already used by _write_state():
write to a sibling temp file, fsync, chmod 600, then os.replace() into
place — which is atomic on POSIX and effectively atomic on Windows.
@sauravpanda sauravpanda force-pushed the fix/pr-4514-review-fixes branch from 27a53db to ea99055 Compare April 2, 2026 20:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Agent Task Evaluation Results: 2/2 (100%)

View detailed results
Task Result Reason
amazon_laptop ✅ Pass Skipped - API key not available (fork PR or missing secret)
browser_use_pip ✅ Pass Skipped - API key not available (fork PR or missing secret)

Check the evaluate-tasks job for detailed task execution logs.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="browser_use/skill_cli/commands/cloud.py">

<violation number="1" location="browser_use/skill_cli/commands/cloud.py:87">
P2: This reintroduces `BROWSER_USE_API_KEY` fallback for `api_key`, which violates the CLI policy to keep the config file as the single source of truth.

(Based on your team's feedback about treating the CLI config as the single source of truth for configuration values.) [FEEDBACK_USED]</violation>
</file>

<file name="browser_use/skill_cli/commands/setup.py">

<violation number="1" location="browser_use/skill_cli/commands/setup.py:246">
P2: Using `Path.rename()` for the temp download can fail across filesystems (e.g., `/tmp` -> `/usr/local/bin`), causing false installation failures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread browser_use/skill_cli/commands/cloud.py Outdated
Comment thread browser_use/skill_cli/commands/setup.py Outdated
…move

- cloud.py: remove BROWSER_USE_API_KEY env var fallback (violates CLI
  policy of config.json as single source of truth); instead detect the
  env var in the error path and print a targeted migration hint
- setup.py: replace Path.rename() with shutil.move() so the temp file
  can be moved across filesystems (e.g. /tmp -> /usr/local/bin)
@sauravpanda sauravpanda merged commit e2ce72f into main Apr 2, 2026
86 checks passed
@sauravpanda sauravpanda deleted the fix/pr-4514-review-fixes branch April 2, 2026 23:27
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.

1 participant