Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using literal-string for wpdb::prepare() #34

Closed
craigfrancis opened this issue May 17, 2022 · 1 comment
Closed

Using literal-string for wpdb::prepare() #34

craigfrancis opened this issue May 17, 2022 · 1 comment

Comments

@craigfrancis
Copy link

Both Psalm 4.8 and PHPStan 0.12.97 have the literal-string type, which can be used to ensure a string is defined by the developer (i.e. does not contain any user values). This is really useful and simple way to prevent SQL Injection Vulnerabilities.

I have created patches for #52506 so identifiers (table/field names) can be escaped via a new %i parameter; and #54042 makes it easier/safer to do WHERE id IN (%...d) style queries.

Hopefully these will be accepted for WordPress 6.1. I've had a few reviews already, and the first patch will be discussed at the next "Early Scrub" meeting (on the 19th May 2022, 18:00 UTC on the Slack #core channel.

Both of these patches will allow the $query parameter to be a literal-string, e.g.

$wpdb->prepare('SELECT * FROM %i WHERE ID IN (%...d)', $table, $ids);

While it might be worth waiting for WordPress 6.1... would it be ok to try setting @param literal-string $query on the wpdb::prepare() method?

@szepeviktor
Copy link
Member

Duplicate of #33

@szepeviktor szepeviktor marked this as a duplicate of #33 May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants