Skip to content

Parser for XML namespaces in xml rules is too restrictive #2358

Open

Description

@ralfmeister

**Parser for XML namespeces in XML rules is too restrictive **

We encountered a bug when porting mod_security from version 2 to version 3.
The parser, that parses the XML-namespace in XML rules is too restrictive.
It allows only namespaces beginning with http://

Burt the specification from https://www.w3.org/TR/1999/REC-xml-names-19990114
states:


  1. Declaring Namespaces

.....

[Definition:] The attribute's value, a URI reference, is the namespace name identifying the namespace. The namespace name, to serve its intended purpose, should have the characteristics of uniqueness and persistence. It is not a goal that it be directly usable for retrieval of a schema (if any exists). An example of a syntax that is designed with these goals in mind is that for Uniform Resource Names [RFC2141]. However, it should be noted that ordinary URLs can be managed in such a way as to achieve these same goals.

Thus, namespaces do not always start with http://, but may also start with e.g. uri:

We got the rules loaded and working by just removing the check for http:// in src/actions/xmlns.cc

--- src/actions/xmlns.cc        Thu Jul  9 13:38:37 2020
+++ src/actions/xmlns.cc        Thu Jul  9 13:41:00 2020
@@ -27,7 +27,6 @@
 
 bool XmlNS::init(std::string *error) {
     size_t pos;
-    std::string http = "http://";
 
     pos = m_parser_payload.find("=");
     if (pos == std::string::npos) {
@@ -46,12 +45,6 @@
     if (m_href.at(0) == '\'' && m_href.size() > 3) {
         m_href.erase(0, 1);
         m_href.pop_back();
-    }
-
-    if (m_href.compare(0, http.length(), http) != 0) {
-        error->assign("XMLS: Missing xmlns href for prefix: " \
-            "`" + m_href + "'.");
-        return false;
     }
 
     return true;

Activity

  1. added
    3.xRelated to ModSecurity version 3.x
    on Jul 14, 2020
  2. self-assigned this
    on Jul 14, 2020
  3. fzipi commented on Oct 12, 2026

    @fzipi
    Collaborator

    Revisiting this one, and confirming it. XmlNS::init in src/actions/xmlns.cc rejects any namespace href that does not start with http://, which excludes https://, urn: and every other valid URI reference (the error text, "Missing xmlns href", does not say so either). 2.x has no such check. The fix is to drop that comparison; the href only needs to be non-empty. Marking as a bug; I can open the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.xRelated to ModSecurity version 3.xbugIt is a confirmed bugpr available

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions