diff --git a/changes-entries/69994.txt b/changes-entries/69994.txt new file mode 100644 index 00000000000..8957310d31a --- /dev/null +++ b/changes-entries/69994.txt @@ -0,0 +1,4 @@ + *) core: Reject a request whose decoded %2f leaves a ".." segment that + escapes the document root, instead of silently continuing, when + "AllowEncodedSlashes on" is in effect. + PR 69994 [Arturo Bernal] diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index 5d1df1abb36..0a29e80c5e8 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -10687 +10703 diff --git a/server/request.c b/server/request.c index 6cee49a9d54..c71c128be19 100644 --- a/server/request.c +++ b/server/request.c @@ -270,7 +270,12 @@ AP_DECLARE(int) ap_process_request_internal(request_rec *r) /* Decoding slashes might have created new // or /./ or /../ * segments (e.g. "/.%2F/"), so re-normalize. */ - ap_normalize_path(r->parsed_uri.path, normalize_flags); + if (!ap_normalize_path(r->parsed_uri.path, normalize_flags)) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10698) + "invalid URI path after decoding encoded " + "slashes (%s)", r->unparsed_uri); + return HTTP_BAD_REQUEST; + } } } diff --git a/test/modules/core/test_001_encoding.py b/test/modules/core/test_001_encoding.py index 75ca9fdd6c7..e71f6db929a 100644 --- a/test/modules/core/test_001_encoding.py +++ b/test/modules/core/test_001_encoding.py @@ -91,3 +91,21 @@ def test_core_001_20(self, env, host, path, status): url = env.mkurl("https", host, path) r = env.curl_get(url) assert r.response["status"] == status + + # BZ 69994: decoding %2f (only done with AllowEncodedSlashes on) can + # complete a ".." segment that the first normalize_path() pass, run + # before %2f is decoded, could not see yet. The second pass detects + # it escaping above the root, but its return value used to be + # ignored, so the request was silently allowed through instead of + # getting the same 400 a plain, never-encoded ".." already gets in + # test_core_001_04 above. + @pytest.mark.parametrize("path", [ + "/a/..%2f..%2fb.html", + "/a/b/..%2f..%2f..%2fc.html", + ]) + def test_core_001_21(self, env, path): + url = env.mkurl("https", "test2", path) + r = env.curl_get(url) + assert r.response["status"] == 400 + env.httpd_error_log.ignore_recent( + matches=[r'.*invalid URI path after decoding encoded slashes.*'])