Help stop titles / slugs with special characters from being queried
-
The issue is, we have apache rules for placing certain URLs behind authentication. The WP feature of stripping out special characters before querying the database allows users to bypass auth rules by adding special characters in the URL.
Example: https://www.mysite.com/my-pa*ge retrieves https://www.mysite.com/my-page, even though https://www.mysite.com/my-page requires authentication.
Is there a creative solution that would allow my site to reject these requests and display a 404 instead?
I’d like to do something like this:
function block_special_chars($title) { // accept only letters, numbers, and hyphens if (preg_match("/^[A-Za-z0-9-]+$/", $title)) { return $title; } else { return "404"; } } add_filter('sanitize_title', 'block_special_chars');
I thought this would work, however the $title passed is already filtered. Is there a hook before this I can use to accomplish what I need?
- The topic ‘Help stop titles / slugs with special characters from being queried’ is closed to new replies.