Currently we have the following typecasting in the WP_Query
class (see here):
$q['posts_per_page'] = (int) $q['posts_per_page'];
if ( $q['posts_per_page'] < -1 )
$q['posts_per_page'] = abs($q['posts_per_page']);
elseif ( $q['posts_per_page'] == 0 )
$q['posts_per_page'] = 1;
and here:
if ( isset($q['page']) ) {
$q['page'] = trim($q['page'], "https://wordpress.stackexchange.com/");
$q['page'] = absint($q['page']);
}
Instead of running the query for every user input, hoping the core will handle it somewhere, validate it beforehand and only run the query if it’s of correct type and range. You could check for a positive integer here and have a max allowed value, e.g. 100, because you don’t want to allow e.g. 9999999 that could seriously slow down the whole site.
Related Posts:
- How to redirect all HTTP requests to HTTPS
- What’s the best approach for generating a new API key?
- Simplest two-way encryption using PHP
- How does the SQL injection from the “Bobby Tables” XKCD comic work?
- how fix “this certificate cannot be verified up to a trusted certification authority”
- How can bcrypt have built-in salts?
- Getting a List of Currently Available Roles on a WordPress Site?
- What’s the easiest way to stop WP from ever logging me out
- Prevent access or auto-delete readme.html, license.txt, wp-config-sample.php
- How safe / sanitized is wp_insert_posts()?
- From a security standpoint, should bloginfo() or get_bloginfo() be escaped?
- Why are passwords exportable as plain text in WordPress?
- What’s the difference between esc_* functions?
- How to set up fail2ban with WordFence?
- Is there a way to force ssl on certain pages
- What is the purpose of having a token in cookies?
- How to remove “Connection Information” requirement on localhost install of WP on MACOSX
- How is password strength calculated?
- Regular security checks – what steps should be included?
- What are the pros and cons of using a custom front-end to retrieve content from a WordPress back-end
- WordPress “Site Health Status” trust it or myself for its security advice?
- Do Cookies Need to be Sanatized Before Being Saved?
- Is WP vulnerable when updating plugins or themes?
- Disable external access to REST API Endpoint
- What is the wp-includes/certificates/ca-bundle.crt used for?
- Do you need to escape hard coded plain text?
- Encrypt emails?
- Garbage in beginning of wp-config.php – was this WP installation compromised?
- WordPress salts set in config and database
- Disallow file edit not preventing plugin install
- How to secure WordPress XMLRPC?
- What is the relationship between cURL, WordPress and cacert.pem?
- How can I find security hole in my wordpress site?
- Does WP show me if I’m logged in from multiple locations?
- Is it necessary to use esc_url with template tags such as get_permalink?
- How to prevent bot or someone to modify any file automatically?
- HTTP Security Headers in wp-config
- WordPress Malware Problem help! [duplicate]
- Staging Site: Made Public – Security Questions
- Best Way to Enable Two Step Authentication
- Restrictive File Permissions
- Why are xmlrpc.php and wp-cron.php being called so often?
- Using esc_html with HTML purifier and CSSTidy: Overkill?
- wordfence scan warning on W3 Total Cache [closed]
- Securing a multi-user permission structure
- Is default functions like update_post_meta safe to use user inputs?
- No option “I would like my site to be private, visible only to users I choose” in Privacy Settings
- wp-config.php modified?
- Securing wp-config leads to sensitive information leak on wp-settings
- Suspicious Files
- What’s the point of forbidding access to wp-config.php?
- How to save iframe tag into a post?
- wp-json and what data does it give away?
- Is is necessary to use security plugin for wordpress? [closed]
- neccessary?
- my wordpress website is suspended [closed]
- Is wp_kses the right approach in sanitizing this string?
- iTheme Security always lockout my account [closed]
- Is it sensible to worry about sanitizing admin input in plugin custom CSS?
- Renaming install.php for security?
- WordPress Front end Form – Enable to Submit PHP Codes
- Is it safe use wp_editor in public contact form
- Which Versions of WordPress Ship with the Patched TimThumb?
- Use global variables or function that returns said variables for site-wide private-ish WP settings?
- How safe is current_user_can()?
- Is it safe to give wordpress directories ownership to www-data?
- Use Google authentication for pages within a website [closed]
- Do we need to escape data that we receive from theme options?
- Why does WordPress change a file’s permissions?
- Side effects of disallowing *.php requests in production environment?
- should I escape a literal url added in functions.php
- Outgoing new connection to linked Websites – why?
- My Site keeps crashing due to the wp-confg file being deleted
- Someone keeps changing my SITEURL (mysql injection or xss?) [closed]
- Moving wp-config.php outside root folder where we have multiple wordpress websites for enhanced security [duplicate]
- Replace domain in database
- What highest security brake with wordpress and static files?
- Spam in WordPress root folder
- Has anyone developed a anti-spam plugin to simply allow users to BLOCK whatever they wish to, but one that will also go easy on IP addresses?
- HSTS header not being added correctly
- how to protect wordpress content from crawler
- Can WordPress admin user + database credentials be used to gain Cpanel or FTP access?
- Should I worry about SQL injection when using REST API?
- Links to root domain from search engines don’t work, but direct links and links from other referrers do
- How can I backup my site if it gets hacked?
- Cannot access wp admin of WordPress website (security plugin issue) [closed]
- Why are the latest visits to my website originating from my own website?
- Secure Multiple WordPress Installations on shared hosting
- How do I hide WordPress users from security scanning?
- Background Updates Not Happening
- wp-config.php file and code injection
- FORCE_SSL_ADMIN affecting subdomains
- What is the best security $_POST method?
- Is WordPress ready for GDPR compliance? [closed]
- Should WordPress Add Options to Enhance Security or Leave it to plugin developers? [closed]
- Bank account number and Sort Code in a form [closed]
- Move data from wp-config to another file
- Heartbleed: What is it and what are options to mitigate it?
- OpenVPN vs. IPsec – Pros and cons, what to use?
- How to test if my server is vulnerable to the ShellShock bug?