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.

10.2 KB
Raw Blame
"""
Security environment settings.

These settings control security-related behavior like SSRF validation
and CORS origin restrictions.
"""

import os
from ..env_settings import BooleanSetting, StringSetting


# External environment variables (set by pytest, CI systems)
# These are read directly since we don't control them
PYTEST_CURRENT_TEST = os.environ.get("PYTEST_CURRENT_TEST")


# LDR Security settings (our application's security configuration)
SECURITY_SETTINGS = [
    StringSetting(
        key="security.cors.allowed_origins",
        description=(
            "Allowed CORS origins for API routes (comma-separated). "
            "Use '*' for all origins, empty for same-origin only. "
            "Example: 'https://example.com,https://app.example.com'"
        ),
        default=None,
    ),
    StringSetting(
        key="security.websocket.allowed_origins",
        description=(
            "Allowed origins for WebSocket/Socket.IO connections (comma-separated). "
            "Unset or empty means same-origin only (default); use '*' to allow all origins. "
            "Example: 'https://example.com,https://app.example.com'"
        ),
        default=None,
    ),
    BooleanSetting(
        key="notifications.allow_private_ips",
        description=(
            "Allow notification webhooks to target private/local IP addresses. "
            "Environment-only to prevent SSRF bypass via the user-writable settings API. "
            "Only enable this if your notification endpoints are on a trusted local network."
        ),
        default=False,
    ),
    BooleanSetting(
        key="security.allow_nat64",
        description=(
            "Allow outbound traffic to NAT64 prefixes (64:ff9b::/96 RFC 6052 "
            "well-known and 64:ff9b:1::/48 RFC 8215 local-use). Disabled by "
            "default to close the IPv6-wrapped SSRF bypass class — on hosts "
            "configured with NAT64 routes, attacker-supplied URLs can wrap "
            "cloud-metadata or RFC1918 destinations through these prefixes. "
            "Enable only on IPv6-only deployments (DNS64+NAT64) where "
            "outbound IPv4 traffic is synthesized through this prefix and "
            "the operator has accepted the residual SSRF risk. 6to4 "
            "(2002::/16), Teredo (2001::/32), the discard prefix "
            "(100::/64), the deprecated IPv4-Compatible IPv6 form "
            "(::/96, except ::1 loopback which follows the loopback/"
            "private flags), and the IPv4-Translated/SIIT form "
            "(::ffff:0:0:0/96) remain unconditionally blocked because "
            "they have no live legitimate use in 2026. The cloud-metadata block "
            "(ALWAYS_BLOCKED_METADATA_IPS) still applies via embedded-IPv4 "
            "extraction — see SECURITY.md."
        ),
        default=False,
    ),
    BooleanSetting(
        key="notifications.allow_outbound",
        description=(
            "Master switch for outbound notification webhooks (Apprise). "
            "Disabled by default so outbound delivery requires an explicit "
            "operator decision. The send path uses a synchronous DNS guard "
            "against rebinding and private/metadata access; see SECURITY.md "
            "'Notification Webhook SSRF' for details. Distinct from the per-user "
            "notifications.enabled toggle in the settings UI: this is the "
            "server-level operator gate, env-only so it cannot be flipped via "
            "the user-writable settings API."
        ),
        default=False,
    ),
    BooleanSetting(
        key="policy.allow_unprotected_egress",
        description=(
            "Allow users to select the UNPROTECTED egress scope. Disabled by "
            "default; this is an environment-only operator gate and cannot be "
            "changed through the user-writable settings API. Hard SSRF and "
            "cloud-metadata protections remain active when enabled."
        ),
        default=False,
    ),
    BooleanSetting(
        key="search.allow_private_engine_urls",
        description=(
            "Allow user-editable PUBLIC search-engine URLs (e.g. the SearXNG "
            "instance_url) to point at private / loopback / link-local "
            "addresses. Environment-only operator gate so it cannot be flipped "
            "through the user-writable settings API. Disabled by default: a "
            "public-nature engine (its data source is the public internet) "
            "pointed at an internal host lets any authenticated user turn a "
            "research run into an internal port scan / service probe, breaking "
            "the PUBLIC_ONLY egress promise. Enable only when you self-host "
            "SearXNG on localhost/LAN and accept that engine fetches may reach "
            "your private network. To approve only specific origins instead "
            "of all private addresses, use the finer-grained "
            "LDR_SEARCH_PRIVATE_ENGINE_URL_ALLOWLIST. "
            "Docker deployments instead pin the URL "
            "directly via LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_"
            "INSTANCE_URL, which is trusted as operator-provisioned. "
            "Cloud-metadata endpoints (ALWAYS_BLOCKED_METADATA_IPS and "
            "ALWAYS_BLOCKED_METADATA_HOSTNAMES) stay blocked regardless of "
            "this flag."
        ),
        default=False,
    ),
    StringSetting(
        key="search.private_engine_url_allowlist",
        description=(
            "Comma-separated list of exact URL origins "
            "(scheme://host[:port]) that user-editable PUBLIC search-engine "
            "URLs (e.g. the SearXNG instance_url) may use even though they "
            "are private / loopback / link-local — e.g. "
            "'http://localhost:8080,http://192.168.1.5:8888'. Finer-grained "
            "alternative to LDR_SEARCH_ALLOW_PRIVATE_ENGINE_URLS=true: "
            "private egress is enabled for an engine only when its "
            "configured URL matches a listed origin (the engine's request "
            "chain, including redirects, then runs with private access — "
            "like the blanket flag, but conditional on the match), rather "
            "than for any private URL. Matching is exact scheme + host + port "
            "(default ports 80/443 implied, host case-insensitive, "
            "path/query ignored); no wildcards or CIDR ranges. Entries that "
            "fail to parse are ignored. Environment-only operator setting "
            "so it cannot be edited through the user-writable settings API. "
            "Cloud-metadata endpoints (ALWAYS_BLOCKED_METADATA_IPS and "
            "ALWAYS_BLOCKED_METADATA_HOSTNAMES) and non-http(s) schemes stay "
            "blocked even if listed."
        ),
        default=None,
    ),
    BooleanSetting(
        key="search.allow_private_result_fetch",
        description=(
            "Allow full-content fetching (search.snippets_only off) to "
            "follow the RESULT URLs a PUBLIC search engine returns into "
            "private / "
            "loopback addresses, e.g. an internal wiki that a self-hosted "
            "SearXNG instance indexes. Distinct from, and required in "
            "addition to, the instance-URL approval "
            "(LDR_SEARCH_ALLOW_PRIVATE_ENGINE_URLS, "
            "LDR_SEARCH_PRIVATE_ENGINE_URL_ALLOWLIST or an env-locked "
            "instance URL): that approval only covers reaching the engine "
            "itself, and because a public engine proxies the public web, "
            "extending it to the URLs the engine returns would let a "
            "poisoned index turn result fetching into a scan of the LDR "
            "host's private network. Environment-only operator gate so it "
            "cannot be flipped through the user-writable settings API. "
            "Disabled by default and not set by the bundled "
            "docker-compose.yml. Link-local addresses (169.254.0.0/16, "
            "fe80::/10) and the cloud-metadata endpoints in "
            "ALWAYS_BLOCKED_METADATA_IPS and "
            "ALWAYS_BLOCKED_METADATA_HOSTNAMES stay blocked regardless of "
            "this flag. Takes effect only under the unprotected egress scope: "
            "under every other scope, the default adaptive scope included, "
            "private result URLs stay blocked even with this flag set."
        ),
        default=False,
    ),
    BooleanSetting(
        key="research_library.allow_filesystem_pdf_storage",
        description=(
            "Allow users to select the UNENCRYPTED 'filesystem' PDF storage "
            "mode for library-downloaded PDFs. Disabled by default; this is "
            "an environment-only operator gate and cannot be changed through "
            "the user-writable settings API. Filesystem mode writes fetched "
            "third-party PDFs as PLAINTEXT to a shared library directory "
            "(cleartext storage of sensitive information, CWE-312). When "
            "off, the 'filesystem' option is withheld from the settings UI "
            "and any stored or "
            "environment value of 'filesystem' is coerced to the encrypted "
            "'database' mode at write time. Previously-written plaintext "
            "files remain readable. Enable only when the library directory "
            "lives on an operator-controlled encrypted volume."
        ),
        default=False,
    ),
    BooleanSetting(
        key="research_library.allow_shared_library",
        description=(
            "Allow shared-library mode, which drops the per-user library "
            "directory boundary so all users' downloaded PDFs live in one "
            "shared directory. Disabled by default; this is an "
            "environment-only operator gate and cannot be enabled through the "
            "user-writable settings API. The shared_library flag is otherwise "
            "user-editable; leaving shared mode user-toggleable would let an "
            "account drop its per-user directory boundary. The storage_path "
            "is now operator-only, but legacy saved paths remain in place. "
            "When off, the per-user subdirectory is always "
            "enforced regardless of the user's shared_library setting. Enable "
            "only on single-tenant or mutually-trusted deployments."
        ),
        default=False,
    ),
]