What changed, and why it matters
This commit changes LNbits so that, by default, login cookies are no longer marked 'Secure' (which normally forces HTTPS). The change is intentional to keep fresh local HTTP installs working out of the box, but it means a default installation on plain HTTP will send session cookies over unencrypted connections. An attacker on the same network could potentially sniff or steal those cookies and impersonate the admin. The patch also adds tests confirming the new default behavior and that the secure flag is only added when an operator explicitly enables it.
Operators should explicitly set `auth_https_only=True` (and deploy HTTPS) for any production or remotely accessible instance. The project should consider emitting a startup warning when the setting is disabled, and the documentation should clearly state that the default is optimized for local development, not production.
Security signals we found
Default security control disabled: `auth_https_only` changed from `True` to `False`
Session cookie `Secure` flag removed by default
First-install admin setup now works over plain HTTP by default
Added regression tests codifying non-secure cookie behavior as default
Evidence from the diff
The patch flips the default value of auth_https_only from True to False in lnbits/settings.py. When auth_https_only is True, auth cookies are set with the Secure attribute, requiring HTTPS. With the new default False, fresh installs running on HTTP will receive non-Secure cookie_access_token cookies. The added tests in tests/api/test_auth_api.py assert that first-install responses do not include Secure by default, and do include it when auth_https_only is explicitly enabled. This is a deliberate usability/security trade-off, not an accidental bug, but it weakens default transport security.
Changed components
lnbits/settings.pytests/api/test_auth_api.pyAuthentication/session cookie handlingFirst-install setup endpoint (`/api/v1/auth/first_install`)Inspect captured patch +45 / −2
diff --git a/lnbits/settings.py b/lnbits/settings.py
index 2e110d9..94ba5dd 100644
--- a/lnbits/settings.py
+++ b/lnbits/settings.py
@@ -1007,8 +1007,9 @@ class EnvSettings(LNbitsSettings):
debug_database: bool = Field(default=False)
bundle_assets: bool = Field(default=True)
# When enabled, auth cookies require HTTPS and SSO will reject insecure HTTP.
- # Set to false for local/dev environments that run without TLS.
- auth_https_only: bool = Field(default=True)
+ # Keep disabled by default so local HTTP installs continue to work unless
+ # operators explicitly opt into HTTPS-only auth cookies.
+ auth_https_only: bool = Field(default=False)
host: str = Field(default="127.0.0.1")
port: int = Field(default=5000, gt=0)
forwarded_allow_ips: str = Field(default="*")
diff --git a/tests/api/test_auth_api.py b/tests/api/test_auth_api.py
index 416c919..6e4b945 100644
--- a/tests/api/test_auth_api.py
+++ b/tests/api/test_auth_api.py
@@ -135,6 +135,8 @@ async def test_auth_api_first_install_success_and_validation(
)
assert success.status_code == 200
assert success.json()["access_token"]
+ assert "cookie_access_token=" in success.headers["set-cookie"]
+ assert "Secure" not in success.headers["set-cookie"]
updated_superuser = await get_account(settings.super_user, active_only=False)
assert updated_superuser is not None
@@ -159,3 +161,43 @@ async def test_auth_api_first_install_success_and_validation(
await update_account(restored_superuser)
settings.first_install = original_first_install
settings.first_install_token = original_first_install_token
+
+
+@pytest.mark.anyio
+async def test_auth_api_first_install_uses_secure_cookie_when_enabled(
+ http_client: AsyncClient, settings: Settings
+):
+ superuser = await get_account(settings.super_user, active_only=False)
+ assert superuser is not None
+
+ original_username = superuser.username
+ original_password_hash = superuser.password_hash
+ original_first_install = settings.first_install
+ original_auth_https_only = settings.auth_https_only
+
+ new_username = f"secure_{uuid4().hex[:8]}"
+
+ try:
+ settings.first_install = True
+ settings.auth_https_only = True
+
+ success = await http_client.put(
+ "/api/v1/auth/first_install",
+ json={
+ "username": new_username,
+ "password": "secret1234",
+ "password_repeat": "secret1234",
+ },
+ )
+
+ assert success.status_code == 200
+ assert "cookie_access_token=" in success.headers["set-cookie"]
+ assert "Secure" in success.headers["set-cookie"]
+ finally:
+ restored_superuser = await get_account(settings.super_user, active_only=False)
+ assert restored_superuser is not None
+ restored_superuser.username = original_username
+ restored_superuser.password_hash = original_password_hash
+ await update_account(restored_superuser)
+ settings.first_install = original_first_install
+ settings.auth_https_only = original_auth_https_only
Why this scored 42/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.