Skip to content

Clarify Session TTL logic #1416

@kaaax0815

Description

@kaaax0815

Describe the feature

iron seal is called with

ttl: config.maxAge ? config.maxAge * 1000 : 0,

Resealing the session updates the expiration to now + maxAge

The cookie however is set with

expires: config.maxAge ? new Date(session.createdAt + config.maxAge * 1000) : undefined,

That means the cookies expiration is createdAt + maxAge

On h3 unseal the expiration is checked with

h3/src/utils/session.ts

Lines 226 to 229 in edb53fe

const age = Date.now() - (unsealed.createdAt || Number.NEGATIVE_INFINITY);
if (age > config.maxAge * 1000) {
throw new Error("Session expired!");
}

This means the seals expiration is effectively createdAt + maxAge

If the expiration should be based on createdAt why not change the seal logic? and remove the unseal logic

This current logic makes setting an expiration based on inactivity impossible (sliding expiration)

Users logs in and gets session with maxAge of 15min. User stays active for 15min and will get locked out as both the cookie is expired and the unsealSession fails (the iron unseal goes through as the logic is different to the h3 unseal logic)

What I want is: User logs in and gets session with maxAge of 15min. Users stays active, and session gets resealed on every api call (which updates the expiration to now + maxAge). users gets inactive. If active again after 15min the cookie and the seal is expired

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions