sigsci_config.vcl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. backend F_sigsci_waf {
  2. .always_use_host_header = true;
  3. .between_bytes_timeout = 60s; # real timeouts are in waf
  4. .connect_timeout = 1s;
  5. .dynamic = true;
  6. .first_byte_timeout = 600s; # real timeouts are in waf
  7. .host = "${host}";
  8. .host_header = "${host}";
  9. .max_connections = 200;
  10. .port = "443";
  11. .share_key = "${shared_key}";
  12. .ssl = true;
  13. .ssl_cert_hostname = "${host}";
  14. .ssl_check_cert = always;
  15. .ssl_sni_hostname = "${host}";
  16. .probe = {
  17. .dummy = false; # this is a real healthcheck for fail open
  18. .initial = 1;
  19. .interval = 12s;
  20. .request = "HEAD / HTTP/1.1" "Host: ${host}" "Connection: close" "x-sigsci-backend: health check" "x-sigsci-host: host health check";
  21. .expected_response = 200;
  22. .threshold = 1;
  23. .timeout = 2s;
  24. .window = 5;
  25. }
  26. }
  27. sub edge_security {
  28. if (!req.backend.is_origin) {
  29. return;
  30. }
  31. if (!backend.F_sigsci_waf.healthy) {
  32. set bereq.http.x-sigsci-no-inspection = "unhealthy_waf";
  33. }
  34. # if the Enabled key is absent then default to Enabled=0%
  35. if (bereq.http.x-sigsci-no-inspection || !randombool(std.atoi(table.lookup(Edge_Security, "Enabled", "0")), 100)) {
  36. unset bereq.http.x-sigsci-no-inspection;
  37. unset bereq.http.x-sigsci-requestid;
  38. unset bereq.http.x-sigsci-tlscipher;
  39. unset bereq.http.x-sigsci-tlsprotocol;
  40. unset bereq.http.x-sigsci-bot-data;
  41. return;
  42. }
  43. if (!waf.executed) {
  44. set bereq.http.x-sigsci-backend = regsub(req.backend, "^[a-zA-Z0-9]+--(?:F_)?", "");
  45. set bereq.http.x-sigsci-host = bereq.http.host;
  46. set bereq.http.x-sigsci-scheme = req.protocol;
  47. if (!bereq.http.x-sigsci-ip-address) {
  48. set bereq.http.x-sigsci-ip-address = req.http.fastly-client-ip;
  49. }
  50. set bereq.http.x-sigsci-protocol = req.proto;
  51. set bereq.http.x-sigsci-serviceid = req.service_id;
  52. set bereq.http.x-sigsci-edgemodule = "vcl 1.11.1";
  53. set req.backend = F_sigsci_waf;
  54. set waf.executed = true;
  55. }
  56. }
  57. sub vcl_recv {
  58. if (req.restarts == 0) {
  59. if (fastly.ff.visits_this_service == 0) {
  60. set req.http.fastly-client-ip = client.ip;
  61. set req.http.x-sigsci-tlscipher = tls.client.cipher;
  62. set req.http.x-sigsci-tlsprotocol = tls.client.protocol;
  63. set req.http.x-sigsci-bot-data = {"{"}
  64. {""a":"} client.as.number {","}
  65. {""c":""} tls.client.ciphers_list {"","}
  66. {""e":""} tls.client.tlsexts_list {"","}
  67. {""h":""} fastly_info.h2.fingerprint {"","}
  68. {""j":""} tls.client.ja3_md5 {"""}
  69. {"}"};
  70. }
  71. unset req.http.x-sigsci-ip-address;
  72. unset req.http.x-sigsci-no-inspection;
  73. set req.http.x-sigsci-requestid = uuid.version4();
  74. }
  75. }