Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore expires and maxAge in res.clearCookie() #5792

Merged
merged 7 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ unreleased
* `res.status()` accepts only integers, and input must be greater than 99 and less than 1000
* will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range
* will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs
* change:
- `res.clearCookie` ignore user provided `maxAge` and `expires` options
jonchurch marked this conversation as resolved.
Show resolved Hide resolved

5.0.0-beta.3 / 2024-03-25
=========================
Expand Down
5 changes: 4 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,10 @@ res.get = function(field){
*/

res.clearCookie = function clearCookie(name, options) {
var opts = merge({ expires: new Date(1), path: '/' }, options);
// Force cookie expiration by setting expires to the past
const opts = Object.assign({ path: '/' } , options, { expires: new Date(1) })
jonchurch marked this conversation as resolved.
Show resolved Hide resolved
// ensure maxAge is not passed
delete opts.maxAge

return this.cookie(name, '', opts);
};
Expand Down
26 changes: 26 additions & 0 deletions test/res.clearCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,31 @@ describe('res', function(){
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})

it('should ignore maxAge', function(done){
var app = express();

app.use(function(req, res){
res.clearCookie('sid', { path: '/admin', maxAge: 1000 }).end();
});

request(app)
.get('/')
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})

it('should ignore user supplied expires param', function(done){
var app = express();

app.use(function(req, res){
res.clearCookie('sid', { path: '/admin', expires: new Date() }).end();
});

request(app)
.get('/')
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})
})
})
Loading