Skip to content

Commit e10e9e0

Browse files
Log input in hex format for SQLi detection
1 parent 91fbf35 commit e10e9e0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/operators/detect_sqli.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
#include "src/operators/operator.h"
2323
#include "src/operators/libinjection_utils.h"
2424
#include "src/operators/libinjection_adapter.h"
25+
#include "src/utils/string.h"
2526
#include "libinjection/src/libinjection_error.h"
2627

2728
namespace modsecurity::operators {
2829

2930
bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
3031
const std::string& input, RuleMessage &ruleMessage) {
32+
const std::string loggable_input =
33+
utils::string::limitTo(80, utils::string::toHexIfNeeded(input));
3134

3235
std::array<char, 8> fingerprint{};
3336

@@ -44,7 +47,7 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
4447

4548
ms_dbg_a(t, 4,
4649
std::string("detected SQLi using libinjection with fingerprint '")
47-
+ fingerprint.data() + "' at: '" + input + "'");
50+
+ fingerprint.data() + "' at: '" + loggable_input + "'");
4851

4952
if (rule != nullptr && rule->hasCaptureAction()) {
5053
t->m_collections.m_tx_collection->storeOrUpdateFirst(
@@ -61,7 +64,7 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
6164
std::string("libinjection parser error during SQLi analysis (")
6265
+ libinjectionResultToString(sqli_result)
6366
+ "); treating as match (fail-safe). Input: '"
64-
+ input + "'");
67+
+ loggable_input + "'");
6568

6669
if (rule != nullptr && rule->hasCaptureAction()) {
6770
t->m_collections.m_tx_collection->storeOrUpdateFirst(
@@ -79,7 +82,7 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
7982
case LIBINJECTION_RESULT_FALSE:
8083
ms_dbg_a(t, 9,
8184
std::string("libinjection was not able to find any SQLi in: ")
82-
+ input);
85+
+ loggable_input);
8386
break;
8487
}
8588

0 commit comments

Comments
 (0)