Repository navigation
Dancer2::Session::Pg Released #1856
mikkoi
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have released a new Dancer2 Session Engine: https://metacpan.org/dist/Dancer2-Session-Pg
It is specially crafted to PostgreSQL and uses Pg special SQL. Required Pg 9.5 or later.
Stores Dancer2 sessions in PostgreSQL, and uses PostgreSQL's own features to make that storage safer than a serialised blob in a table.
web session is not ordinary data. It frequently carries the credentials that prove who somebody is.
Authenticated encryption at rest
The payload is encrypted with an AEAD cipher, so a dump, a backup or a support copy of the table does not hand over the contents of a session, and a row that has been altered fails to decrypt instead of deserialising into a structure the application would then trust.
Expiry decided by the server's clock
expires is a timestamptz and every read filters on it. Application clocks drift; the database's clock is the one every process shares, so all of them agree about whether a session is still alive.
Atomic writes
Sessions are written with INSERT ... ON CONFLICT DO UPDATE, which is atomic. Any number of workers may write one session id concurrently without producing a duplicate row, a unique violation or a deadlock, and without moving the expiry cap.
An optional clear column beside the encrypted payload makes it possible to find and end every session belonging to one account without decrypting anything -- see "destroy_for_principal" in Dancer2::Session::Pg. Suspending an account has little effect while the suspended user's cookie still works. That column is off by default and need not exist; "THE PRINCIPAL COLUMN" in Dancer2::Session::Pg is about whether you want it.
I am using this in my own (commercial) apps in production.
All reactions