Skip to content

Commit 102275f

Browse files
committed
Encode possible binary characters in headers; add more tests
1 parent 85384fe commit 102275f

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

src/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ std::string Transaction::toJSON(int parts) {
16221622

16231623
m_variableRequestHeaders.resolve(&l);
16241624
for (auto &h : l) {
1625-
LOGFY_ADD(h->getKey().c_str(), h->getValue());
1625+
LOGFY_ADD(utils::string::toHexIfNeeded(h->getKey().c_str()).c_str(), utils::string::toHexIfNeeded(h->getValue()));
16261626
delete h;
16271627
}
16281628

test/test-cases/regression/auditlog.json

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@
541541
"enabled": 1,
542542
"version_min": 300000,
543543
"version_max": 0,
544-
"title": "auditlog : Binary char from input",
544+
"title": "auditlog : Binary char from input, check message",
545545
"client": {
546546
"ip": "200.249.12.31",
547547
"port": 2313
@@ -595,5 +595,132 @@
595595
"SecAuditLogType Serial",
596596
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
597597
]
598+
},
599+
{
600+
"enabled": 1,
601+
"version_min": 300000,
602+
"version_max": 0,
603+
"title": "auditlog : Binary char from input, check body",
604+
"client": {
605+
"ip": "200.249.12.31",
606+
"port": 2313
607+
},
608+
"server": {
609+
"ip": "200.249.12.31",
610+
"port": 80
611+
},
612+
"request": {
613+
"headers": {
614+
"Host": "www.modsecurity.org",
615+
"User-Agent": "Mozilla\/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko\/20091102 Firefox\/3.5.5 (.NET CLR 3.5.30729)",
616+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
617+
"Accept-Language": "en-us,en;q=0.5",
618+
"Accept-Encoding": "gzip,deflate",
619+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
620+
"Keep-Alive": "300",
621+
"Connection": "keep-alive",
622+
"Pragma": "no-cache",
623+
"Cache-Control": "no-cache",
624+
"Content-Type": "application/x-www-form-urlencoded",
625+
"Content-Length": "3"
626+
},
627+
"uri": "\/?attack=true",
628+
"method": "POST",
629+
"http_version": 1.1,
630+
"body": [
631+
"\u00ad=\u00ad"
632+
]
633+
},
634+
"response": {
635+
"headers": {
636+
"Content-Type": "plain\/text\n\r"
637+
},
638+
"body": [
639+
"test"
640+
]
641+
},
642+
"expected": {
643+
"audit_log": "\"body\":\"\\\\\\\\xc2\\\\\\\\xad=\\\\\\\\xc2\\\\\\\\xad\\\\\\\\x0a",
644+
"debug_log": "",
645+
"error_log": "",
646+
"http_code": 403
647+
},
648+
"rules": [
649+
"SecRuleEngine On",
650+
"SecRule ARGS_NAMES \"@rx attack\" \"id:1,phase:2,deny,t:none",
651+
"SecAuditEngine RelevantOnly",
652+
"SecAuditLogParts ABCHJZ",
653+
"SecAuditLogFormat JSON",
654+
"SecAuditLogStorageDir /tmp/test",
655+
"SecAuditLog /tmp/audit_test_prefix.log",
656+
"SecAuditLogDirMode 0766",
657+
"SecAuditLogFileMode 0600",
658+
"SecAuditLogType Serial",
659+
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
660+
]
661+
},
662+
{
663+
"enabled": 1,
664+
"version_min": 300000,
665+
"version_max": 0,
666+
"title": "auditlog : Binary char from input, check header",
667+
"client": {
668+
"ip": "200.249.12.31",
669+
"port": 2313
670+
},
671+
"server": {
672+
"ip": "200.249.12.31",
673+
"port": 80
674+
},
675+
"request": {
676+
"headers": {
677+
"Host": "www.modsecurity.org",
678+
"User-Agent": "Mozilla\/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko\/20091102 Firefox\/3.5.5 (.NET CLR 3.5.30729)",
679+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
680+
"Accept-Language": "en-us,en;q=0.5",
681+
"Accept-Encoding": "gzip,deflate",
682+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
683+
"Keep-Alive": "300",
684+
"Connection": "keep-alive",
685+
"Pragma": "no-cache",
686+
"Cache-Control": "no-cache",
687+
"Content-Type": "application/x-www-form-urlencoded",
688+
"Content-Length": "3",
689+
"X-\u00ad-custom": "Some \u00ad value"
690+
},
691+
"uri": "\/?attack=true",
692+
"method": "POST",
693+
"http_version": 1.1,
694+
"body": [
695+
"\u00ad=\u00ad"
696+
]
697+
},
698+
"response": {
699+
"headers": {
700+
"Content-Type": "plain\/text\n\r"
701+
},
702+
"body": [
703+
"test"
704+
]
705+
},
706+
"expected": {
707+
"audit_log": "\"X-\\\\\\\\xc2\\\\\\\\xad-custom\":\"Some \\\\\\\\xc2\\\\\\\\xad value\"",
708+
"debug_log": "",
709+
"error_log": "",
710+
"http_code": 403
711+
},
712+
"rules": [
713+
"SecRuleEngine On",
714+
"SecRule ARGS|ARGS_NAMES \"@rx attack\" \"id:1,phase:2,deny,t:none",
715+
"SecAuditEngine RelevantOnly",
716+
"SecAuditLogParts ABHJZ",
717+
"SecAuditLogFormat JSON",
718+
"SecAuditLogStorageDir /tmp/test",
719+
"SecAuditLog /tmp/audit_test_prefix.log",
720+
"SecAuditLogDirMode 0766",
721+
"SecAuditLogFileMode 0600",
722+
"SecAuditLogType Serial",
723+
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
724+
]
598725
}
599726
]

0 commit comments

Comments
 (0)