summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlmightyJu <almightyju@arandomworld.co.uk>2017-09-19 02:31:46 +0100
committerAlmightyJu <almightyju@arandomworld.co.uk>2017-09-19 02:31:46 +0100
commite590cad8975f6cbba76e4f23e4bf9b1c90dd3ebe (patch)
tree3ae994de1d3d46f3b08231f6f48b58a16367e737
parent190ee307b0ce70ece06face009eb4ab5abdb33b4 (diff)
downloadcouchdb-e590cad8975f6cbba76e4f23e4bf9b1c90dd3ebe.tar.gz
Support setting cookie domain for auth
-rw-r--r--rel/overlay/etc/default.ini1
-rw-r--r--src/couch/src/couch_httpd_auth.erl9
2 files changed, 9 insertions, 1 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 653131e0c..27a952c74 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -177,6 +177,7 @@ iterations = 10 ; iterations for password hashing
; public_fields =
; secret =
; users_db_public = false
+; cookie_domain = example.com
; CSP (Content Security Policy) Support for _utils
[csp]
diff --git a/src/couch/src/couch_httpd_auth.erl b/src/couch/src/couch_httpd_auth.erl
index 51a83e7e4..6ac7b75af 100644
--- a/src/couch/src/couch_httpd_auth.erl
+++ b/src/couch/src/couch_httpd_auth.erl
@@ -265,7 +265,7 @@ cookie_auth_cookie(Req, User, Secret, TimeStamp) ->
Hash = crypto:hmac(sha, Secret, SessionData),
mochiweb_cookies:cookie("AuthSession",
couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)),
- [{path, "/"}] ++ cookie_scheme(Req) ++ max_age()).
+ [{path, "/"}] ++ cookie_scheme(Req) ++ max_age() ++ cookie_domain()).
ensure_cookie_auth_secret() ->
case config:get("couch_httpd_auth", "secret", undefined) of
@@ -442,6 +442,13 @@ max_age() ->
[{max_age, Timeout}]
end.
+cookie_domain() ->
+ Domain = config:get("couch_httpd_auth", "cookie_domain", ""),
+ case Domain of
+ "" -> [];
+ _ -> [{domain, Domain}]
+ end.
+
reject_if_totp(User) ->
case get_totp_config(User) of
undefined ->