Conversation
78e98e6 to
e7bfe0b
Compare
|
Thanks for this work on persistent sessions! A few security concerns we noticed during review:
We have PR #3282 ( |
@clutester We definitely want to be able to build on your existing PR, though you'd need to address some of the above concerns. We're thinking that maybe it doesn't make sense after all to have users specify their own cookie storage keys, since it then becomes the user's responsibility to securely generate random keys of sufficient length to avoid padding and whatnot. We do love the cookie expiration option that you added in the config file, so that can stay. As for the key itself, we can combine the two approaches and go for the following:
Caldera's file_svc.py already provides methods to write/read encrypted files, so you can use those without having to implement anything new. |
e7bfe0b to
856b9eb
Compare
Thank you for the review below are the recent changes per your request: Removed session_cookie_key from YAML to prevent weak/default keys. Implemented automated key persistence using file_svc to read/write an encrypted cookie_storage file in the data directory. Retained the session_expiration_days config as requested. |
|
|
verified generated session cookie was saved encrypted at appropriate file location added some small changes to fix unit tests, remove unused imports, and update .gitignore to ignore the cookie storage file |
uruwhy
left a comment
There was a problem hiding this comment.
thank you very much for your contribution!


Description
Fixes #3256
This PR introduces configurable, persistent session cookies across server restarts, addressing the friction developers and operators experience when frequently restarting the Caldera server.
Previously,
auth_svc.pygenerated an ephemeralFernetkey in memory on every boot, immediately invalidating all existing browser sessions. This update shifts the session encryption key to the configuration file while maintaining backwards compatibility.Key Changes:
session_cookie_keyandsession_expiration_daystoconf/default.yml.app/utility/config_generator.pyto automatically generate a secure, url-safe token forsession_cookie_keywhen a newlocal.ymlis created.app/service/auth_svc.pyto read the configured key, properly pad/encode it to meet the strict 32-byte AES requirement ofaiohttp_session, and apply the calculatedmax_ageto the browser cookie.Type of change
How Has This Been Tested?
Extensive local testing was performed to ensure cryptographic requirements were met and no regressions were introduced to the login flow.
session_expiration_daysto fractional values (e.g.,0.0001). Verified the math correctly converted to seconds, the browser dropped the cookie after the allotted seconds, and the backend safely redirected to the login screen without throwing HTTP 500 errors.local.ymland ranserver.py --fresh(without the--insecureflag). Verifiedconfig_generator.pysuccessfully injected a secure, random string into the new configuration and thataiohttpaccepted the generated key length.local.ymlentirely. Verified the server gracefully fell back to generating an ephemeral key without crashing.Checklist: