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
2728namespace modsecurity ::operators {
2829
2930bool DetectSQLi::evaluate (Transaction *t, RuleWithActions *rule,
3031 const std::string& input, RuleMessage &ruleMessage) {
32+ #ifndef NO_LOGS
33+ const std::string loggable_input =
34+ utils::string::limitTo (80 , utils::string::toHexIfNeeded (input));
35+ #endif
3136
3237 std::array<char , 8 > fingerprint{};
3338
@@ -42,9 +47,11 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
4247 case LIBINJECTION_RESULT_TRUE:
4348 t->m_matched .emplace_back (fingerprint.data ());
4449
50+ #ifndef NO_LOGS
4551 ms_dbg_a (t, 4 ,
4652 std::string (" detected SQLi using libinjection with fingerprint '" )
47- + fingerprint.data () + " ' at: '" + input + " '" );
53+ + fingerprint.data () + " ' at: '" + loggable_input + " '" );
54+ #endif
4855
4956 if (rule != nullptr && rule->hasCaptureAction ()) {
5057 t->m_collections .m_tx_collection ->storeOrUpdateFirst (
@@ -57,11 +64,13 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
5764 break ;
5865
5966 case LIBINJECTION_RESULT_ERROR:
67+ #ifndef NO_LOGS
6068 ms_dbg_a (t, 4 ,
6169 std::string (" libinjection parser error during SQLi analysis (" )
6270 + libinjectionResultToString (sqli_result)
6371 + " ); treating as match (fail-safe). Input: '"
64- + input + " '" );
72+ + loggable_input + " '" );
73+ #endif
6574
6675 if (rule != nullptr && rule->hasCaptureAction ()) {
6776 t->m_collections .m_tx_collection ->storeOrUpdateFirst (
@@ -77,9 +86,11 @@ bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
7786 break ;
7887
7988 case LIBINJECTION_RESULT_FALSE:
89+ #ifndef NO_LOGS
8090 ms_dbg_a (t, 9 ,
8191 std::string (" libinjection was not able to find any SQLi in: " )
82- + input);
92+ + loggable_input);
93+ #endif
8394 break ;
8495 }
8596
0 commit comments