Jetpack Sitemaps: wrap post column names in backticks to handle SQL reserved words#48569
Jetpack Sitemaps: wrap post column names in backticks to handle SQL reserved words#48569
Conversation
…served words When a site has a custom column on wp_posts that matches a SQL reserved word (e.g. `order`), the sitemap query would fail with a SQL syntax error. Wrap each column name in backticks in get_sanitized_post_columns() so reserved keywords are treated as identifiers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so: 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
Problem
When a site has a custom column on
wp_postswhose name matches a SQL reserved word (e.g.order), the sitemap generation query fails with a SQL syntax error. This was reported as a conflict with the Solid Backups Legacy plugin causing backups to fail.Root Cause
Jetpack_Sitemap_Librarian::get_sanitized_post_columns()fetches all columns fromwp_postsand interpolates them into aSELECTstatement without quoting:If any column name is a SQL reserved keyword, the query becomes syntactically invalid.
Fix
Wrap each column name in backtick quotes so MySQL/MariaDB treats them as identifiers regardless of whether they are reserved words:
Testing
order(or another SQL reserved word) towp_posts./sitemap.xml).References
Linear: TSTAISB-56