Skip to main content

CRE-2025-0030

SQLAlchemy create_engine fails when password contains special characters like @Medium
Impact: 6/10
Mitigation: 2/10

CRE-2025-0030View on GitHub

Description

SQLAlchemy applications using `create_engine()` may fail to connect to a database if the username or password contains special characters (e.g., `@`, `:`, `/`, `#`). These characters must be URL-encoded when included in the database connection string. Failure to encode them leads to parsing errors or incorrect credential usage.\n

Mitigation

- URL-encode special characters in usernames and passwords when constructing the connection string.\n- For example, replace `@` with `%40`, `:` with `%3A`, `/` with `%2F`, etc.\n- Alternatively, use the dictionary-style `create_engine(URL.create(...))` approach to avoid manual string encoding.\n- See official docs: https://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords\n

References