Skip to content

url parsing struggle with username containing @ char #483

Closed
@victornoel

Description

@victornoel
  • asyncpg version: 0.18.3

I am using asyncpg to connect to a Azure PostgreSQL database, and Azure imposes the use of a username of the form name@db, so the full connection url looks like:

postgresql://my-user@my-db-server:my-password@my-db-server.postgres.database.azure.com:5432/some-db

When using such an url to connect with asyncpg, I get the following error:

File "/home/victor/.local/share/virtualenvs/datapipe-3ZEOKy8g/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 187, in _parse_hostlist
    hostlist_ports.append(int(hostspec_port))
ValueError: invalid literal for int() with base 10: 'my-password@my-db-server.postgres.database.azure.com:5432'

I see two problems here:

  • the password leak in the logs (even tough I'm not sure how to avoid this in a consistent manner…)
  • the fact that asyncpg incorrectly split the netloc part of the uri by splitting at the first @ intead of the last one.

The ticket is about the second problem:

  • I think it should be safe to assume that everything before the last @ in the netloc is for authentication.
  • Also by the way, it should also be safe to assume that everything after the first : in the auth part to be the password.

For the record, when using sqlalchemy + psycogs2, I have no problem using this kind of url to connect to my database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions