Repository: couchdb-chttpd Updated Branches: refs/heads/master 07493ef4c -> f9cad9dd1
Port max_rewrites to chttpd This commit incorporates the original work by Ronny Pfannschmidt <[email protected]> and myself for COUCHDB-1441 and COUCHDB-1651. Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/f9cad9dd Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/f9cad9dd Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/f9cad9dd Branch: refs/heads/master Commit: f9cad9dd19fd175d8b26da3d5af10ba70e3513d1 Parents: 07493ef Author: Robert Newson <[email protected]> Authored: Wed Jul 29 18:17:27 2015 +0100 Committer: Robert Newson <[email protected]> Committed: Wed Jul 29 18:23:10 2015 +0100 ---------------------------------------------------------------------- src/chttpd.erl | 1 + src/chttpd_rewrite.erl | 9 +++++++++ 2 files changed, 10 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f9cad9dd/src/chttpd.erl ---------------------------------------------------------------------- diff --git a/src/chttpd.erl b/src/chttpd.erl index 1e80a53..31c16d3 100644 --- a/src/chttpd.erl +++ b/src/chttpd.erl @@ -130,6 +130,7 @@ stop() -> handle_request(MochiReq0) -> Begin = os:timestamp(), + erlang:put(?REWRITE_COUNT, 0), MochiReq = couch_httpd_vhost:dispatch_host(MochiReq0), case config:get("chttpd", "socket_options") of http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f9cad9dd/src/chttpd_rewrite.erl ---------------------------------------------------------------------- diff --git a/src/chttpd_rewrite.erl b/src/chttpd_rewrite.erl index 902f6e9..87198d4 100644 --- a/src/chttpd_rewrite.erl +++ b/src/chttpd_rewrite.erl @@ -119,6 +119,15 @@ handle_rewrite_req(#httpd{ Prefix = <<"/", DbName/binary, "/", DesignId/binary>>, QueryList = lists:map(fun decode_query_value/1, chttpd:qs(Req)), + RewritesSoFar = erlang:get(?REWRITE_COUNT), + MaxRewrites = config:get_integer("httpd", "rewrite_limit", 100), + case RewritesSoFar >= MaxRewrites of + true -> + throw({bad_request, <<"Exceeded rewrite recursion limit">>}); + false -> + erlang:put(?REWRITE_COUNT, RewritesSoFar + 1) + end, + #doc{body={Props}} = DDoc, % get rules from ddoc
