diff --git a/src/operators/validate_schema.cc b/src/operators/validate_schema.cc index d45ef5750..112696952 100644 --- a/src/operators/validate_schema.cc +++ b/src/operators/validate_schema.cc @@ -54,22 +54,21 @@ bool ValidateSchema::evaluate(Transaction *transaction, return true; } + std::string schemaErr; + xmlSchemaParserCtxtPtr parserCtx = xmlSchemaNewParserCtxt(m_resource.c_str()); if (parserCtx == NULL) { std::stringstream err; err << "XML: Failed to load Schema from file: "; err << m_resource; err << ". "; - if (m_err.empty() == false) { - err << m_err; - } ms_dbg_a(transaction, 4, err.str()); return true; } xmlSchemaSetParserErrors(parserCtx, (xmlSchemaValidityErrorFunc)error_load, - (xmlSchemaValidityWarningFunc)warn_load, &m_err); + (xmlSchemaValidityWarningFunc)warn_load, &schemaErr); xmlSchemaPtr schema = xmlSchemaParse(parserCtx); if (schema == NULL) { @@ -77,8 +76,8 @@ bool ValidateSchema::evaluate(Transaction *transaction, err << "XML: Failed to load Schema: "; err << m_resource; err << "."; - if (m_err.empty() == false) { - err << " " << m_err; + if (schemaErr.empty() == false) { + err << " " << schemaErr; } ms_dbg_a(transaction, 4, err.str()); xmlSchemaFreeParserCtxt(parserCtx); @@ -88,8 +87,8 @@ bool ValidateSchema::evaluate(Transaction *transaction, xmlSchemaValidCtxtPtr validCtx = xmlSchemaNewValidCtxt(schema); if (validCtx == NULL) { std::stringstream err("XML: Failed to create validation context."); - if (m_err.empty() == false) { - err << " " << m_err; + if (schemaErr.empty() == false) { + err << " " << schemaErr; } ms_dbg_a(transaction, 4, err.str()); xmlSchemaFree(schema); diff --git a/src/operators/validate_schema.h b/src/operators/validate_schema.h index 96cca8f25..65e450de5 100644 --- a/src/operators/validate_schema.h +++ b/src/operators/validate_schema.h @@ -100,7 +100,6 @@ class ValidateSchema : public Operator { private: std::string m_resource; - std::string m_err; #endif }; diff --git a/test/test-cases/regression/request-body-parser-xml.json b/test/test-cases/regression/request-body-parser-xml.json index cd4426c7f..45a31ac28 100644 --- a/test/test-cases/regression/request-body-parser-xml.json +++ b/test/test-cases/regression/request-body-parser-xml.json @@ -298,5 +298,65 @@ "SecRule REQUEST_HEADERS:Content-Type \"^text/xml$\" \"id:500008,phase:1,t:none,t:lowercase,nolog,pass,ctl:requestBodyProcessor=XML\"", "SecRule XML \"@validateSchema test-cases/data/SoapEnvelope-bad.xsd\" \"id:500007,phase:3,deny\"" ] + }, + { + "enabled": 1, + "version_min": 300000, + "title": "Testing XML request body parser (bad schema, errors are not accumulated between evaluations)", + "resource": "libxml2", + "client": { + "ip": "200.249.12.31", + "port": 123 + }, + "server": { + "ip": "200.249.12.31", + "port": 80 + }, + "request": { + "headers": { + "Host": "localhost", + "User-Agent": "curl/7.38.0", + "Accept": "*/*", + "Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120", + "Content-Type": "text/xml", + "Content-Length": "683" + }, + "uri": "/?key=value&key=other_value", + "method": "POST", + "body": [ + "", + " ", + " ", + " ", + " 12123", + " ", + " ", + "" + ] + }, + "response": { + "headers": { + "Content-Length": "0" + }, + "body": [ + "" + ] + }, + "expected": { + "debug_log": "XML: Failed to load Schema: test-cases/data/SoapEnvelope-bad\\.xsd\\. XML Error: Failed to parse(?!.*^XML Error:)", + "http_code": 403 + }, + "rules": [ + "SecRuleEngine On", + "SecRequestBodyAccess On", + "SecXMLExternalEntity On", + "SecRule REQUEST_HEADERS:Content-Type \"^text/xml$\" \"id:500008,phase:1,t:none,t:lowercase,nolog,pass,ctl:requestBodyProcessor=XML\"", + "SecRule XML \"@validateSchema test-cases/data/SoapEnvelope-bad.xsd\" \"id:500007,phase:3,deny,t:none,t:lowercase,multiMatch\"" + ] } ]