4

In vcl_recv I'm trying to send a 403 to requests that contain the following characters in the url: ",',<,>,(, and )

if(req.url ~ "[\'\<\>()].*\.html" ) {
  return (synth(403, "Forbidden"));
}

everything works except the double quote " I tried regex like:

"[\"\'\<\>()].*\.html"
"[\\"\'\<\>()].*\.html"
"[%22\'\<\>()].*\.html"
"[x22\'\<\>()].*\.html"

All of them do not compile with "varnishd -C -f default.vcl" I'm currently on varnish-4.1.1 Does anyone know how to escape the " correctly?

2 Answers2

7

How about:

if (req.url ~ "[\x27<>()\x22]") {
    return (synth(403, "Forbidden"));
}

Regex test

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35
2

%22 will give you a double quote within your quoted string in Varnish VCL

Vinnie James
  • 5,763
  • 6
  • 43
  • 52
  • Take into account that Fastly VCL has many custom extensions. Percent-escaping is one of those extensions, see https://www.fastly.com/blog/unicode-in-vcl – Martijn Pieters Jun 21 '21 at 20:05