summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Cottlehuber <dch@apache.org>2018-04-30 10:10:26 +0000
committerDave Cottlehuber <dch@apache.org>2018-04-30 21:48:34 +0000
commit2cec527cd183f8b247f7f4d8ec3fc2e17fbc7f1a (patch)
tree17ea6d47eaeaec9da0014280aff64849c0007381
parent180a1551435153779628a6698e41557b0e60339e (diff)
downloadcouchdb-2cec527cd183f8b247f7f4d8ec3fc2e17fbc7f1a.tar.gz
config: improve handling of admin-supplied changes
- send a readable error response from failed config set - trust but verify admin-supplied content in separate function - return specific error conditions for logging
-rw-r--r--src/chttpd/src/chttpd_misc.erl10
-rw-r--r--src/couch/src/couch_httpd_misc_handlers.erl2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl
index 15eabbfbd..696eeb6bf 100644
--- a/src/chttpd/src/chttpd_misc.erl
+++ b/src/chttpd/src/chttpd_misc.erl
@@ -258,11 +258,15 @@ handle_node_req(#httpd{path_parts=[_, _Node, <<"_config">>, _Section]}=Req) ->
% "value"
handle_node_req(#httpd{method='PUT', path_parts=[_, Node, <<"_config">>, Section, Key]}=Req) ->
couch_util:check_config_blacklist(Section),
- Value = chttpd:json_body(Req),
+ Value = string:trim(chttpd:json_body(Req)),
Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
OldValue = call_node(Node, config, get, [Section, Key, ""]),
- ok = call_node(Node, config, set, [Section, Key, ?b2l(Value), Persist]),
- send_json(Req, 200, list_to_binary(OldValue));
+ case call_node(Node, config, set, [Section, Key, ?b2l(Value), Persist]) of
+ ok ->
+ send_json(Req, 200, list_to_binary(OldValue));
+ {error, Reason} ->
+ chttpd:send_error(Req, {bad_request, Reason})
+ end;
% GET /_node/$node/_config/Section/Key
handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_config">>, Section, Key]}=Req) ->
case call_node(Node, config, get, [Section, Key, undefined]) of
diff --git a/src/couch/src/couch_httpd_misc_handlers.erl b/src/couch/src/couch_httpd_misc_handlers.erl
index 1def94853..372200d28 100644
--- a/src/couch/src/couch_httpd_misc_handlers.erl
+++ b/src/couch/src/couch_httpd_misc_handlers.erl
@@ -285,7 +285,7 @@ handle_approved_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Re
<<"admins">> ->
couch_passwords:hash_admin_password(RawValue);
_ ->
- RawValue
+ string:trim(RawValue)
end
end,
OldValue = config:get(Section, Key, ""),