~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(security): drop misleading request name in rekey sidecar lock helpers (#7734)
LearningCircuit904300e56eba
diff --git a/changelog.d/+rekey-lock-request-name-traversal.security.md b/changelog.d/+rekey-lock-request-name-traversal.security.mdnew file mode 100644index 0000000000..5dc1130882--- /dev/null+++ b/changelog.d/+rekey-lock-request-name-traversal.security.md@@ -0,0 +1 @@+Fixed Semgrep code-scanning alert 9739 (`semgrep.rules.request-path-traversal-risk`) in `database/rekey_lock.py`, a name-collision false positive: the sidecar-lock helpers took a private `_SidecarLockRequest` dataclass in a local variable called `request`, which matched the rule's `request.$ATTR` taint source even though the value is not an HTTP request. The misleading name is now `lock_request` throughout those helpers (matching the existing `_open_sidecar` parameter), so the paths reaching `os.scandir` are clearly service-generated from the authenticated user's database location and no longer resemble request-controlled input.diff --git a/src/local_deep_research/database/rekey_lock.py b/src/local_deep_research/database/rekey_lock.pyindex 36be1d7668..57811bcd6e 100644--- a/src/local_deep_research/database/rekey_lock.py+++ b/src/local_deep_research/database/rekey_lock.py@@ -323,11 +323,11 @@ def _authorization_lock_path(db_path: Path) -> Path:def _sidecar_io_error(- request: _SidecarLockRequest,+ lock_request: _SidecarLockRequest,operation: RekeySidecarOperation,error: OSError,) -> RekeySidecarIOError:- return RekeySidecarIOError(request.db_path, operation, error.errno)+ return RekeySidecarIOError(lock_request.db_path, operation, error.errno)def _open_sidecar(lock_request: _SidecarLockRequest) -> int:@@ -380,7 +380,7 @@ def _open_sidecar(lock_request: _SidecarLockRequest) -> int:def _is_database_file(- request: _SidecarLockRequest, status: os.stat_result+ lock_request: _SidecarLockRequest, status: os.stat_result) -> bool:"""True when ``status`` may be the inode of a database file.@@ -398,7 +398,7 @@ def _is_database_file(if status.st_nlink < 2:return Falseidentity = (status.st_dev, status.st_ino)- db_path = request.db_path+ db_path = lock_request.db_pathfor path in (db_path,db_path.with_name(f"{db_path.name}-wal"),@@ -410,9 +410,9 @@ def _is_database_file(continueif (other.st_dev, other.st_ino) == identity:return True- lock_name = request.lock_path.name+ lock_name = lock_request.lock_path.nametry:- with os.scandir(request.lock_path.parent) as entries:+ with os.scandir(lock_request.lock_path.parent) as entries:for entry in entries:if entry.name == lock_name:continue@@ -428,28 +428,30 @@ def _is_database_file(def _refuse_foreign_sidecar(- request: _SidecarLockRequest, fd: int+ lock_request: _SidecarLockRequest, fd: int) -> RekeySidecarIOError | None:try:status = os.fstat(fd)except OSError as error:- return _sidecar_io_error(request, RekeySidecarOperation.OPEN, error)+ return _sidecar_io_error(+ lock_request, RekeySidecarOperation.OPEN, error+ )if not stat.S_ISREG(status.st_mode):return RekeySidecarIOError(- request.db_path, RekeySidecarOperation.OPEN, errno.EINVAL+ lock_request.db_path, RekeySidecarOperation.OPEN, errno.EINVAL)- if _is_database_file(request, status):+ if _is_database_file(lock_request, status):# Planted between the check before the open and the open itself:# refused here as well, although the close that follows may# already have dropped this process's locks on the database.return RekeySidecarIOError(- request.db_path, RekeySidecarOperation.OPEN, errno.EMLINK+ lock_request.db_path, RekeySidecarOperation.OPEN, errno.EMLINK)if status.st_nlink == 0:# Already unlinked: a lock on it would exclude nobody who opens the# name afterwards.return RekeySidecarIOError(- request.db_path, RekeySidecarOperation.OPEN, errno.EMLINK+ lock_request.db_path, RekeySidecarOperation.OPEN, errno.EMLINK)return None@@ -463,17 +465,17 @@ def _close_refused_sidecar(fd: int) -> None:@contextmanagerdef _acquire_sidecar_lock(- request: _SidecarLockRequest,+ lock_request: _SidecarLockRequest,) -> Generator[None, None, None]:"""Hold one sidecar lock while preserving protected-body failures."""- gate = _get_sidecar_gate(request.lock_path)- if request.deadline is not None:+ gate = _get_sidecar_gate(lock_request.lock_path)+ if lock_request.deadline is not None:gate_timeout: float | None = max(- 0.0, request.deadline - time.monotonic()+ 0.0, lock_request.deadline - time.monotonic())- elif request.gate_wait is not None:- gate_timeout = request.gate_wait- elif request.blocking:+ elif lock_request.gate_wait is not None:+ gate_timeout = lock_request.gate_wait+ elif lock_request.blocking:gate_timeout = Noneelse:gate_timeout = 0.0@@ -482,14 +484,16 @@ def _acquire_sidecar_lock(else:acquired = gate.acquire(timeout=gate_timeout)if not acquired:- raise RekeyLockContentionError(request.lock_path)+ raise RekeyLockContentionError(lock_request.lock_path)try:- yield from _acquire_sidecar_lock_locked(request)+ yield from _acquire_sidecar_lock_locked(lock_request)finally:gate.release()-def _acquire_os_lock_with_retry(fd: int, request: _SidecarLockRequest) -> None:+def _acquire_os_lock_with_retry(+ fd: int, lock_request: _SidecarLockRequest+) -> None:"""Take the OS lock, retrying a non-blocking attempt for a short window.Every cache probe in any process (``is_user_connected``/``get_session``)@@ -497,30 +501,30 @@ def _acquire_os_lock_with_retry(fd: int, request: _SidecarLockRequest) -> None:therefore reported spurious contention whenever it collided with one ofthose probes; ``contention_retry`` absorbs such brief holds while agenuine long-lived owner (another process's rekey) still fails fast.- A request with a ``deadline`` retries until that deadline instead.+ A lock request with a ``deadline`` retries until that deadline instead."""- if request.deadline is not None:- deadline = request.deadline+ if lock_request.deadline is not None:+ deadline = lock_request.deadlineelse:- deadline = time.monotonic() + request.contention_retry+ deadline = time.monotonic() + lock_request.contention_retrywhile True:try:if os.name == "nt":_acquire_windows_lock(fd,- request.lock_path,- mode=request.mode,- blocking=request.blocking,+ lock_request.lock_path,+ mode=lock_request.mode,+ blocking=lock_request.blocking,)else:_acquire_posix_lock(fd,- request.lock_path,- mode=request.mode,- blocking=request.blocking,+ lock_request.lock_path,+ mode=lock_request.mode,+ blocking=lock_request.blocking,)except RekeyLockContentionError:- if request.blocking or time.monotonic() >= deadline:+ if lock_request.blocking or time.monotonic() >= deadline:raisetime.sleep(_CONTENTION_RETRY_INTERVAL)else:@@ -528,9 +532,9 @@ def _acquire_os_lock_with_retry(fd: int, request: _SidecarLockRequest) -> None:def _acquire_sidecar_lock_locked(- request: _SidecarLockRequest,+ lock_request: _SidecarLockRequest,) -> Generator[None, None, None]:- fd = _open_sidecar(request)+ fd = _open_sidecar(lock_request)acquired = False# The failure of the acquire or of the protected body, recorded as it# passes through. A release failure is added to it as a note, and is@@ -544,10 +548,10 @@ def _acquire_sidecar_lock_locked(try:acquire_error: RekeySidecarIOError | None = Nonetry:- _acquire_os_lock_with_retry(fd, request)+ _acquire_os_lock_with_retry(fd, lock_request)except OSError as error:acquire_error = _sidecar_io_error(- request, RekeySidecarOperation.ACQUIRE, error+ lock_request, RekeySidecarOperation.ACQUIRE, error)if acquire_error is not None:raise acquire_error # noqa: TRY301 — recorded as active_error by the except below@@ -567,14 +571,16 @@ def _acquire_sidecar_lock_locked(except OSError as error:cleanup_errors.append(_sidecar_io_error(- request, RekeySidecarOperation.UNLOCK, error+ lock_request, RekeySidecarOperation.UNLOCK, error))try:os.close(fd)except OSError as error:cleanup_errors.append(- _sidecar_io_error(request, RekeySidecarOperation.CLOSE, error)+ _sidecar_io_error(+ lock_request, RekeySidecarOperation.CLOSE, error+ ))if active_error is not None:@@ -618,7 +624,7 @@ def acquire_rekey_lock(ends there with ``RekeyLockContentionError``. It overrides ``blocking``,``local_wait`` and ``contention_retry``."""- request = _SidecarLockRequest(+ lock_request = _SidecarLockRequest(db_path=db_path,lock_path=db_path.with_name(f"{db_path.name}.rekey.lock"),mode=AuthorizationLeaseMode.EXCLUSIVE,@@ -627,7 +633,7 @@ def acquire_rekey_lock(contention_retry=contention_retry,deadline=None if timeout is None else time.monotonic() + timeout,)- with _acquire_sidecar_lock(request):+ with _acquire_sidecar_lock(lock_request):yield@@ -638,13 +644,13 @@ def acquire_authorization_lease(blocking: bool = True,) -> Generator[None, None, None]:"""Hold a persistent shared or exclusive authorization sidecar lease."""- request = _SidecarLockRequest(+ lock_request = _SidecarLockRequest(db_path=db_path,lock_path=_authorization_lock_path(db_path),mode=mode,blocking=blocking,)- with _acquire_sidecar_lock(request):+ with _acquire_sidecar_lock(lock_request):yield