From 514abeb513fa64b9f9d44e91c8e4272e1772f495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ervin=20Heged=C3=BCs?= Date: Sat, 28 Jan 2023 21:48:51 +0100 Subject: [PATCH 1/3] Remove EOL chars from MULTIPART_PART_HEADER variable --- src/request_body_processor/multipart.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/request_body_processor/multipart.cc b/src/request_body_processor/multipart.cc index cfce8434..276189c3 100644 --- a/src/request_body_processor/multipart.cc +++ b/src/request_body_processor/multipart.cc @@ -935,6 +935,7 @@ int Multipart::process_part_header(std::string *error, int offset) { "Multipart: Added part header \"" + header_name \ + "\" \"" + header_value + "\"."); if (len_without_termination > 0) { + m_buf[len_without_termination] = '\0'; m_mpp->m_last_header_line.assign(m_buf); } else { m_mpp->m_last_header_line.assign(""); From 0a296af37575ad14be75d30e28b132e1bb8f7c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ervin=20Heged=C3=BCs?= Date: Sat, 28 Jan 2023 21:50:00 +0100 Subject: [PATCH 2/3] Add regression test case --- .../variable-MULTIPART_PART_HEADERS.json | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/test-cases/regression/variable-MULTIPART_PART_HEADERS.json b/test/test-cases/regression/variable-MULTIPART_PART_HEADERS.json index f2798ddb..1669589e 100644 --- a/test/test-cases/regression/variable-MULTIPART_PART_HEADERS.json +++ b/test/test-cases/regression/variable-MULTIPART_PART_HEADERS.json @@ -162,6 +162,57 @@ "SecRuleEngine On", "SecRule MULTIPART_PART_HEADERS:parm2 \"@rx content-type:.*jpeg\" \"phase:2,deny,status:403,id:500074,t:lowercase\"" ] + }, + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: MULTIPART_PART_HEADERS (check EOL)", + "client":{ + "ip":"200.249.12.31", + "port":123 + }, + "server":{ + "ip":"200.249.12.31", + "port":80 + }, + "request":{ + "headers":{ + "Host":"localhost", + "User-Agent":"curl/7.38.0", + "Accept":"*/*", + "Content-Length":"249", + "Content-Type":"multipart/form-data; boundary=-----------------------------69343412719991675451336310646", + "Expect":"100-continue" + }, + "uri":"/", + "method":"POST", + "body":[ + "-------------------------------69343412719991675451336310646", + "Content-Disposition: form-data; name=\"file\"; filename=\"New Text Document.txt\"", + "Content-Type: text/plain; charset=utf-8\r\n", + "", + "1", + "-------------------------------69343412719991675451336310646--" + ] + }, + "response":{ + "headers":{ + "Date":"Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type":"text/html" + }, + "body":[ + "no need." + ] + }, + "expected":{ + "http_code": 200 + }, + "rules":[ + "SecRuleEngine On", + "SecRule MULTIPART_PART_HEADERS \"@rx ^content-type\\s*+:\\s*+(.*)$\" \"id:922110,phase:2,deny,capture,t:none,t:lowercase,chain\"", + "SecRule TX:1 \"!@rx ^text/plain; charset=(?:iso-8859-15?|windows-1252|utf-8)$\" \"t:lowercase\"" + ] } ] From 6623c0ae29accba12d27fb6da93038c80927402c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ervin=20Heged=C3=BCs?= Date: Sun, 23 Apr 2023 17:32:26 +0200 Subject: [PATCH 3/3] Changed strip methodology to MULTIPART_PART_HEADERS --- src/request_body_processor/multipart.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/request_body_processor/multipart.cc b/src/request_body_processor/multipart.cc index df769815..78dc5d9c 100644 --- a/src/request_body_processor/multipart.cc +++ b/src/request_body_processor/multipart.cc @@ -935,8 +935,7 @@ int Multipart::process_part_header(std::string *error, int offset) { "Multipart: Added part header \"" + header_name \ + "\" \"" + header_value + "\"."); if (len_without_termination > 0) { - m_buf[len_without_termination] = '\0'; - m_mpp->m_last_header_line.assign(m_buf); + m_mpp->m_last_header_line.assign(m_buf, len_without_termination); } else { m_mpp->m_last_header_line.assign(""); }