You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2017/10/31 19:18:40 UTC

[couchdb] branch 1.x.x updated: Blacklist some config sections from HTTP PUT/DELETE operations

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

jan pushed a commit to branch 1.x.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/1.x.x by this push:
     new 9a28df7  Blacklist some config sections from HTTP PUT/DELETE operations
9a28df7 is described below

commit 9a28df7e9703a1a3420e7616c4d33a523ee06354
Author: Alexander Shorin <kx...@apache.org>
AuthorDate: Thu Oct 26 01:24:08 2017 +0300

    Blacklist some config sections from HTTP PUT/DELETE operations
    
    This is backport of:
    https://github.com/apache/couchdb/pull/914
---
 share/www/script/test/config.js           |  8 ++++++++
 src/couchdb/couch_httpd_misc_handlers.erl |  1 +
 src/couchdb/couch_util.erl                | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/share/www/script/test/config.js b/share/www/script/test/config.js
index 193aa89..22824b2 100644
--- a/share/www/script/test/config.js
+++ b/share/www/script/test/config.js
@@ -208,4 +208,12 @@ couchTests.config = function(debug) {
     headers: {"X-Couch-Persist": "false"}
   });
   TEquals(200, xhr.status, "Reset config whitelist to undefined");
+
+  // Confirm that the blacklist is functional
+  ["daemons", "external", "httpd_design_handlers", "httpd_db_handlers", "native_query_servers", "os_daemons", "query_servers"].forEach(function(section) {
+    xhr = CouchDB.request("PUT", "/_config/" + section + "/wohali",{
+      body: "\"rules\""
+    });
+    TEquals(403, xhr.status, "Blacklisted config section " + section);
+  });
 };
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
index dbf698c..a284e7a 100644
--- a/src/couchdb/couch_httpd_misc_handlers.erl
+++ b/src/couchdb/couch_httpd_misc_handlers.erl
@@ -168,6 +168,7 @@ handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
 handle_config_req(#httpd{method=Method, path_parts=[_, Section, Key]}=Req)
       when (Method == 'PUT') or (Method == 'DELETE') ->
     ok = couch_httpd:verify_is_server_admin(Req),
+    couch_util:check_config_blacklist(Section),
     Persist = couch_httpd:header_value(Req, "X-Couch-Persist") /= "false",
     case couch_config:get(<<"httpd">>, <<"config_whitelist">>, null) of
         null ->
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl
index 2509bef..0053084 100644
--- a/src/couchdb/couch_util.erl
+++ b/src/couchdb/couch_util.erl
@@ -30,12 +30,33 @@
 -export([with_db/2]).
 -export([rfc1123_date/0, rfc1123_date/1]).
 -export([find_in_binary/2]).
+-export([check_config_blacklist/1]).
 
 -include("couch_db.hrl").
 
 % arbitrarily chosen amount of memory to use before flushing to disk
 -define(FLUSH_MAX_MEM, 10000000).
 
+-define(BLACKLIST_CONFIG_SECTIONS, [
+    <<"daemons">>,
+    <<"external">>,
+    <<"httpd_design_handlers">>,
+    <<"httpd_db_handlers">>,
+    <<"httpd_global_handlers">>,
+    <<"native_query_servers">>,
+    <<"os_daemons">>,
+    <<"query_servers">>
+]).
+
+check_config_blacklist(Section) ->
+    case lists:member(Section, ?BLACKLIST_CONFIG_SECTIONS) of
+    true ->
+        Msg = <<"Config section blacklisted for modification over HTTP API.">>,
+        throw({forbidden, Msg});
+    _ ->
+        ok
+    end.
+
 priv_dir() ->
     case code:priv_dir(couch) of
         {error, bad_name} ->

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].