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.

security: make allow_registrations env-var-only (#2164)

LearningCircuitf24feefc86c9
diff --git a/docker-compose.yml b/docker-compose.yml
index 090ffe2731..71381de200 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -73,6 +73,13 @@ services:
- LDR_LLM_OLLAMA_URL=http://ollama:11434
- LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL=http://searxng:8080
+ # ============================================================================
+ # SECURITY: Disable user registration (recommended for public deployments)
+ # When set to false, no new accounts can be created through the web UI.
+ # Register your initial account FIRST, then set this to false.
+ # ============================================================================
+ # - LDR_APP_ALLOW_REGISTRATIONS=false
+
# ============================================================================
# ADVANCED: Uncomment ONLY if you need to enforce/lock these settings
# WARNING: This will disable UI configuration for these settings!
diff --git a/docs/docker-compose-guide.md b/docs/docker-compose-guide.md
index 055e7d5306..d9ba4b5525 100644
--- a/docs/docker-compose-guide.md
+++ b/docs/docker-compose-guide.md
@@ -59,6 +59,7 @@ Most settings can be configured through the web UI at http://localhost:5000/sett
| `LDR_WEB_HOST` | Bind address (default: `0.0.0.0` for Docker) |
| `LDR_WEB_PORT` | Internal port (default: `5000`) |
| `LDR_DATA_DIR` | Data directory (default: `/data`) |
+| `LDR_APP_ALLOW_REGISTRATIONS` | Allow new user registration (default: `true`). Set to `false` for public deployments after creating your initial account. |
| `LDR_LLM_PROVIDER` | LLM provider (`ollama`, `openai`, `anthropic`, etc.) |
| `LDR_LLM_MODEL` | Model name (e.g., `gemma3:12b`) |
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 66c8c5a0a5..7622fce2d7 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -248,8 +248,8 @@
},
"app.allow_registrations": {
"category": "app_interface",
- "description": "Allow new user registrations through the web interface.",
- "editable": true,
+ "description": "Allow new user registrations through the web interface. This setting cannot be changed from the UI for security reasons. To disable registration on public-facing deployments, set the environment variable LDR_APP_ALLOW_REGISTRATIONS=false. Enabled by default so initial account creation works out of the box.",
+ "editable": false,
"max_value": null,
"min_value": null,
"name": "Allow Registrations",
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index c434fa4d7e..ef905cf4a3 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -346,6 +346,19 @@ def save_all_settings():
for setting in db_session.query(Setting).all()
}
+ # Filter out non-editable settings
+ non_editable_keys = [
+ key
+ for key in form_data.keys()
+ if key in all_db_settings and not all_db_settings[key].editable
+ ]
+ if non_editable_keys:
+ logger.warning(
+ f"Skipping non-editable settings: {non_editable_keys}"
+ )
+ for key in non_editable_keys:
+ del form_data[key]
+
# Update each setting
for key, value in form_data.items():
# Skip corrupted keys or empty strings as keys
@@ -714,6 +727,19 @@ def save_settings():
for setting in db_session.query(Setting).all()
}
+ # Filter out non-editable settings
+ non_editable_keys = [
+ key
+ for key in form_data.keys()
+ if key in all_db_settings and not all_db_settings[key].editable
+ ]
+ if non_editable_keys:
+ logger.warning(
+ f"Skipping non-editable settings: {non_editable_keys}"
+ )
+ for key in non_editable_keys:
+ del form_data[key]
+
# Process each setting
for key, value in form_data.items():
try:
@@ -1021,6 +1047,10 @@ def api_delete_setting(key):
if not db_setting:
return jsonify({"error": f"Setting not found: {key}"}), 404
+ # Check if setting is editable
+ if not db_setting.editable:
+ return jsonify({"error": f"Setting {key} is not editable"}), 403
+
# Delete setting
success = settings_manager.delete_setting(key)
if success:
diff --git a/src/local_deep_research/web/server_config.py b/src/local_deep_research/web/server_config.py
index 1242bcd08c..e9a8ad4afd 100644
--- a/src/local_deep_research/web/server_config.py
+++ b/src/local_deep_research/web/server_config.py
@@ -6,6 +6,7 @@ variables and database settings.
"""
import json
+import os
from pathlib import Path
from typing import Dict, Any
@@ -61,27 +62,59 @@ def load_server_config() -> Dict[str, Any]:
"checkbox",
default=True,
),
- # Rate limiting settings
- "rate_limit_default": get_typed_setting_value(
- "security.rate_limit_default",
- saved_config.get("rate_limit_default"),
- "text",
- default="5000 per hour;50000 per day",
- ),
- "rate_limit_login": get_typed_setting_value(
- "security.rate_limit_login",
- saved_config.get("rate_limit_login"),
- "text",
- default="5 per 15 minutes",
- ),
- "rate_limit_registration": get_typed_setting_value(
- "security.rate_limit_registration",
- saved_config.get("rate_limit_registration"),
- "text",
- default="3 per hour",
- ),
}
+ # Security: if LDR_APP_ALLOW_REGISTRATIONS is set to an unrecognized
+ # value (e.g. "disabled", "nein", typos like "flase"), default to False
+ # (registrations disabled) rather than True. This "fail closed" approach
+ # prevents accidental open registration when an admin clearly intended to
+ # restrict it but used a non-standard boolean string.
+ _RECOGNIZED_BOOL_VALUES = {
+ "true",
+ "false",
+ "1",
+ "0",
+ "yes",
+ "no",
+ "on",
+ "off",
+ }
+ raw_reg_env = os.getenv("LDR_APP_ALLOW_REGISTRATIONS")
+ if raw_reg_env is not None:
+ normalized = raw_reg_env.lower().strip()
+ if normalized not in _RECOGNIZED_BOOL_VALUES:
+ logger.warning(
+ f"LDR_APP_ALLOW_REGISTRATIONS='{raw_reg_env}' is not a "
+ f"recognized boolean value. Defaulting to FALSE "
+ f"(registrations disabled) for security. Use "
+ f"'true'/'false', '1'/'0', 'yes'/'no', or 'on'/'off'."
+ )
+ config["allow_registrations"] = False
+
+ config.update(
+ {
+ # Rate limiting settings
+ "rate_limit_default": get_typed_setting_value(
+ "security.rate_limit_default",
+ saved_config.get("rate_limit_default"),
+ "text",
+ default="5000 per hour;50000 per day",
+ ),
+ "rate_limit_login": get_typed_setting_value(
+ "security.rate_limit_login",
+ saved_config.get("rate_limit_login"),
+ "text",
+ default="5 per 15 minutes",
+ ),
+ "rate_limit_registration": get_typed_setting_value(
+ "security.rate_limit_registration",
+ saved_config.get("rate_limit_registration"),
+ "text",
+ default="3 per hour",
+ ),
+ }
+ )
+
return config
diff --git a/tests/web/routes/test_settings_routes.py b/tests/web/routes/test_settings_routes.py
index 433be81c5c..ed8d5ce4a6 100644
--- a/tests/web/routes/test_settings_routes.py
+++ b/tests/web/routes/test_settings_routes.py
@@ -834,3 +834,86 @@ class TestCalculateWarningsExtended:
result = calculate_warnings()
assert isinstance(result, list)
+
+
+class TestNonEditableSettingsProtection:
+ """Tests that non-editable settings cannot be modified via bulk save endpoints."""
+
+ def test_save_all_settings_skips_non_editable(self, authenticated_client):
+ """Test that save_all_settings silently skips non-editable settings like allow_registrations."""
+ # First, verify the setting exists and get its current value
+ get_response = authenticated_client.get(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert get_response.status_code == 200
+ original_value = get_response.get_json().get("value")
+
+ # Attempt to change app.allow_registrations (non-editable)
+ response = authenticated_client.post(
+ f"{SETTINGS_PREFIX}/save_all_settings",
+ json={
+ "app.allow_registrations": not original_value,
+ },
+ content_type="application/json",
+ )
+ # Should succeed (200) — the non-editable key is silently skipped
+ assert response.status_code == 200
+
+ # Verify the non-editable setting was NOT changed
+ verify_response = authenticated_client.get(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert verify_response.status_code == 200
+ assert verify_response.get_json()["value"] == original_value
+
+ def test_save_settings_form_skips_non_editable(self, authenticated_client):
+ """Test that save_settings (form POST) silently skips non-editable settings."""
+ # Get current value
+ get_response = authenticated_client.get(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert get_response.status_code == 200
+ original_value = get_response.get_json().get("value")
+
+ # Attempt to change via form POST
+ response = authenticated_client.post(
+ f"{SETTINGS_PREFIX}/save_settings",
+ data={
+ "app.allow_registrations": "false"
+ if original_value
+ else "true",
+ },
+ content_type="application/x-www-form-urlencoded",
+ follow_redirects=True,
+ )
+ # Should redirect/succeed — non-editable key is silently skipped
+ assert response.status_code in [200, 302]
+
+ # Verify the non-editable setting was NOT changed
+ verify_response = authenticated_client.get(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert verify_response.status_code == 200
+ assert verify_response.get_json()["value"] == original_value
+
+ def test_put_api_rejects_non_editable(self, authenticated_client):
+ """Test that PUT /api/<key> returns 403 for non-editable settings (existing behavior)."""
+ response = authenticated_client.put(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations",
+ json={"value": False},
+ content_type="application/json",
+ )
+ assert response.status_code == 403
+
+ def test_delete_api_rejects_non_editable(self, authenticated_client):
+ """Test that DELETE /api/<key> returns 403 for non-editable settings."""
+ response = authenticated_client.delete(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert response.status_code == 403
+
+ # Verify the setting still exists
+ get_response = authenticated_client.get(
+ f"{SETTINGS_PREFIX}/api/app.allow_registrations"
+ )
+ assert get_response.status_code == 200
diff --git a/tests/web/test_server_config.py b/tests/web/test_server_config.py
index f94b92d986..b222d5ad0e 100644
--- a/tests/web/test_server_config.py
+++ b/tests/web/test_server_config.py
@@ -184,6 +184,76 @@ class TestLoadServerConfig:
assert "allow_registrations" in result
assert result["allow_registrations"] is True
+ def test_unrecognized_allow_registrations_defaults_to_false(
+ self, tmp_path, monkeypatch
+ ):
+ """Unrecognized LDR_APP_ALLOW_REGISTRATIONS value should default to False (fail closed)."""
+ monkeypatch.setenv("LDR_APP_ALLOW_REGISTRATIONS", "disabled")
+
+ with patch(
+ "local_deep_research.web.server_config.get_data_dir",
+ return_value=str(tmp_path),
+ ):
+ with patch(
+ "local_deep_research.web.server_config.get_typed_setting_value",
+ side_effect=lambda key, val, typ, default: default,
+ ):
+ with patch(
+ "local_deep_research.web.server_config.logger"
+ ) as mock_logger:
+ from local_deep_research.web.server_config import (
+ load_server_config,
+ )
+
+ result = load_server_config()
+
+ # Should have warned about unrecognized value
+ warning_calls = [
+ str(c) for c in mock_logger.warning.call_args_list
+ ]
+ assert any(
+ "disabled" in call and "recognized" in call
+ for call in warning_calls
+ ), (
+ f"Expected warning about 'disabled', got: {warning_calls}"
+ )
+
+ # Should default to False (fail closed) for security
+ assert result["allow_registrations"] is False
+
+ def test_no_warning_on_recognized_allow_registrations_value(
+ self, tmp_path, monkeypatch
+ ):
+ """Should NOT warn when LDR_APP_ALLOW_REGISTRATIONS is a recognized boolean value."""
+ monkeypatch.setenv("LDR_APP_ALLOW_REGISTRATIONS", "false")
+
+ with patch(
+ "local_deep_research.web.server_config.get_data_dir",
+ return_value=str(tmp_path),
+ ):
+ with patch(
+ "local_deep_research.web.server_config.get_typed_setting_value",
+ side_effect=lambda key, val, typ, default: default,
+ ):
+ with patch(
+ "local_deep_research.web.server_config.logger"
+ ) as mock_logger:
+ from local_deep_research.web.server_config import (
+ load_server_config,
+ )
+
+ load_server_config()
+
+ # No warning should contain "recognized"
+ warning_calls = [
+ str(c) for c in mock_logger.warning.call_args_list
+ ]
+ assert not any(
+ "recognized" in call for call in warning_calls
+ ), (
+ f"Unexpected warning about recognized value: {warning_calls}"
+ )
+
class TestSaveServerConfig:
"""Tests for save_server_config function."""