Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape error.log fields ('data', etc.) value #2854

Merged
merged 6 commits into from
Jan 18, 2023

Conversation

airween
Copy link
Member

@airween airween commented Dec 30, 2022

This patch escapes the log's data field, similar as mod_security2 does.

The aim is to help to process the content for log parsers.

@airween
Copy link
Member Author

airween commented Jan 6, 2023

May be we should add the new function here too:

--- a/src/operators/operator.cc
+++ b/src/operators/operator.cc
@@ -112,17 +112,17 @@ std::string Operator::resolveMatchMessage(Transaction *t,
         if (m_couldContainsMacro == false) {
             ret = "Matched \"Operator `" + m_op + "' with parameter `" +
                 utils::string::limitTo(200, m_param) +
-                "' against variable `" + key + "' (Value: `" +
-                utils::string::limitTo(100,
-                    utils::string::toHexIfNeeded(value)) + \
+                "' against variable `" + 
+                utils::string::log_escape_hex(utils::string::limitTo(100, key)) + "' (Value: `" +
+                utils::string::log_escape_hex(utils::string::limitTo(100, value)) +
                 "' )";
         } else {
             std::string p(m_string->evaluate(t));
             ret = "Matched \"Operator `" + m_op + "' with parameter `" +
                 utils::string::limitTo(200, p) +
-                "' against variable `" + key + "' (Value: `" +
-                utils::string::limitTo(100,
-                    utils::string::toHexIfNeeded(value)) +
+                "' against variable `" +
+                utils::string::log_escape_hex(utils::string::limitTo(100, key)) + "' (Value: `" +
+                utils::string::log_escape_hex(utils::string::limitTo(100, value)) +
                 "' )";
         }
     }

I didn't find any occurrence where the user input appears.

There is a similar function toHexIfNeeded(), but it does not encode ".

src/rule_message.cc Outdated Show resolved Hide resolved
src/utils/string.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@martinhsv martinhsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments both for when a new function should be called, and comments about specifics about a new function.

src/utils/string.h Outdated Show resolved Hide resolved
src/utils/string.cc Show resolved Hide resolved
src/utils/string.h Outdated Show resolved Hide resolved
@airween airween requested a review from martinhsv January 18, 2023 15:42
Copy link
Contributor

@martinhsv martinhsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good. Thanks.

@martinhsv martinhsv merged commit 860b118 into owasp-modsecurity:v3/master Jan 18, 2023
@martinhsv martinhsv changed the title Escape log field 'data' value Escape error.log fields ('data', etc.) value Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants