Blog

Sessions that cannot be forged

2 min read

Signing in should take three lines and be safe by default. Signed cookies, the right flags and a short list of rules can be the language's job.

Sessions are where web frameworks hand the most decisions to the programmer: where to keep them, how to sign them, which cookie flags to set, how long they last. Each choice has a safe answer most of the time, and most of the trouble comes from not knowing it.

Three calls

route POST /login { form: { email: str, password: str } } {    let user = db.one("select * from users where email = ?", email)    if !crypto.verify_password(password, user.password_hash) { reply 401 "Wrong email or password" }    set_session({ user: user.id })    redirect("/")}route POST /logout { end_session(); redirect("/") }

set_session, session() and end_session(). That is the whole interface.

Safe defaults, made by the runtime

What it leaves to you

Ending a session everywhere (a stolen laptop) needs the server to remember which sessions exist. The runtime cannot know your rules for that, so the guide shows how: keep an id in the session and check it against the database.

Since then: sessions work this way in Quillo. See Cookies and sessions.

The Quillo newsletterNew posts, components and plugins, about once a week. No tracking.

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On Sessions that cannot be forged: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.