Skip to content

Commit d3d9867

Browse files
committed
Add percent encoding of user passwords for postgresql connection
1 parent 450073e commit d3d9867

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cosmotech/coal/utils/postgresql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pyarrow import Table
1010
import pyarrow as pa
1111
from typing import Optional
12+
from urllib.parse import quote
1213
from cosmotech.coal.utils.logger import LOGGER
1314

1415

@@ -18,9 +19,12 @@ def generate_postgresql_full_uri(
1819
postgres_db: str,
1920
postgres_user: str,
2021
postgres_password: str, ) -> str:
22+
# Check if password needs percent encoding (contains special characters)
23+
# We don't log anything about the password for security
24+
encoded_password = quote(postgres_password, safe='')
2125
return ('postgresql://' +
2226
f'{postgres_user}'
23-
f':{postgres_password}'
27+
f':{encoded_password}'
2428
f'@{postgres_host}'
2529
f':{postgres_port}'
2630
f'/{postgres_db}')

0 commit comments

Comments
 (0)