0

I have url https://myhost.test/en/searchResult?param=<

I want to return 404 if query param have special char '<'

https://myhost.test/en/searchResult?param=test ----- Valid url

https://myhost.test/en/searchResult?param=<h1>    ----- return 404

I tried below but not working

   error_page 420 = @blockUrl;
   location ~ ^/(en)/search {
     if ($args ~* "q=<") {
        return 420;
     }
  }
 location @blockUrl{
    return 404;
 }

Could someone please help me how can block having '<' in query param.

1
  • It may be URL encoded. You could try: if ($args ~* "q=%3C") Dec 15 '20 at 17:40
1

In my tests no matter how I entered the url (encoded or not) it always is encoded in the log file.
Here are two possibilities to accomplish your requirement:

if ($args ~* (param=.*(%3C|%3E).*)) {
   return 404;
}

or

In your location block:

if ($err404) {
   return 404;
}

In the http block (not inside the server block!):

map $args $err404 {
        ~param=.*(%3C|%3E).*            1;
        default                         0;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.