koajs / koajs/session

Session cookie survives (maxAge + zero value bug)

Open
#142 2 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
908
Forks
115
PR merge metrics
No merged PRs in 30d

Description

I'm using `koa-session` with params:
```
{
key: 'sid',
prefix: 'sess:',
httpOnly: true,
path: '/',
overwrite: true,
signed: false,
maxAge: 3600 * 4 * 1e3,
rolling: true
}
```

Session removal does this: `ctx.cookies.set(key, '', opts)`.

Unfortunately, in "cookies" module, `toHeader` has this:

```
if (this.maxAge) this.expires = new Date(Date.now() + this.maxAge);
```

So no value (cookie deletion) actually leads to empty cookie with future expiration.

Contributor guide

Open the contributing guide

Research direction

Start by tracing session removal to the cookies module's toHeader logic shown in the issue, then reproduce deletion with a configured maxAge and an empty value. Confirm whether the fix belongs in this middleware or the cookies dependency; done means removing a session produces a cookie with an expiration that prevents it from surviving.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.