Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/operators/validate_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,30 @@ 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) {
std::stringstream err;
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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/operators/validate_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class ValidateSchema : public Operator {

private:
std::string m_resource;
std::string m_err;
#endif
};

Expand Down
60 changes: 60 additions & 0 deletions test/test-cases/regression/request-body-parser-xml.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
" <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"",
" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"",
" xmlns:tns=\"http://www.bluebank.example.com/axis/getBalance.jws\"",
" xmlns:types=\"http://www.bluebank.example.com/axis/getBalance.jws/encodedTypes\"",
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">",
" <soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">",
" <q1:getInput xmlns:q1=\"http://DefaultNamespace\">",
" <id xsi:type=\"xsd:string\">12123</id>",
" </q1:getInput>",
" </soap:Body>",
"</soap:Envelope>"
]
},
"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\""
]
}
]
Loading