From edf649dea62510d483ead53d98c9540fb14dbc50 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:27:50 -0500 Subject: [PATCH] fix: prevent postgres credentials leak (#3895) Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> --- mealie/core/settings/db_providers.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mealie/core/settings/db_providers.py b/mealie/core/settings/db_providers.py index 7cad9653f776..e9bb7705e6de 100644 --- a/mealie/core/settings/db_providers.py +++ b/mealie/core/settings/db_providers.py @@ -72,9 +72,18 @@ class PostgresProvider(AbstractDBProvider, BaseSettings): @property def db_url_public(self) -> str: - user = self.POSTGRES_USER - password = self.POSTGRES_PASSWORD - return self.db_url.replace(user, "*****", 1).replace(password, "*****", 1) + if self.POSTGRES_URL_OVERRIDE: + return "Postgres Url Overridden" + + return str( + PostgresDsn.build( + scheme="postgresql", + username="******", + password="******", + host=f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}", + path=f"{self.POSTGRES_DB or ''}", + ) + ) def db_provider_factory(provider_name: str, data_dir: Path, env_file: Path, env_encoding="utf-8") -> AbstractDBProvider: