CRE-2025-0030
SQLAlchemy create_engine fails when password contains special characters like @MediumImpact: 6/10Mitigation: 2/10
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.
Mitigation
- URL-encode special characters in usernames and passwords when constructing the connection string. - For example, replace `@` with `%40`, `:` with `%3A`, `/` with `%2F`, etc. - Alternatively, use the dictionary-style `create_engine(URL.create(...))` approach to avoid manual string encoding. - See official docs: https://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords