From 9e16dd4c3fa1e6f96d1f39c0731ca23f2ddb379b Mon Sep 17 00:00:00 2001 From: Philippe Date: Tue, 7 Jul 2020 19:37:46 +0200 Subject: [PATCH 1/3] Add debug to DataDome integration --- .../datadome_integration.json | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/etc/fastly_edge_modules/datadome_integration.json b/etc/fastly_edge_modules/datadome_integration.json index 1f6bb0a7..899c2897 100644 --- a/etc/fastly_edge_modules/datadome_integration.json +++ b/etc/fastly_edge_modules/datadome_integration.json @@ -37,6 +37,22 @@ "description": "How long to wait between bytes in milliseconds.", "default": "100", "required": true + }, { + "label": "Debug mode", + "name": "datadome_debug", + "type": "boolean", + "description": "If debug mode is enabled, faslty service id and logging endpoint must me specified", + "default": "0" + }, { + "label": "Fastly service id", + "name": "fastly_service_id", + "type": "string", + "description": "Fastly service id to use the logging system" + }, { + "label": "Logging endpoint", + "name": "logging_endpoint", + "type": "string", + "description": "Service to stream the logs" } ], "test": { @@ -63,7 +79,7 @@ "type": "deliver" }, { - "template": "# Configure the regular expression below to match URLs that\n# should be checked by DataDome\nif (fastly.ff.visits_this_service == 0 \u0026\u0026 req.restarts == 0 \u0026\u0026 !(req.url.path ~ \"{{datadome_exclusion_ext}}\" \u0026\u0026 (req.method == \"GET\" || req.method == \"HEAD\"))) {\n\n set req.backend = datadome;\n # Configure the string below to include your DataDome API key\n set req.http.x-datadome-params:method = urlencode(req.method);\n set req.http.x-datadome-params:postparamlen = urlencode(req.http.content-length);\n set req.method = \"GET\";\n return (pass);\n} else {\n if (req.http.x-datadome-params:method) {\n set req.method = urldecode(req.http.x-datadome-params:method);\n # After a restart, clustering is disabled. This re-enables it.\n set req.http.fastly-force-shield = \"1\";\n }\n unset req.http.x-datadome-params;\n}\n\n# we\u0027re using the first restart for datadome, update a part of fastly code\n# we can\u0027t replace whole macros because we haven\u0027t got any idea about backends\nif (req.restarts == 1) {\n if (!req.http.x-timer) {\n set req.http.x-timer = \"S\" time.start.sec \".\" time.start.usec_frac;\n }\n set req.http.x-timer = req.http.x-timer \",VS0\";\n}\n\nset var.fastly_req_do_shield = (req.restarts \u003c= 1);", + "template": "# Configure the regular expression below to match URLs that\n# should be checked by DataDome\nif (fastly.ff.visits_this_service == 0 && req.restarts == 0 && !(req.url.path ~ \"(?i)\\.(avi|flv|mka|mkv|mov|mp4|mpeg|mpg|mp3|flac|ogg|ogm|opus|wav|webm|webp|bmp|gif|ico|jpeg|jpg|png|svg|svgz|swf|eot|otf|ttf|woff|woff2|css|less|js)$\" && (req.method == \"GET\" || req.method == \"HEAD\"))) {\n\n set req.backend = datadome;\n # Configure the string below to include your DataDome API key\n set req.http.x-datadome-params:method = urlencode(req.method);\n set req.http.x-datadome-params:postparamlen = urlencode(req.http.content-length);\n set req.method = \"GET\";\n{{#if datadome_debug }}\n ## Debug DataDome\n log {\"syslog {{fastly_service_id}} {{logging_endpoint}} :: \"} \n {\" timestamp=\"} now \n {\" client_ip=\"} req.http.Fastly-Client-IP\n {\" request=\"} req.method\n {\" host=\"} req.http.host\n {\" url=\"} req.url\n {\" request_referer=\"} req.http.Referer\n {\" request_user_agent=\"} req.http.User-Agent\n {\" request_accept_language=\"} req.http.Accept-Language\n {\" request_accept_charset=\"} req.http.Accept-Charset\n {\" contentLength=\"} req.http.Content-Length\n {\" restarts=\"} req.restarts \n {\" DataDomeDebug=\"} \"To_DataDome\"\n {\" fastlyFF=\"} fastly.ff.visits_this_service;\n ## \n{{/if}}\n return (pass);\n} else {\n if (req.http.x-datadome-params:method) {\n set req.method = urldecode(req.http.x-datadome-params:method);\n # After a restart, clustering is disabled. This re-enables it.\n set req.http.fastly-force-shield = \"1\";\n }\n unset req.http.x-datadome-params;\n{{#if datadome_debug}} \n ## Debug DataDome\n log {\"syslog {{fastly_service_id}} {{logging_endpoint}} :: \"} \n {\" timestamp=\"} now \n {\" client_ip=\"} req.http.Fastly-Client-IP\n {\" request=\"} req.method\n {\" host=\"} req.http.host\n {\" url=\"} req.url\n {\" request_referer=\"} req.http.Referer\n {\" request_user_agent=\"} req.http.User-Agent\n {\" request_accept_language=\"} req.http.Accept-Language\n {\" request_accept_charset=\"} req.http.Accept-Charset\n {\" contentLength=\"} req.http.Content-Length\n {\" restarts=\"} req.restarts \n {\" DataDomeDebug=\"} \"Bypass_DataDome\"\n {\" fastlyFF=\"} fastly.ff.visits_this_service;\n ##{{/if}} \n}\n\n\n\n# we're using the first restart for datadome, update a part of fastly code\n# we can't replace whole macros because we haven't got any idea about backends\nif (req.restarts == 1) {\n if (!req.http.x-timer) {\n set req.http.x-timer = \"S\" time.start.sec \".\" time.start.usec_frac;\n }\n set req.http.x-timer = req.http.x-timer \",VS0\";\n}\n\nset var.fastly_req_do_shield = (req.restarts <= 1);", "type": "recv" }, { @@ -75,5 +91,5 @@ "type": "pass" } ], - "version": "2.8" + "version": "2.9" } From d179f5b8ca0fb7251634f09183cddb205f7c1b86 Mon Sep 17 00:00:00 2001 From: Philippe Date: Tue, 7 Jul 2020 20:54:20 +0200 Subject: [PATCH 2/3] Fix typo --- etc/fastly_edge_modules/datadome_integration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/fastly_edge_modules/datadome_integration.json b/etc/fastly_edge_modules/datadome_integration.json index 899c2897..c46cb076 100644 --- a/etc/fastly_edge_modules/datadome_integration.json +++ b/etc/fastly_edge_modules/datadome_integration.json @@ -47,7 +47,7 @@ "label": "Fastly service id", "name": "fastly_service_id", "type": "string", - "description": "Fastly service id to use the logging system" + "description": "Fastly service id to use with the logging system" }, { "label": "Logging endpoint", "name": "logging_endpoint", From 9fc8182e05f62e21c0a8118916e9ecba5382128f Mon Sep 17 00:00:00 2001 From: Philippe Date: Wed, 8 Jul 2020 16:49:58 +0200 Subject: [PATCH 3/3] Remove fastly service id and fix log format --- etc/fastly_edge_modules/datadome_integration.json | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/etc/fastly_edge_modules/datadome_integration.json b/etc/fastly_edge_modules/datadome_integration.json index c46cb076..18aae37c 100644 --- a/etc/fastly_edge_modules/datadome_integration.json +++ b/etc/fastly_edge_modules/datadome_integration.json @@ -37,17 +37,6 @@ "description": "How long to wait between bytes in milliseconds.", "default": "100", "required": true - }, { - "label": "Debug mode", - "name": "datadome_debug", - "type": "boolean", - "description": "If debug mode is enabled, faslty service id and logging endpoint must me specified", - "default": "0" - }, { - "label": "Fastly service id", - "name": "fastly_service_id", - "type": "string", - "description": "Fastly service id to use with the logging system" }, { "label": "Logging endpoint", "name": "logging_endpoint", @@ -79,7 +68,7 @@ "type": "deliver" }, { - "template": "# Configure the regular expression below to match URLs that\n# should be checked by DataDome\nif (fastly.ff.visits_this_service == 0 && req.restarts == 0 && !(req.url.path ~ \"(?i)\\.(avi|flv|mka|mkv|mov|mp4|mpeg|mpg|mp3|flac|ogg|ogm|opus|wav|webm|webp|bmp|gif|ico|jpeg|jpg|png|svg|svgz|swf|eot|otf|ttf|woff|woff2|css|less|js)$\" && (req.method == \"GET\" || req.method == \"HEAD\"))) {\n\n set req.backend = datadome;\n # Configure the string below to include your DataDome API key\n set req.http.x-datadome-params:method = urlencode(req.method);\n set req.http.x-datadome-params:postparamlen = urlencode(req.http.content-length);\n set req.method = \"GET\";\n{{#if datadome_debug }}\n ## Debug DataDome\n log {\"syslog {{fastly_service_id}} {{logging_endpoint}} :: \"} \n {\" timestamp=\"} now \n {\" client_ip=\"} req.http.Fastly-Client-IP\n {\" request=\"} req.method\n {\" host=\"} req.http.host\n {\" url=\"} req.url\n {\" request_referer=\"} req.http.Referer\n {\" request_user_agent=\"} req.http.User-Agent\n {\" request_accept_language=\"} req.http.Accept-Language\n {\" request_accept_charset=\"} req.http.Accept-Charset\n {\" contentLength=\"} req.http.Content-Length\n {\" restarts=\"} req.restarts \n {\" DataDomeDebug=\"} \"To_DataDome\"\n {\" fastlyFF=\"} fastly.ff.visits_this_service;\n ## \n{{/if}}\n return (pass);\n} else {\n if (req.http.x-datadome-params:method) {\n set req.method = urldecode(req.http.x-datadome-params:method);\n # After a restart, clustering is disabled. This re-enables it.\n set req.http.fastly-force-shield = \"1\";\n }\n unset req.http.x-datadome-params;\n{{#if datadome_debug}} \n ## Debug DataDome\n log {\"syslog {{fastly_service_id}} {{logging_endpoint}} :: \"} \n {\" timestamp=\"} now \n {\" client_ip=\"} req.http.Fastly-Client-IP\n {\" request=\"} req.method\n {\" host=\"} req.http.host\n {\" url=\"} req.url\n {\" request_referer=\"} req.http.Referer\n {\" request_user_agent=\"} req.http.User-Agent\n {\" request_accept_language=\"} req.http.Accept-Language\n {\" request_accept_charset=\"} req.http.Accept-Charset\n {\" contentLength=\"} req.http.Content-Length\n {\" restarts=\"} req.restarts \n {\" DataDomeDebug=\"} \"Bypass_DataDome\"\n {\" fastlyFF=\"} fastly.ff.visits_this_service;\n ##{{/if}} \n}\n\n\n\n# we're using the first restart for datadome, update a part of fastly code\n# we can't replace whole macros because we haven't got any idea about backends\nif (req.restarts == 1) {\n if (!req.http.x-timer) {\n set req.http.x-timer = \"S\" time.start.sec \".\" time.start.usec_frac;\n }\n set req.http.x-timer = req.http.x-timer \",VS0\";\n}\n\nset var.fastly_req_do_shield = (req.restarts <= 1);", + "template": "# Configure the regular expression below to match URLs that\n# should be checked by DataDome\nif (fastly.ff.visits_this_service == 0 && req.restarts == 0 && !(req.url.path ~ \"(?i)\\.(avi|flv|mka|mkv|mov|mp4|mpeg|mpg|mp3|flac|ogg|ogm|opus|wav|webm|webp|bmp|gif|ico|jpeg|jpg|png|svg|svgz|swf|eot|otf|ttf|woff|woff2|css|less|js)$\" && (req.method == \"GET\" || req.method == \"HEAD\"))) {\n\n set req.backend = datadome;\n # Configure the string below to include your DataDome API key\n set req.http.x-datadome-params:method = urlencode(req.method);\n set req.http.x-datadome-params:postparamlen = urlencode(req.http.content-length);\n set req.method = \"GET\";\n {{#if logging_endpoint}}\n ## Debug DataDome\n log {\"syslog \"} req.service_id {\" {{logging_endpoint}} :: \"} \n \" timestamp=%22\" now\n \"%22 client_ip=\" req.http.Fastly-Client-IP\n \" request=\" req.method \n \" host=\" req.http.host \n \" url=%22\" cstr_escape(req.url)\n \"%22 request_referer=%22\" cstr_escape(req.http.Referer)\n \"%22 request_user_agent=%22\" cstr_escape(req.http.User-Agent)\n \"%22 request_accept_language=%22\" cstr_escape(req.http.Accept-Language)\n \"%22 request_accept_charset=%22\" cstr_escape(req.http.Accept-Charset) \n \"%22 contentLength=\" req.http.Content-Length \n \" restarts=\" req.restarts \n \" DataDomeDebug=\" \"To_DataDome\"\n \" fastlyFF=\" fastly.ff.visits_this_service;\n ## \n {{/if}}\n return (pass);\n} else {\n if (req.http.x-datadome-params:method) {\n set req.method = urldecode(req.http.x-datadome-params:method);\n # After a restart, clustering is disabled. This re-enables it.\n set req.http.fastly-force-shield = \"1\";\n }\n unset req.http.x-datadome-params;\n {{#if logging_endpoint}}\n ## Debug DataDome\n log {\"syslog \"} req.service_id {\" {{logging_endpoint}} :: \"} \n \" timestamp=%22\" now\n \"%22 client_ip=\" req.http.Fastly-Client-IP\n \" request=\" req.method \n \" host=\" req.http.host \n \" url=%22\" cstr_escape(req.url)\n \"%22 request_referer=%22\" cstr_escape(req.http.Referer)\n \"%22 request_user_agent=%22\" cstr_escape(req.http.User-Agent)\n \"%22 request_accept_language=%22\" cstr_escape(req.http.Accept-Language)\n \"%22 request_accept_charset=%22\" cstr_escape(req.http.Accept-Charset) \n \"%22 contentLength=\" req.http.Content-Length \n \" restarts=\" req.restarts \n \" DataDomeDebug=\" \"Bypass_DataDome\"\n \" fastlyFF=\" fastly.ff.visits_this_service;\n ## \n {{/if}}\n}\n\n# we're using the first restart for datadome, update a part of fastly code\n# we can't replace whole macros because we haven't got any idea about backends\nif (req.restarts == 1) {\n if (!req.http.x-timer) {\n set req.http.x-timer = \"S\" time.start.sec \".\" time.start.usec_frac;\n }\n set req.http.x-timer = req.http.x-timer \",VS0\";\n}\n\nset var.fastly_req_do_shield = (req.restarts <= 1);", "type": "recv" }, {