Block users with empty user agent


(Alex Kim) #1

Hi, guys!
Please help, how to block users with empty user agent at caddy server?


(Matthew Fay) #2

One trick would be to use a rewrite to direct a request with an empty User-Agent to a path that you can then explicitly forbid.

rewrite {
  if {>User-Agent} is ""
  to /no-user-agent-forbidden
}
status 403 /no-user-agent-forbidden

This should result in an empty message body with Status 403.