escape values in LIKE statements to prevent injection of placeholders (_ or %)
While not technically a security risk, LIKE queries with lots of placeholders can result in high database load, very slow query execution and therefore are a possible vector for denial of service attacks. Further, escaping the wildcard characters in actual query values now allows to actually search for values containing these characters.
The attached patches, which have been extracted from Planio are:
- The first patch removes '%' signs from query strings used in the search test case. These did not matter until now since they just resulted in queries like
field LIKE '%%value%%', but now would be looking for a value with literal percent signs. Tests pass before and after that change.
- Patches 2-4 add
sanitize_sql_likecalls to the various places where we currrently generate sql LIKE statements. Corresponding tests are included.
- The last patch is just a cosmetic change that replaces a
.sendwith a direct call since the called method is now public.