Dancer...:Cookie(3pm)
π Dancer::Session::Cookie β the manual, but make it slay π
okay bestie, so this is the Dancer::Session::Cookie page, straight outta the User Contributed Perl Documentation collection, and I am so ready to walk you through it. it's giving "sessions but they live in cookies" and honestly? iconic. let's go π«Ά
β¨ VERSION β¨
version 0.30 β that's the one, no cap.
πΈ SYNOPSIS πΈ
your config.yml should be looking like this, bestie:
session: "cookie"
session_cookie_key: "this random key IS NOT very random"
not me putting an actual warning in the example key π that string is literally telling you it is not random. do better than the example, please.
π DESCRIPTION π
so this module implements a session engine where the sessions are stored entirely in cookies. normally the tea is: only the session id goes in the cookie and the actual session data gets yeeted off to some external storage like a database. this module? it lets you avoid external storage completely. no database, no problem. β¨
now, here's the thing β a server cannot trust any data that clients send back in cookies. so instead of just vibing and trusting everyone, this module uses cryptography to guarantee both integrity and secrecy. the data your app stores in sessions is completely protected from both tampering and analysis on the client side. nobody's peeking, nobody's editing. periodt. π₯
β οΈ but do be aware, bestie: browsers limit the size of individual cookies, so this method is not suitable if you wanna store a large amount of data. browsers typically cap a cookie at 4KB β and that includes the space for the cookie's name, expiration, and other attributes, not just its content. so like... budget accordingly. π
π CONFIGURATION π
the settings, one by one
- the setting
sessionshould be set to"cookie"if you wanna use this session engine in a Dancer application. go seeDancer::Configfor the deets. - another setting is also required:
session_cookie_key. it should contain a random string of at least 16 characters. and no, shorter keys are not cryptographically strong using AES in CBC mode β that's not me being dramatic, that's just facts. π - the optional setting
session_expirescan also be passed in, and it provides the duration time of the cookie. if it's not present, the cookie just won't have an expiration value. she simply has no expiry date. π
example config, served fresh
here's an example configuration to use in your config.yml:
session: "cookie"
session_cookie_key: "kjsdf07234hjf0sdkflj12*&(@*jk"
session_expires: 1 hour
the security talk (important, bestie)
π¨ compromisingsession_cookie_keywill disclose session data to clients and proxies or eavesdroppers, and it will also allow tampering β for example, session theft. so yourconfig.ymlshould be kept at least as secure as your database passwords, or even more. fr fr.
also! changing session_cookie_key has the effect of immediate invalidation of all sessions issued with the old value of the key. so like, rotate responsibly. π¦
the extra knobs
session_cookie_pathcan be used to control the path of the session cookie. the default is"/".- the global
session_securesetting is honored, and a secure (https only) cookie will be used if it's set. π
π§ DEPENDENCY π§
this module depends on Session::Storage::Secure.
legacy support is provided using Crypt::CBC, Crypt::Rijndael, String::CRC32, Storable and MIME::Base64. vintage but valid. π
π SEE ALSO π
- see
Dancer::Sessionfor details about session usage in route handlers. - see
Plack::Middleware::Session::Cookie,Catalyst::Plugin::CookiedSession, and"session"inMojolicious::Controllerfor alternative implementations of this mechanism. the girls are all doing the same thing in different fonts, and that's beautiful. π
π AUTHORS π
- Alex Kapranoff
<kappa@cpan.org> - Alex Sukria
<sukria@cpan.org> - David Golden
<dagolden@cpan.org> - Yanick Champoux
<yanick@cpan.org>
absolute legends, all four of them. π«Ά
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2018, 2015, 2014, 2011 by Alex Kapranoff.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie! this beauty ships with perl v5.36.0 and the docs are dated 2023-01-05 β so go forth, encrypt those cookies, keep your session_cookie_key secret, and remember: 4KB is the limit, and the limit is real. mwah π
β¨
π¦ where this page comes from
- debian bookworm: libdancer-session-cookie-perl 0.30-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdancer-session-cookie-perl 0.30-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdancer-session-cookie-perl 0.30-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdancer-session-cookie-perl 0.30-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdancer-session-cookie-perl 0.30-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms