metaflow-service icon indicating copy to clipboard operation
metaflow-service copied to clipboard

fix: percent-encode forward slash in database connection string

Open wedaly opened this issue 5 months ago • 2 comments

The DB connection string used urllib.parse.quote to percent-encode the username and password. However, quote has a default kwarg safe="/" that does NOT percent-encode forward slashes. If the username or password includes a forward slash, then the resulting connection string may be rejected by the postgres client.

For example, when the password contains an unescaped forward slash, psycopg incorrectly parses the password field as a port.

>>> import psycopg2
>>> conn = "postgresql://user:abc/123@localhost:5432/db"
>>> psycopg2.connect(conn)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    psycopg2.connect(conn)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/willdaly/repos/metaflow-service/.venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: invalid integer value "abc" for connection option "port"

Fix it by percent-escaping forward slashes in all DB connection strings.

wedaly avatar Jun 10 '25 15:06 wedaly

incidentally, I discovered this while trying to use AWS RDS IAM. AWS puts forward slashes in its tokens.

wedaly avatar Jun 10 '25 15:06 wedaly

It seems that linter check failed. Can you address that so that we can merge this PR?

savingoyal avatar Jun 10 '25 15:06 savingoyal