~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): scope settings exception scan suppressions (#7599)
LearningCircuitf06daee87bbc
diff --git a/.github/SECURITY_ALERTS.md b/.github/SECURITY_ALERTS.mdindex d3c4102a99..83610c5772 100644--- a/.github/SECURITY_ALERTS.md+++ b/.github/SECURITY_ALERTS.md@@ -328,6 +328,32 @@ is tracked in #6792; this PR does not change the CodeQL configuration.---+## Settings exception diagnostics++The `python_lang_exception` rule remains enabled. Reviewed validation and+lifecycle raises in `settings/manager.py` have statement-scoped annotations:++- Number, list, JSON-constant and environment-boolean validation errors use+ fixed text that does not include the rejected value.+- `SettingsValueError` reports the setting key, source and a fixed reason or an+ allowlisted control type. It does not include the configured value. Parser+ failures are discarded before raising it, including their exception chains.+- Missing-session and closed-manager errors use fixed lifecycle guidance.+- The thread-safety error includes only numeric IDs from `threading.get_ident()`.++`tests/settings/test_settings_exception_privacy.py` checks rejected values,+unsupported control metadata, retained parser exceptions, session-state privacy+and valid-input controls. Existing settings and HTTP error-response tests also+qualify the diagnostic boundary.++These annotations apply only to the reviewed raises. Changes to their data+sources or output require renewed review; unrelated exception findings continue+to be scanned. Settings-manager and privacy-test changes trigger the Bearer PR+workflow. A successful scanner job alone does not qualify a release: the release+gate still requires fresh processed scan evidence and acceptable open alerts.++---+## Container Image CVEs**Status:** Documented, awaiting upstream fixesdiff --git a/.github/workflows/bearer.yml b/.github/workflows/bearer.ymlindex ec6c65e44b..1517a38dca 100644--- a/.github/workflows/bearer.yml+++ b/.github/workflows/bearer.yml@@ -4,6 +4,8 @@ on:pull_request:paths:- "src/local_deep_research/database/sqlcipher_compat.py"+ - "src/local_deep_research/settings/manager.py"+ - "tests/settings/test_settings_exception_privacy.py"- "bearer.yml"- ".github/workflows/bearer.yml"- ".github/scripts/prepare_bearer_sarif.py"diff --git a/changelog.d/+bearer-settings-diagnostics.security.md b/changelog.d/+bearer-settings-diagnostics.security.mdnew file mode 100644index 0000000000..bcdb5378f2--- /dev/null+++ b/changelog.d/+bearer-settings-diagnostics.security.md@@ -0,0 +1 @@+Resolve false-positive security-scan findings for settings validation and lifecycle diagnostics while retaining exception-message scanning.diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.pyindex 97bfa629b3..048f9dc86a 100644--- a/src/local_deep_research/settings/manager.py+++ b/src/local_deep_research/settings/manager.py@@ -124,9 +124,13 @@ def parse_boolean(value: Any) -> bool:def _parse_number(x):"""Parse number, returning int if it's a whole number, otherwise float."""if isinstance(x, bool):+ # Fixed validation text; no configured value is included.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a number")f = float(x)if not math.isfinite(f):+ # Fixed validation text; no configured value is included.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a finite number")if f.is_integer():return int(f)@@ -169,12 +173,16 @@ def _parse_multiselect(x):if stripped.startswith(("[", "{")):parsed = json.loads(stripped)if not isinstance(parsed, list):+ # Fixed validation text; the parsed object is not included.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a list")return parsed# Comma-separated values are an explicitly supported input format.return [item.strip() for item in stripped.split(",") if item.strip()]if x is None:return None+ # Fixed validation text; the rejected carrier is not included.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a list or comma-separated values")@@ -508,6 +516,8 @@ UI_ELEMENT_TO_SETTING_TYPE: Dict[str, Callable[..., Any]] = {def _reject_json_constant(_value: str):"""Reject JSON's non-standard NaN/Infinity extensions without echoing input."""+ # The rejected argument is unused; this diagnostic is constant.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a finite JSON number")@@ -518,6 +528,8 @@ def _parse_environment_boolean(value: str) -> bool:return Trueif normalized in ("false", "0", "no", "off", "disabled"):return False+ # Fixed validation text; the environment value is not included.+ # bearer:disable python_lang_exceptionraise ValueError("Expected a boolean token")@@ -555,6 +567,8 @@ def get_typed_setting_value(not isinstance(ui_element, str)or ui_element not in UI_ELEMENT_TO_SETTING_TYPE):+ # Report only the setting key, source and this fixed reason.+ # bearer:disable python_lang_exceptionraise SettingsValueError(key, source=source, reason="unsupported setting type")@@ -575,6 +589,8 @@ def get_typed_setting_value(pass# Raise outside the handler: even a suppressed __context__ can contain# credentials from float()/json.loads() errors. See #6201.+ # The control type is allowlisted above; no value or parser error is used.+ # bearer:disable python_lang_exceptionraise SettingsValueError(key, source=source, reason=f"expected a valid {ui_element} value")@@ -737,6 +753,8 @@ class SettingsManager(ISettingsManager):from ..database.models import Settingif self.db_session is None:+ # Fixed lifecycle text; no session contents are included.+ # bearer:disable python_lang_exceptionraise RuntimeError("Database session is not initialized")settings_count = self.db_session.query(Setting).count()@@ -761,6 +779,8 @@ class SettingsManager(ISettingsManager):"""Check if this instance is being used in the same thread it was created in."""current_thread_id = threading.get_ident()if self.db_session and current_thread_id != self._creation_thread_id:+ # Only numeric IDs from threading.get_ident() are interpolated.+ # bearer:disable python_lang_exceptionraise RuntimeError(f"SettingsManager instance created in thread {self._creation_thread_id} "f"is being used in thread {current_thread_id}. This is not thread-safe! "@@ -990,6 +1010,8 @@ class SettingsManager(ISettingsManager):"this is a bug; the caller should not reuse a closed manager",key,)+ # Fixed lifecycle text; no setting value is included.+ # bearer:disable python_lang_exceptionraise RuntimeError("SettingsManager has been closed. ""Create a new instance or call close() only at end of lifecycle."@@ -1111,6 +1133,8 @@ class SettingsManager(ISettingsManager):"this is a bug; the caller should not reuse a closed manager",key,)+ # Fixed lifecycle text; no setting value is included.+ # bearer:disable python_lang_exceptionraise RuntimeError("SettingsManager has been closed. ""Create a new instance or call close() only at end of lifecycle."@@ -1305,6 +1329,8 @@ class SettingsManager(ISettingsManager):"SettingsManager.get_all_settings() called after close() — ""this is a bug; the caller should not reuse a closed manager",)+ # Fixed lifecycle text; no settings snapshot is included.+ # bearer:disable python_lang_exceptionraise RuntimeError("SettingsManager has been closed. ""Create a new instance or call close() only at end of lifecycle."@@ -1425,6 +1451,8 @@ class SettingsManager(ISettingsManager):"SettingsManager.get_settings_snapshot() called after close() — ""this is a bug; the caller should not reuse a closed manager",)+ # Fixed lifecycle text; no settings snapshot is included.+ # bearer:disable python_lang_exceptionraise RuntimeError("SettingsManager has been closed. ""Create a new instance or call close() only at end of lifecycle."@@ -1728,6 +1756,8 @@ class SettingsManager(ISettingsManager):# delete the prior row directly and abort the call on failure# rather than blindly inserting a duplicate.if self.db_session is None:+ # Fixed lifecycle text; no session contents are included.+ # bearer:disable python_lang_exceptionraise RuntimeError("Database session is not initialized")try:self._check_thread_safety()@@ -1794,6 +1824,8 @@ class SettingsManager(ISettingsManager):returnif self.db_session is None:+ # Fixed lifecycle text; no imported settings are included.+ # bearer:disable python_lang_exceptionraise RuntimeError("Database session is not initialized")logger.debug(f"Importing {len(settings_data)} settings")changed_keys: list[str] = []diff --git a/tests/settings/test_settings_exception_privacy.py b/tests/settings/test_settings_exception_privacy.pynew file mode 100644index 0000000000..9635cc2c5a--- /dev/null+++ b/tests/settings/test_settings_exception_privacy.py@@ -0,0 +1,187 @@+"""Keep the data-free diagnostics behind scoped scanner annotations private."""++import json+import threading+import traceback++import pytest+from sqlalchemy.orm import Session++from local_deep_research.settings import manager as settings+from local_deep_research.settings.exceptions import SettingsValueError+++_PRIVATE_VALUE = "synthetic-private-settings-value-1761"+_KEY = "llm.diagnostic_privacy_probe"+_ENV = "LDR_LLM_DIAGNOSTIC_PRIVACY_PROBE"+++def _private_error(call, error_type=ValueError):+ with pytest.raises(error_type) as raised:+ call()+ error = raised.value+ rendered = "\n".join(+ [str(error), repr(error), repr(error.args), repr(vars(error))]+ ) + "".join(traceback.format_exception(error))+ assert _PRIVATE_VALUE not in rendered+ # Suppressing display with ``from None`` still retains a sensitive parser+ # exception in __context__. The typed boundary must discard it entirely.+ assert error.__cause__ is None+ assert error.__context__ is None+ return error+++ "parse, raw",+ [+ (settings._parse_multiselect, {"value": _PRIVATE_VALUE}),+ (settings._parse_multiselect, json.dumps({"value": _PRIVATE_VALUE})),+ (settings._parse_environment_boolean, _PRIVATE_VALUE),+ (settings._reject_json_constant, _PRIVATE_VALUE),+ ],+ ids=[+ "multiselect-carrier",+ "multiselect-object",+ "boolean",+ "json-constant",+ ],+)+def test_parser_diagnostics_do_not_echo_rejected_values(parse, raw):+ _private_error(lambda: parse(raw))+++ "source, ui_element, raw",+ [+ ("value", "number", _PRIVATE_VALUE),+ ("value", "range", _PRIVATE_VALUE),+ ("value", "multiselect", '["' + _PRIVATE_VALUE + '",broken'),+ ("environment", "number", _PRIVATE_VALUE),+ ("environment", "range", _PRIVATE_VALUE),+ ("environment", "checkbox", _PRIVATE_VALUE),+ ("environment", "json", '{"value":"' + _PRIVATE_VALUE + '",broken'),+ ("environment", "multiselect", '["' + _PRIVATE_VALUE + '",broken'),+ ],+)+def test_typed_errors_discard_sensitive_parser_state(+ monkeypatch, source, ui_element, raw+):+ monkeypatch.delenv(_ENV, raising=False)+ if source == "environment":+ monkeypatch.setenv(_ENV, raw)+ error = _private_error(+ lambda: settings.get_typed_setting_value(+ _KEY, raw, ui_element, default=5+ ),+ SettingsValueError,+ )+ assert error.key == _KEY+ assert error.source == source+ assert _KEY in error.diagnostic+ assert source in error.diagnostic++[email protected]("source", ["value", "environment"])+def test_unsupported_control_metadata_does_not_enter_the_diagnostic(+ monkeypatch, source+):+ monkeypatch.delenv(_ENV, raising=False)+ if source == "environment":+ monkeypatch.setenv(_ENV, _PRIVATE_VALUE)+ error = _private_error(+ lambda: settings.get_typed_setting_value(+ _KEY, {"value": _PRIVATE_VALUE}, _PRIVATE_VALUE+ ),+ SettingsValueError,+ )+ assert error.key == _KEY+ assert error.source == source+++ "method, args",+ [+ ("get_setting", (_KEY, {"value": _PRIVATE_VALUE})),+ ("set_setting", (_KEY, {"value": _PRIVATE_VALUE})),+ ("get_all_settings", ()),+ ("get_settings_snapshot", ()),+ ],+)+def test_closed_manager_does_not_echo_setting_data(method, args):+ manager = settings.SettingsManager(seed_defaults=False)+ manager.default_settings = {_KEY: {"value": _PRIVATE_VALUE}}+ manager.close()+ _private_error(+ lambda: getattr(manager, method)(*args),+ RuntimeError,+ )+++ "method, args, kwargs",+ [+ ("_ensure_settings_initialized", (), {}),+ ("update_db_version", (), {}),+ (+ "import_settings",+ ({_KEY: {"value": _PRIVATE_VALUE}},),+ {"override_locked": True},+ ),+ ],+)+def test_missing_session_does_not_echo_setting_data(method, args, kwargs):+ manager = settings.SettingsManager(seed_defaults=False)+ manager.default_settings = {_KEY: {"value": _PRIVATE_VALUE}}+ try:+ _private_error(+ lambda: getattr(manager, method)(*args, **kwargs), RuntimeError+ )+ finally:+ manager.close()+++def test_wrong_thread_diagnostic_does_not_render_session_state():+ with Session(info={"value": _PRIVATE_VALUE}) as session:+ manager = settings.SettingsManager(+ db_session=session, seed_defaults=False+ )+ outcomes = []+ failures = []++ def check():+ try:+ error = _private_error(+ manager._check_thread_safety, RuntimeError+ )+ outcomes.append((threading.get_ident(), str(error)))+ except BaseException as error:+ failures.append(error)++ worker = threading.Thread(target=check)+ worker.start()+ worker.join(timeout=5)+ assert not worker.is_alive()+ assert not failures+ assert len(outcomes) == 1+ worker_id, message = outcomes[0]+ assert worker_id != manager._creation_thread_id+ assert str(worker_id) in message+ assert str(manager._creation_thread_id) in message+ manager.close()+++ "ui_element, raw, expected",+ [+ ("number", "3.5", 3.5),+ ("range", "7", 7),+ ("multiselect", '["first","second"]', ["first", "second"]),+ ("checkbox", "false", False),+ ("json", '{"selected":true}', {"selected": True}),+ ],+)+def test_valid_environment_values_remain_usable(+ monkeypatch, ui_element, raw, expected+):+ monkeypatch.setenv(_ENV, raw)+ assert settings.get_typed_setting_value(_KEY, None, ui_element) == expected