2 ms·
To construct dynamic sql queries to have to string concatenate at least some parts, . User data should of course be passed via prepared statements.
by Yokohiii 2mo ago
To construct dynamic sql queries to have to string concatenate at least some parts, .
User data should of course be passed via prepared statements.
- formerly_proven 2mo agoNot user code, no. Someone eventually has to, but virtually every ORM under the sun allows you to construct dynamic queries without having to concatenate strings yourself or resort to string interpolation.
- winstonwinston 2mo agoQuick search shows this in Wordpress: > WordPress database access abstraction class. class wpdb {} So this is some sort of ORM provided. $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_id = 1", OBJECT ); > Some of the methods in this class take an SQL statement as input. All untrusted values in an SQL statement must be escaped to prevent SQL injection attacks. Some methods will escape SQL for you; others will not. Check the documentation to be sure before you use any method in this class. For more on SQL escaping in WordPress, see the section entitled Protect Queries Against SQL Injection Attacks below. It does not however prevent $wpdb users from NOT binding query parameters, which leads to this vulnerability.
- codedokode 2mo agoIt seems that wpdb doesn't support placeholders for comma-separated lists, like in "WHERE id IN (?)". So the developers have to fall back to string concatenation.
- codedokode 2mo agoOne usually uses "query builder" pattern for that. Also, regarding placeholders, historically many DB and frameworks do not support passing lists for a value in a placeholder (like "WHERE id IN(?)") so users of such software fall back to string concatenation.
- Yokohiii 2mo agoORMs and query builders ARE concatenating strings.
- codedokode 2mo agoBut in a safe manner.
- Yokohiii 2mo agoYou can do that too.