hexnginx-location

nginx - how to match hexadecimal URL


I have an access log entry:

\x16\x03\x01\x00\x85\x01\x00\x00\x81\x03\x03f\xC5\xFD\xC4\xDCC\xBBLY\xC5D\xD6&\xD5X\x98\x82.\x02\x09$\xE1B|\xEAT\xD6\x87\xA0|\xFA?\x00\x00 \xC0/\xC00\xC0+\xC0,\xCC\xA8\xCC\xA9\xC0\x13\xC0\x09\xC0\x14\xC0

I have tried:

location ~ ^/\x16\x03\x01.*$ {
    rewrite ^ /unknown/ permanent;
}

But no luck.

What is the correct way to match a hexadecimal prefix of a URL?


Some additional one's I've tried:

# no leading slash
location ~* ^x16x03x01.*$
# escape the backslash      
location ~* ^/\\x16\\x03.*$
# just the prefix
location ~* ^/\x16\x03
# use parens
location ~* (^x16x03x01)
# no regex
location ~* (x16x03x01)
# back to case-sensitive
location ~ (x16x03x01)

Solution

  • You can use the ~* modifier for a case-insensitive match.

    So it should look something like this:

    location ~* ^/\x16\x03\x01.*$ {
        rewrite ^ /unknown/ permanent;
    }