Skip to content

[Lazarus revival] fix(res): handle null maxAge gracefully in res.cookie() and updated the dependency "cookie" to the 1.0.2 latest version - #1

Draft
kax168 wants to merge 2 commits into
masterfrom
lazarus/revive-6875
Draft

[Lazarus revival] fix(res): handle null maxAge gracefully in res.cookie() and updated the dependency "cookie" to the 1.0.2 latest version#1
kax168 wants to merge 2 commits into
masterfrom
lazarus/revive-6875

Conversation

@kax168

@kax168 kax168 commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Maintainer Briefing: fix(res): handle null maxAge gracefully in res.cookie() and updated the dependency "cookie" to the 1.0.2 latest version

What this PR was trying to do

Normalize res.cookie() options so an explicit maxAge: null produces a session cookie without Expires or Max-Age, while retaining existing handling for numeric values. The PR also proposes upgrading the direct cookie dependency to 1.0.2.

What changed in the repo since it died

The repository has advanced substantially, including several response-related changes, dependency upgrades, and additional tests. No listed intervening commit directly addresses null maxAge handling. The baseline did not merge cleanly and had 1,237 passing tests with one unrelated acceptance-test failure.

What Lazarus changed to revive it

The revived branch merges cleanly and npm test reports 1,260 passing tests. A follow-up commit, 284b82a9, changes res.sendFile() to pass absolute paths as a basename plus parent root, avoiding dotfile-parent rejection by send@1.2.1; targeted res.sendFile() tests and lint were also reported as passing. The supplied log does not show the revived cookie normalization, dependency-version diff, or associated test changes, so their exact final implementation is unavailable.

Test evidence

Evidence Before After
Tests detected Yes Yes
Test command npm test npm test
Tests passed No Yes
Merge clean No Yes

Risk assessment

The intended cookie behavior is narrowly scoped, but the dependency upgrade may alter serialization or validation beyond maxAge: null; evidence for those exact changes is unavailable. The additional res.sendFile() change is unrelated to the PR’s cookie purpose and affects absolute-path handling, so it warrants separate maintainer review despite the clean full test run.

Credits

Originally contributed by @SaisakthiM.


Original PR: expressjs#6875
Original author: @SaisakthiM

SaisakthiM and others added 2 commits July 19, 2026 01:18
This pull request fixes an edge case in res.cookie() where specifying maxAge: null caused the function to produce incorrect cookie headers or throw an internal error.

Previously, maxAge: null was not normalized and led to unintended conversion to 0, causing an undesired Expires header (Max-Age=0).
This behavior conflicted with Express’s intended semantics, where null should mean “no expiration — session cookie”.

✅ Updated Behavior

When maxAge is explicitly null, it is now normalized to undefined.

The cookie is serialized without Expires or Max-Age fields (consistent with session cookies).

Existing logic for finite and numeric maxAge values remains unchanged.

All test cases, including res.cookie(name, string, options) maxAge should not throw on null, now pass successfully.

⚙️ Implementation Summary

In lib/response.js, the logic under res.cookie() was updated:

if (opts.maxAge === null) {
  opts.maxAge = undefined;
}

This ensures that null values are excluded from expiration logic.

✅ Test Results

All 1,238 tests pass locally:

  1238 passing (11s)
  0 failing

🧩 Motivation

This change improves compatibility with earlier Express 4.x behavior, aligns with the HTTP cookie specification for session cookies, and maintains backward compatibility with existing user code.
@SaisakthiM

Copy link
Copy Markdown

thanks, i left the PR it was idle for a long time thanks for the fix

@kax168

kax168 commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Hey @SaisakthiM — thank you. This PR is exactly why I built the tool.

It's called Lazarus, a project for OpenAI Build Week: it finds open-source pull requests that went stale (merge conflicts, the base branch moving on, maintainers getting busy) and uses an OpenAI Codex agent to rebase them onto the current code, resolve the conflicts, and get the tests green again — then opens a fresh PR crediting the original author.

Your null-maxAge fix was one of the ones it revived: it rebased onto today's master, handled the cookie 1.0.2 dependency jump, and the suite went from conflicted to 1260 passing / 0 failing. You did the real work months ago; the tool just made sure it didn't get lost.

Honestly, your "it was idle for a long time, thanks for the fix" comment means more than any test result — that's the whole reason the project exists. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants