Modify WP_QUERY class to sanitize search query input to prevent XSS injection.
-
Our site was facing XSS injection issue where we were able to inject Javascript code into the search bar, We tried using sanitizing the user input in the template code which was using
https://github.com/WordPress/wordpress-develop/blob/f0a27d908b41368b568189c48b65d873610f5e99/src/wp-includes/general-template.php#L4306-L4320
method to get the search query, but that didn’t help as it was injecting the code first then escaping the the string. So is it possible to modifyWP_QUERY
class such that before making search query we can strip search query to include only alpha numeric value preventing injection of any type of code.We tried applying
esc_attr
on$q['s']
and it helped with XSS injection, But since its changes to core wordpress its not suggested, Is there any better way to do this, Or something where wordpress can be modified to fix these permanently.The page I need help with: [log in to see the link]
- The topic ‘Modify WP_QUERY class to sanitize search query input to prevent XSS injection.’ is closed to new replies.