mod_dav: XML-quote core property values taken from the subrequest: * modules/dav/main/props.c (dav_insert_coreprop): Quote the getcontenttype and getcontentlanguage values. * test/modules/dav/test_007_propfind_quoting.py: New test. * changes-entries/dav-propfind-quoting.txt: New file. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
diff --git a/changes-entries/dav-propfind-quoting.txt b/changes-entries/dav-propfind-quoting.txt new file mode 100644 index 0000000..d2ad83f --- /dev/null +++ b/changes-entries/dav-propfind-quoting.txt
@@ -0,0 +1,2 @@ + *) mod_dav: Escape the getcontenttype and getcontentlanguage + properties in PROPFIND responses. [Joe Orton]
diff --git a/modules/dav/main/props.c b/modules/dav/main/props.c index 7509a21..ee20868 100644 --- a/modules/dav/main/props.c +++ b/modules/dav/main/props.c
@@ -399,7 +399,8 @@ dav_do_prop_subreq(propdb); } if (propdb->subreq->content_type != NULL) { - value = propdb->subreq->content_type; + value = apr_xml_quote_string(propdb->p, + propdb->subreq->content_type, 0); } break; @@ -412,7 +413,7 @@ } if ((lang = apr_table_get(propdb->subreq->headers_out, "Content-Language")) != NULL) { - value = lang; + value = apr_xml_quote_string(propdb->p, lang, 0); } break; }
diff --git a/test/modules/dav/test_007_propfind_quoting.py b/test/modules/dav/test_007_propfind_quoting.py new file mode 100644 index 0000000..52a5b5e --- /dev/null +++ b/test/modules/dav/test_007_propfind_quoting.py
@@ -0,0 +1,56 @@ +import os +import xml.etree.ElementTree as ET + +import pytest + +from pyhttpd.conf import HttpdConf + + +CONTENT_TYPE = 'text/x-test; note="a&b<c>"' + +PROPFIND_BODY = ('<?xml version="1.0" encoding="utf-8"?>' + '<D:propfind xmlns:D="DAV:">' + '<D:prop><D:getcontenttype/></D:prop>' + '</D:propfind>') + + +class TestDavPropfindQuoting: + """DAV:getcontenttype must be XML-quoted in a PROPFIND response.""" + + @pytest.fixture(autouse=True, scope='class') + @classmethod + def _class_scope(cls, env): + dav_dir = os.path.join(env.gen_dir, 'dav-quote') + os.makedirs(dav_dir, exist_ok=True) + with open(os.path.join(dav_dir, 'hello.txt'), 'w') as fd: + fd.write('hello') + dav_dir_conf = dav_dir.replace('\\', '/') + conf = HttpdConf(env, extras={ + f"test1.{env.http_tld}": f""" + Alias /dav-quote "{dav_dir_conf}" + <Directory "{dav_dir_conf}"> + Dav On + Require all granted + ForceType '{CONTENT_TYPE}' + </Directory> + """, + }) + conf.add_vhost_test1() + conf.install() + assert env.apache_restart() == 0 + + @pytest.mark.parametrize("body", [PROPFIND_BODY, None]) + def test_dav_007_01_getcontenttype(self, env, body): + url = env.mkurl("http", "test1", "/dav-quote/hello.txt") + options = ['-X', 'PROPFIND', '-H', 'Depth: 0'] + if body: + options += ['-H', 'Content-Type: text/xml', + '--data-binary', body] + r = env.curl_raw(url, options=options) + assert r.response["status"] == 207 + # fails to parse if the property value is not quoted + root = ET.fromstring(r.response["body"]) + prop = root.find('.//{DAV:}getcontenttype') + assert prop is not None + assert prop.text == CONTENT_TYPE + assert len(prop) == 0