@@ -138,20 +138,19 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, const char *id,
138138 ms->m_session_collection, ms->m_user_collection,
139139 ms->m_resource_collection),
140140#ifdef WITH_LIBXML2
141- m_xml (std::make_unique<RequestBodyProcessor::XML>(this ,
142- this ->m_rules->m_requestBodyLimitAction != RulesSet::BodyLimitAction::ProcessPartialBodyLimitAction)),
141+ m_xml (std::make_unique<RequestBodyProcessor::XML>(this )),
143142#else
144143 m_xml (nullptr ),
145144#endif
146145#ifdef WITH_YAJL
147- m_json (std::make_unique<RequestBodyProcessor::JSON>(this ,
148- this ->m_rules->m_requestBodyLimitAction == RulesSet::BodyLimitAction::ProcessPartialBodyLimitAction)),
146+ m_json (std::make_unique<RequestBodyProcessor::JSON>(this )),
149147#else
150148 m_json (nullptr ),
151149#endif
152150 m_secRuleEngine (RulesSetProperties::PropertyNotSetRuleEngine),
153151 m_secXMLParseXmlIntoArgs(rules->m_secXMLParseXmlIntoArgs),
154152 m_logCbData(logCbData),
153+ m_requestBodyLimitExceeded(false ),
155154 TransactionAnchoredVariables(this ) {
156155 m_variableUrlEncodedError.set (" 0" , 0 );
157156 m_variableMscPcreError.set (" 0" , 0 );
@@ -689,27 +688,33 @@ int Transaction::processRequestBody() {
689688 std::unique_ptr<std::string> a = m_variableRequestHeaders.resolveFirst (
690689 " Content-Type" );
691690
691+ bool is_process_partial = (m_rules->m_requestBodyLimitAction
692+ == RulesSet::BodyLimitAction::ProcessPartialBodyLimitAction);
693+
692694 bool requestBodyNoFilesLimitExceeded = false ;
693695 if ((m_requestBodyType == WWWFormUrlEncoded) ||
694696 (m_requestBodyProcessor == JSONRequestBody) ||
695697 (m_requestBodyProcessor == XMLRequestBody)) {
696698 if ((m_rules->m_requestBodyNoFilesLimit .m_set )
697699 && (m_requestBody.str ().size () > m_rules->m_requestBodyNoFilesLimit .m_value )) {
698- m_variableReqbodyError.set (" 1" , 0 );
699- m_variableReqbodyErrorMsg.set (" Request body excluding files is bigger than the maximum expected." , 0 );
700- m_variableInboundDataError.set (" 1" , m_variableOffset);
701- ms_dbg (5 , " Request body excluding files is bigger than the maximum expected. Limit: " \
702- + std::to_string (m_rules->m_requestBodyNoFilesLimit .m_value ));
700+ if (!is_process_partial) {
701+ m_variableReqbodyError.set (" 1" , 0 );
702+ m_variableReqbodyErrorMsg.set (" Request body excluding files is bigger than the maximum expected." , 0 );
703+ m_variableInboundDataError.set (" 1" , m_variableOffset);
704+ ms_dbg (5 , " Request body excluding files is bigger than the maximum expected. Limit: " \
705+ + std::to_string (m_rules->m_requestBodyNoFilesLimit .m_value ));
706+ }
703707 requestBodyNoFilesLimitExceeded = true ;
704- }
708+ }
705709 }
706710
707711#ifdef WITH_LIBXML2
708712 if (m_requestBodyProcessor == XMLRequestBody) {
709713 // large size might cause issues in the parsing itself; omit if exceeded
710- if (!requestBodyNoFilesLimitExceeded) {
714+ if (!requestBodyNoFilesLimitExceeded || is_process_partial ) {
711715 std::string error;
712- if (m_xml->init () == true ) {
716+ bool require_well_formed = !(is_process_partial && m_requestBodyLimitExceeded);
717+ if (m_xml->init (require_well_formed) == true ) {
713718 m_xml->processChunk (m_requestBody.str ().c_str (),
714719 m_requestBody.str ().size (),
715720 &error);
@@ -735,12 +740,13 @@ int Transaction::processRequestBody() {
735740 if (m_requestBodyProcessor == JSONRequestBody) {
736741#endif
737742 // large size might cause issues in the parsing itself; omit if exceeded
738- if (!requestBodyNoFilesLimitExceeded) {
743+ if (!requestBodyNoFilesLimitExceeded || is_process_partial ) {
739744 std::string error;
740745 if (m_rules->m_requestBodyJsonDepthLimit .m_set ) {
741746 m_json->setMaxDepth (m_rules->m_requestBodyJsonDepthLimit .m_value );
742747 }
743- if (m_json->init () == true ) {
748+ unsigned int allow_partial_values = is_process_partial && m_requestBodyLimitExceeded;
749+ if (m_json->init (allow_partial_values) == true ) {
744750 m_json->processChunk (m_requestBody.str ().c_str (),
745751 m_requestBody.str ().size (),
746752 &error);
@@ -930,6 +936,7 @@ int Transaction::appendRequestBody(const unsigned char *buf, size_t len) {
930936
931937 if (this ->m_rules ->m_requestBodyLimit .m_value > 0
932938 && this ->m_rules ->m_requestBodyLimit .m_value < len + current_size) {
939+ m_requestBodyLimitExceeded = true ;
933940 m_variableInboundDataError.set (" 1" , m_variableOffset);
934941 ms_dbg (5 , " Request body is bigger than the maximum expected." );
935942
0 commit comments