Skip to content

Commit

Permalink
Use 144-bit session IDs
Browse files Browse the repository at this point in the history
Part of #13.
  • Loading branch information
aantron committed Apr 13, 2021
1 parent eee1664 commit b77e16f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/middleware/session.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ let (|>?) =
https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#session-id-length
Extended to the next multiple of 6 for a nice base64 encoding. *)
...extended to the next multiple of 6 for a nice base64 encoding.
NIST recommends 64 bits:
https://pages.nist.gov/800-63-3/sp800-63b.html#sec7
..and links to OWASP.
Some rough bounds give a maximal probability of 2^-70 for a collision between
two keys among 100,000,000,000 concurrent sessions (5x the monthly traffic of
google.com in February 2021). *)
let new_key () =
Dream__cipher.Random.random 18 |> Dream__pure.Formats.to_base64url

Expand All @@ -109,8 +119,7 @@ let new_label () =
module Memory =
struct
let rec create hash_table expires_at =
let key =
Dream__cipher.Random.random 33 |> Dream__pure.Formats.to_base64url in
let key = new_key () in
if Hashtbl.mem hash_table key then
create hash_table expires_at
else begin
Expand Down
2 changes: 1 addition & 1 deletion src/sql/session.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let remove =

let rec create db expires_at attempt =
let session = Session.{
key = Dream__cipher.Random.random 33 |> Dream__pure.Formats.to_base64url;
key = Session.new_key ();
label = Session.new_label ();
expires_at;
payload = [];
Expand Down

0 comments on commit b77e16f

Please sign in to comment.