Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function JSONCookies (obj) {
key = cookies[i]
val = JSONCookie(obj[key])

if (val) {
if (val !== undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve the invalid-signature sentinel for signed JSON false. The middleware runs JSONCookies() over req.signedCookies after verification (lines 64–65), while signedCookie() and the README use boolean false to signal a failed signature. With this condition, a correctly signed j:false payload is also converted to boolean false. I reproduced both a valid cookie created with cookie-signature.sign('j:false', secret) and the same cookie with a corrupted signature; req.signedCookies.flag is false in both cases, so callers can no longer distinguish authentic data from signature failure—the exact ambiguity raised in issue #168. Please resolve that representation/API conflict before parsing false here, and add a middleware-level test covering valid j:false versus a tampered signed cookie.

obj[key] = val
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/cookieParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ describe('cookieParser.JSONCookie(str)', function () {
})
})

describe('cookieParser.JSONCookies(obj)', function () {
it('should parse JSON cookie values, including falsy ones', function () {
assert.deepEqual(cookieParser.JSONCookies({
f: 'j:false',
z: 'j:0',
e: 'j:""',
n: 'j:null'
}), { f: false, z: 0, e: '', n: null })
})

it('should leave non-JSON cookie values untouched', function () {
assert.deepEqual(cookieParser.JSONCookies({ a: 'bar', b: 'j:{foo:"bar"}' }), { a: 'bar', b: 'j:{foo:"bar"}' })
})
})

describe('cookieParser.signedCookie(str, secret)', function () {
it('should return undefined for non-string arguments', function () {
assert.strictEqual(cookieParser.signedCookie(undefined, 'keyboard cat'), undefined)
Expand Down