This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch validate-redirect
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 32845a1f5e84ab23af792fd9d688bef0d0a93cde
Author: Robert Newson <[email protected]>
AuthorDate: Thu Oct 29 13:08:35 2026 +0000

    validate redirect location
---
 src/couch/src/couch_httpd.erl         |  9 ++++++++-
 test/elixir/test/cookie_auth_test.exs | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 094efee12..d729a6f6c 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -660,7 +660,14 @@ host_for_request(#httpd{mochi_req = MochiReq}) ->
             Value
     end.
 
-absolute_uri(#httpd{mochi_req = MochiReq} = Req, [$/ | _] = Path) ->
+absolute_uri(#httpd{} = Req, [$/ | _] = Path) ->
+    case uri_string:parse(Path) of
+        {error, _Type, _Reason} ->
+            throw({bad_request, "invalid path"});
+        #{} = URIMap ->
+            absolute_uri(Req, URIMap)
+    end;
+absolute_uri(#httpd{mochi_req = MochiReq} = Req, #{path := Path}) ->
     Host = host_for_request(Req),
     XSsl = chttpd_util:get_chttpd_config("x_forwarded_ssl", "X-Forwarded-Ssl"),
     Scheme =
diff --git a/test/elixir/test/cookie_auth_test.exs 
b/test/elixir/test/cookie_auth_test.exs
index 7cbac699f..fedfcecb2 100644
--- a/test/elixir/test/cookie_auth_test.exs
+++ b/test/elixir/test/cookie_auth_test.exs
@@ -296,6 +296,20 @@ defmodule CookieAuthTest do
     assert resp.body["error"] == "unauthorized"
     assert String.ends_with?(resp.headers["location"], "/_up")
 
+    # test redirect with invalid path
+    resp =
+      Couch.post(
+        "/_session",
+        query: [next: "/_up\r"],
+        body: %{
+          :username => "Jason Davies",
+          :password => @password
+        }
+      )
+
+    assert resp.status_code == 400
+    assert resp.body["error"] == "bad_request"
+
     session = login("jchris", "funnybone")
     info = Couch.Session.info(session)
     assert info["userCtx"]["name"] == "jchris"

Reply via email to