hermes - 💡(How to fix) Fix concurrency: four TOCTOU races in browser_tool.py lazy-init singletons

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix

Apply double-checked locking to each: add per-function threading.Locks, fast path remains lock-free after first init, value written before resolved flag inside the lock.

Code Example

_command_timeout_resolved = True      # ← flag set first
result = DEFAULT_COMMAND_TIMEOUT
# … config read …
_cached_command_timeout = result      # ← value written last
RAW_BUFFERClick to expand / collapse

Bug

Four resolver functions in tools/browser_tool.py share the same TOCTOU pattern: the resolved flag is set to True before the cached value is computed or written. A concurrent thread hitting the early-return fast path in the window between the flag write and the value write reads a stale default.

Affected functions and the impact of a stale read:

FunctionStale value returnedImpact
_get_command_timeout()None (typed int)TypeError downstream
_get_browser_engine()"auto"wrong engine selected
_allow_private_urls()FalseSSRF protection not disabled when configured
_auto_local_for_private_urls()Truerouting decision wrong

Example pattern (all four look like this):

_command_timeout_resolved = True      # ← flag set first
result = DEFAULT_COMMAND_TIMEOUT
# … config read …
_cached_command_timeout = result      # ← value written last

Fix

Apply double-checked locking to each: add per-function threading.Locks, fast path remains lock-free after first init, value written before resolved flag inside the lock.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix concurrency: four TOCTOU races in browser_tool.py lazy-init singletons