nickva commented on code in PR #4798:
URL: https://github.com/apache/couchdb/pull/4798#discussion_r1347575999
##########
src/couch/src/couch_httpd_auth.erl:
##########
@@ -460,16 +460,18 @@ cookie_auth_header(
cookie_auth_header(_Req, _Headers) ->
[].
-cookie_auth_cookie(Req, User, Secret, TimeStamp, MustMatchBasic) ->
- MustMatchBasicStr =
- case MustMatchBasic of
- true -> "1";
- false -> "0"
- end,
- SessionData = lists:join(":", [
+cookie_auth_cookie(Req, User, Secret, TimeStamp, true) ->
+ SessionItems = [
User,
- lists:join(",", [erlang:integer_to_list(TimeStamp, 16),
MustMatchBasicStr])
- ]),
+ [erlang:integer_to_list(TimeStamp, 16), ",1"]
+ ],
+ cookie_auth_cookie(Req, Secret, SessionItems);
+cookie_auth_cookie(Req, User, Secret, TimeStamp, false) ->
+ SessionItems = [User, erlang:integer_to_list(TimeStamp, 16)],
+ cookie_auth_cookie(Req, Secret, SessionItems).
+
+cookie_auth_cookie(Req, Secret, SessionItems) when is_list(SessionItems) ->
+ SessionData = lists:join(":", SessionItems),
Review Comment:
This is a bit tricky to reason about:
```erlang
([email protected])1> SessionItems = [<<"user">>, ["abcd123", ",1"]].
[<<"user">>,["abcd123",",1"]]
([email protected])2> SessionData = lists:join(":", SessionItems).
[<<"user">>,":",["abcd123",",1"]]
```
However it does work as https://www.erlang.org/doc/man/crypto#mac-4 takes
iodata.
```erlang
([email protected])3> erlang:iolist_to_binary(SessionData).
<<"user:abcd123,1">>
```
The existing cookie will then be:
```erlang
([email protected])1> SessionItems = [<<"user">>, ["abcd123"]].
[<<"user">>,["abcd123"]]
([email protected])2> SessionData = lists:join(":", SessionItems).
[<<"user">>,":",["abcd123"]]
([email protected])3> erlang:iolist_to_binary(SessionData).
<<"user:abcd123">>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]