You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 2025-05-16 - [Medium] Fix LIKE clause wildcard injection
2
+
**Vulnerability:** A LIKE clause wildcard injection vulnerability in the Pokemon API. In `src/app/repositories/pokemon_repository.py`, the `find_all` method took a `name` filter string which was used in a `LIKE` SQL query (`ilike()`). While it escaped `%` and `_`, it failed to escape the literal escape character `\` itself. This allowed user input to escape the database's wildcard characters in unintended ways, leading to an incorrect or malicious query executing.
3
+
**Learning:** Even when manually escaping string tokens before passing them into a `LIKE` statement, it is critical to also escape the specific escape character itself (typically `\`) otherwise the user can neutralize the query's wildcards.
4
+
**Prevention:** When doing manual substring search escaping for database queries in python (e.g., `ilike(f"%{escaped}%")`), ensure you escape the backslash *first* before escaping other wildcard characters. For example: `escaped = input.replace("\\", "\\\\").replace("%", r"\%").replace("_", r"\_")`.
0 commit comments