Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

fix(oidc): accept quoted OIDC_SCOPES values and quote them in the env templates (#1247)

Tássio Noronha6f39a65198d0
diff --git a/.env.example b/.env.example
index fd62d234..7425cac6 100644
--- a/.env.example
+++ b/.env.example
@@ -24,11 +24,13 @@ ENABLE_BANKING_APP_ID=
## Redirect/callback URL to register in the provider:
## http://localhost:${FRONTEND_PORT:-3000}/api/auth/oidc/callback
# OIDC_ENABLED=true
-# OIDC_PROVIDER_NAME=Pocket ID
+# OIDC_PROVIDER_NAME="My SSO"
# OIDC_DISCOVERY_URL=https://id.example.com/.well-known/openid-configuration
# OIDC_CLIENT_ID=securo
# OIDC_CLIENT_SECRET=your-client-secret
-# OIDC_SCOPES=openid email profile
+# Quoted on purpose: values with spaces must be quoted for deploy scripts
+# that source this file with a shell. Compose and the backend strip the quotes.
+# OIDC_SCOPES="openid email profile"
# OIDC_AUTO_REGISTER=true
# OIDC_REQUIRE_VERIFIED_EMAIL=true
# Optional: require OIDC-only login; requires OIDC_ENABLED, OIDC_CLIENT_ID, and OIDC_DISCOVERY_URL
diff --git a/backend/.env.example b/backend/.env.example
index 674295be..063ce9e7 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -30,7 +30,9 @@ OIDC_CLIENT_ID=
OIDC_CLIENT_SECRET=
# Defaults to ${FRONTEND_URL}/api/auth/oidc/callback
OIDC_REDIRECT_URI=
-OIDC_SCOPES=openid email profile
+# Quoted on purpose: values with spaces must be quoted for deploy scripts
+# that source this file with a shell. Compose and the backend strip the quotes.
+OIDC_SCOPES="openid email profile"
OIDC_AUTO_REGISTER=true
OIDC_REQUIRE_VERIFIED_EMAIL=true
# Set to false only with OIDC_ENABLED=true, OIDC_CLIENT_ID, and OIDC_DISCOVERY_URL configured
diff --git a/backend/app/core/config.py b/backend/app/core/config.py
index 87bd419e..e5487538 100644
--- a/backend/app/core/config.py
+++ b/backend/app/core/config.py
@@ -2,7 +2,7 @@ from functools import lru_cache
from os import getenv
from pathlib import Path
-from pydantic import SecretStr, model_validator
+from pydantic import SecretStr, field_validator, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
# Use the same environment variable that systemd uses: https://systemd.io/CREDENTIALS/
@@ -114,6 +114,18 @@ class Settings(BaseSettings):
oidc_admin_roles: str = "" # comma-separated provider roles/groups that grant Securo admin
oidc_workspace_role_map: str = "" # JSON: {"provider-role": "owner|editor|viewer"}
+ # Deploy scripts that source the .env file with a shell need values with
+ # spaces to be quoted, and some panels (PaaS env vars, manual exports)
+ # keep those quotes in the value. Drop one pair of surrounding quotes so
+ # the provider always receives clean scope tokens (#887).
+ @field_validator("oidc_scopes")
+ @classmethod
+ def _strip_oidc_scopes_quotes(cls, value: str) -> str:
+ value = value.strip()
+ if len(value) >= 2 and value[0] == value[-1] and value[0] in ("'", '"'):
+ value = value[1:-1].strip()
+ return value
+
# Celery
redis_url: str = "redis://localhost:6379/0"
diff --git a/backend/tests/test_config.py b/backend/tests/test_config.py
index cf309f4e..d1c756c1 100644
--- a/backend/tests/test_config.py
+++ b/backend/tests/test_config.py
@@ -163,6 +163,25 @@ def test_local_auth_disabled_requires_complete_oidc_configuration(
)
+ ("raw", "expected"),
+ [
+ ('"openid email profile groups"', "openid email profile groups"),
+ ("'openid email profile groups'", "openid email profile groups"),
+ (' "openid email profile" ', "openid email profile"),
+ ("openid email profile", "openid email profile"),
+ ("openid", "openid"),
+ ],
+)
+def test_oidc_scopes_strips_surrounding_quotes(monkeypatch, raw: str, expected: str):
+ """Deploy scripts that source the .env with a shell force users to quote
+ values with spaces, and some panels keep those quotes in the value; the
+ provider must still receive clean scope tokens (#887)."""
+ monkeypatch.setenv("OIDC_SCOPES", raw)
+
+ assert Settings(_env_file=None).oidc_scopes == expected
+
+
def test_empty_frontend_url_uses_frontend_port(monkeypatch):
"""docker-compose.yml passes FRONTEND_URL empty when unset (no nested
default, which podman-compose < 1.6.0 mangles: #1162) plus FRONTEND_PORT."""