Skip to content

~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.

8.6 KB
Raw Blame

Fixed a follow-up gap in #5771's settings-redaction work: the write-back guards that stop the [REDACTED] placeholder from being saved over a real secret checked only the outer setting key's sensitivity, so a secret nested a level or more inside a JSON-typed setting (for example a stop_token/page_token/download_token field inside an llm.model_kwargs-style dict) could still have its masked placeholder written back verbatim on save, silently discarding the real value. The guards now check every leaf of a dict/list value for the placeholder regardless of the outer key's name, and now merge a partially-masked container leaf-by-leaf instead of rejecting it outright: editing a plain sibling field (or a masked leaf's non-string sibling, like a port number) next to an untouched [REDACTED] secret restores the secret and saves the edit, rather than 400ing every GET-then-edit round-trip a client can construct. A masked leaf is restored from whatever the stored row actually holds — a list, a dict, a number or a boolean as well as a string — sharing only the emptiness half of the rule the redactor masks on, not its sensitivity check: because a GET collapses any non-empty value stored under one of the exact secret leaf names (api_key, token, password, secret, …) to a bare [REDACTED], a merge that could only restore strings turned an untouched GET-then-save of such a setting into a permanent 400 the client could never satisfy — and on the settings page, where every rendered row is posted on save, that one row rolled back the entire save. Because the merge does not also require the leaf's own sub-key to be sensitive, a placeholder submitted over any other key is restored the same way from whatever non-empty value is stored there (e.g. a stored {"port": 19530} is never masked on read, but a submitted {"port": "[REDACTED]"} over it still restores 19530). That allowance is scoped to a single object (and to a one-item list), where there is exactly one candidate entry to restore into: inside a list of two or more entries the same sibling edit is still deliberately refused with a 400, because by position alone it is indistinguishable from the permutation described next — such an edit has to be split into two writes (change or clear the secret first, then edit the sibling). The same masked container serialized as a JSON string rather than sent as a native object — the shape a <textarea>, or a client that JSON.stringify()'d the field, would send — is now recognized too, not only a native dict/list (recognition is a strict json.loads of a string that starts with {/[, so only well-formed JSON is decoded: a trailing comma, a leading BOM, a Python repr(), JSON with comments, a double-encoded string, or one nested past the depth cap still falls through and is written as the string it is) — this closes both a silent-data-loss path (the string form previously overwrote the stored dict verbatim) and, in an intermediate iteration, a secret-disclosure path where the restored/merged container could be run through the same string-typed coercion a plain "text"/"textarea" setting uses, flattening it to its Python repr() and persisting the real secret as an unredacted plain string; a merged/reconciled container is now always persisted as the container it is, never coerced through a scalar type. A same-length permutation of a list of dicts (e.g. two engine configs swapped) is now rejected rather than trusted positionally, since restoring a masked secret by index alone would silently rebind it to the wrong entry. This closes positional rebinding for lists specifically, not container rebinding in general: a dict-keyed container whose entries are swapped between their keys (and the same shape wrapped in one-item lists) is still accepted, because restoring by key is the same trust the single-object case documented below already accepts. The merged-vs-stored "did anything actually change" comparison is now type-aware, so e.g. 1 submitted over a stored true is recognized as a genuine edit instead of a false no-op. A sensitive multiselect setting's bare [REDACTED] round-trip (the shape redact_value produces for an exact-name match like access_token even when the real value is a list) no longer gets mis-parsed into a one-item list and spuriously rejected, and a spliced one ("[REDACTED],new") on the same setting is now a hard 400 like every other ui_element — the multiselect comma-split previously turned that corrupted scalar into a list whose first item was an exact sentinel match and quietly merged it, persisting ["<real first item>", "new"] with a 200 and destroying every stored item the client had not resent. Also hardened: the qualifier that keeps flag-like settings such as requires_api_key readable now requires an exact match on that literal leaf name, not merely a prefix (it previously matched a qualifier prefix combined with any sensitive suffix, which let real secrets like db_skip_password or local_search_use_milvus_token slip through unredacted); the settings-creation write paths now reject a placeholder-bearing value the way the update paths do, with one gap left open and documented rather than papered over: on the two bulk save routes the create guard is handed the raw submission and has no ui_element to decode it with, so a masked container submitted as a JSON string under a brand-new, non-sensitive key is still stored verbatim (the single-key PUT catches that shape only when the caller also supplies a ui_element). No secret can be lost that way — a brand-new key has no stored value to overwrite — so this is a data-integrity wart, not a disclosure or clobbering path; and the new redaction-guard helpers reject a pathologically deeply nested JSON payload with a clean 400 instead of crashing — on the list branch as well as the dict one, where the positional-rebinding gate and the type-aware equality helper it bottoms out in were initially left uncapped and could still reach a RecursionError (an opaque 500) for a list submitted against a stored list of the same over-deep shape. No shipped default setting is affected by any of these — every trigger requires a user-created setting, audited against all 586 keys the settings loader reads (not only the top-level defaults/settings_*.json files).

Accepted trade-off, documented rather than reverted: merging a partially-masked container also means a caller can edit a non-secret sibling of a restored secret (e.g. repoint a search engine's url while its api_key stays masked) without ever seeing the real secret. Egress/SSRF validation for such settings is keyed off fixed, known setting names — it does not inspect arbitrary user-defined JSON — so this is not, on its own, a new way to bypass egress policy for a registered setting, but it does mean a masked secret can end up silently pointed at a different destination than the one it was originally saved for. See _merge_redacted_container's docstring for the full reasoning.

Separately, the policy.* audit log entry no longer records a changed setting's old/new value verbatim when that value is free-form. _is_policy_setting is a prefix match rather than an allow-list, and three keys already in its scope (policy.trusted_search_engines, policy.trusted_inference_providers, llm.allowed_local_hostnames) ship as editable JSON with no item schema — their egress validator skips non-string entries instead of rejecting them, so a list of dicts carrying an API key was accepted and then written to the log in plaintext at WARNING, on the bulk save paths as well as the single-key PUT. Values that cannot carry free-form text (booleans, numbers, null) and strings drawn from the key's own shipped select options are still recorded verbatim; anything else is recorded as structural metadata only — its type, plus its length for a string or its entry count for a container — with no value-derived token of any kind in the line. An intermediate version of this fix logged a stable truncated SHA-256 of the value; that is an offline dictionary oracle (anyone holding the log can confirm a guessed credential by hashing candidates offline), so it was replaced with the structure-only rendering. The corresponding trade-off is deliberate: change detection on free-form values is coarse (two different same-length secrets render identically), which is what guarantees the line can never be used to confirm a guess. The in-memory settings manager used by the programmatic API and the MCP server also stopped logging a value it fails to convert, matching the fix already applied to the database manager's converter.