Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly escape postgres password #3424

Merged
merged 20 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9399a98
fix: properly escape special characters in postgres db url passwords
tba-code Apr 4, 2024
471251d
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 4, 2024
f50055b
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 4, 2024
218fb7d
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 5, 2024
47162c6
fix: always unquote first
tba-code Apr 5, 2024
239153a
change: add unit testing for postgress password parsing
tba-code Apr 5, 2024
ec3afdc
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 5, 2024
5684f6f
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 5, 2024
1ae45fb
fix: no longer unquote password first
tba-code Apr 5, 2024
adaae1d
fix: pg encode password test no longer broken
tba-code Apr 5, 2024
149dbc8
fix: pg password encode test string now based on POSTGRES_* variables
tba-code Apr 5, 2024
5f17d92
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 6, 2024
bdb842b
Merge branch 'mealie-recipes:mealie-next' into fix/postgres-url-parsing
tba-code Apr 7, 2024
e5126fd
remove DB_URL None error
hay-kot Apr 7, 2024
a9a7a38
unquote then requote to preserve backwards compatibility
hay-kot Apr 7, 2024
9056fc9
formatting
hay-kot Apr 7, 2024
fb1bdfe
reformat alembic file
hay-kot Apr 7, 2024
d6d6869
revert unquote/requote
hay-kot Apr 7, 2024
64ce793
Merge branch 'mealie-next' into fix/postgres-url-parsing
michael-genson Apr 7, 2024
fa21b63
Merge branch 'mealie-next' into fix/postgres-url-parsing
michael-genson Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Set DB url from config
settings = get_app_settings()
config.set_main_option("sqlalchemy.url", settings.DB_URL)
config.set_main_option("sqlalchemy.url", settings.DB_URL.replace("%", "%%"))
tba-code marked this conversation as resolved.
Show resolved Hide resolved


def run_migrations_offline():
Expand Down
14 changes: 11 additions & 3 deletions mealie/core/settings/db_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ class PostgresProvider(AbstractDBProvider, BaseSettings):
@property
def db_url(self) -> str:
if self.POSTGRES_URL_OVERRIDE:
url = PostgresDsn(url=self.POSTGRES_URL_OVERRIDE)
if not url.scheme == ("postgresql"):
url = self.POSTGRES_URL_OVERRIDE

scheme, remainder = url.split("://", 1)
if scheme != "postgresql":
raise ValueError("POSTGRES_URL_OVERRIDE scheme must be postgresql")

return str(url)
remainder = remainder.split(":", 1)[1]
password = remainder[: remainder.rfind("@")]
safe_password = urlparse.quote_plus(password)

safe_url = url.replace(password, safe_password)

return safe_url

return str(
PostgresDsn.build(
Expand Down
Loading