Skip to content

Commit

Permalink
Allow Sessions to support secure cookie settings (#211)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Torrey <[email protected]>
  • Loading branch information
ranok authored Feb 24, 2023
1 parent ab0a5b4 commit efb1284
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/prologue/middlewares/sessions/memorysession.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ proc sessionMiddleware*(
path = "",
domain = "",
sameSite = Lax,
httpOnly = false
httpOnly = false,
secure = false
): HandlerAsync =

var memorySessionTable = newTable[string, Session]()
Expand All @@ -38,7 +39,7 @@ proc sessionMiddleware*(
data = urlsafeBase64Encode(randomBytesSeq(16))
ctx.setCookie(sessionName, data,
maxAge = some(maxAge), path = path, domain = domain,
sameSite = sameSite, httpOnly = httpOnly)
sameSite = sameSite, httpOnly = httpOnly, secure = secure)
memorySessionTable[data] = ctx.session

await switch(ctx)
Expand Down
5 changes: 3 additions & 2 deletions src/prologue/middlewares/sessions/redissession.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ proc sessionMiddleware*(
path = "",
domain = "",
sameSite = Lax,
httpOnly = false
httpOnly = false,
secure = false
): HandlerAsync =

var redisClient = waitFor openAsync()
Expand All @@ -53,7 +54,7 @@ proc sessionMiddleware*(
data = genUid()
ctx.setCookie(sessionName, data,
maxAge = some(maxAge), path = path, domain = domain,
sameSite = sameSite, httpOnly = httpOnly)
sameSite = sameSite, httpOnly = httpOnly, secure = secure)

await switch(ctx)

Expand Down
5 changes: 3 additions & 2 deletions src/prologue/middlewares/sessions/signedcookiesession.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ proc sessionMiddleware*(
path = "",
domain = "",
sameSite = Lax,
httpOnly = false
httpOnly = false,
secure = false
): HandlerAsync =

var secretKey = settings["prologue"].getOrDefault("secretKey").getStr
Expand Down Expand Up @@ -69,4 +70,4 @@ proc sessionMiddleware*(
if ctx.session.modified:
ctx.setCookie(sessionName, signer.sign(dumps(ctx.session)),
maxAge = some(maxAge), path = path, domain = domain,
sameSite = sameSite, httpOnly = httpOnly)
sameSite = sameSite, httpOnly = httpOnly, secure = secure)

0 comments on commit efb1284

Please sign in to comment.