• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

expressjs / cookie-parser / 19000067557

01 Nov 2025 05:17PM UTC coverage: 100.0%. Remained the same
19000067557

Pull #149

github

web-flow
build(deps): bump actions/upload-artifact from 4.6.2 to 5.0.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.2 to 5.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/ea165f8d6...330a01c49)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #149: build(deps): bump actions/upload-artifact from 4.6.2 to 5.0.0

31 of 32 branches covered (96.88%)

55 of 55 relevant lines covered (100.0%)

291.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/index.js
1
/*!
2
 * cookie-parser
3
 * Copyright(c) 2014 TJ Holowaychuk
4
 * Copyright(c) 2015 Douglas Christopher Wilson
5
 * MIT Licensed
6
 */
7

8
'use strict'
9

10
/**
11
 * Module dependencies.
12
 * @private
13
 */
14

15
var cookie = require('cookie')
24✔
16
var signature = require('cookie-signature')
24✔
17

18
/**
19
 * Module exports.
20
 * @public
21
 */
22

23
module.exports = cookieParser
24✔
24
module.exports.JSONCookie = JSONCookie
24✔
25
module.exports.JSONCookies = JSONCookies
24✔
26
module.exports.signedCookie = signedCookie
24✔
27
module.exports.signedCookies = signedCookies
24✔
28

29
/**
30
 * Parse Cookie header and populate `req.cookies`
31
 * with an object keyed by the cookie names.
32
 *
33
 * @param {string|array} [secret] A string (or array of strings) representing cookie signing secret(s).
34
 * @param {Object} [options]
35
 * @return {Function}
36
 * @public
37
 */
38

39
function cookieParser (secret, options) {
40
  var secrets = !secret || Array.isArray(secret)
264✔
41
    ? (secret || [])
120✔
42
    : [secret]
43

44
  return function cookieParser (req, res, next) {
264✔
45
    if (req.cookies) {
312✔
46
      return next()
24✔
47
    }
48

49
    var cookies = req.headers.cookie
288✔
50

51
    req.secret = secrets[0]
288✔
52
    req.cookies = Object.create(null)
288✔
53
    req.signedCookies = Object.create(null)
288✔
54

55
    // no cookies
56
    if (!cookies) {
288✔
57
      return next()
48✔
58
    }
59

60
    req.cookies = cookie.parse(cookies, options)
240✔
61

62
    // parse signed cookies
63
    if (secrets.length !== 0) {
240✔
64
      req.signedCookies = signedCookies(req.cookies, secrets)
192✔
65
      req.signedCookies = JSONCookies(req.signedCookies)
192✔
66
    }
67

68
    // parse JSON cookies
69
    req.cookies = JSONCookies(req.cookies)
240✔
70

71
    next()
240✔
72
  }
73
}
74

75
/**
76
 * Parse JSON cookie string.
77
 *
78
 * @param {String} str
79
 * @return {Object} Parsed object or undefined if not json cookie
80
 * @public
81
 */
82

83
function JSONCookie (str) {
84
  if (typeof str !== 'string' || str.substr(0, 2) !== 'j:') {
600✔
85
    return undefined
504✔
86
  }
87

88
  try {
96✔
89
    return JSON.parse(str.slice(2))
96✔
90
  } catch (err) {
91
    return undefined
48✔
92
  }
93
}
94

95
/**
96
 * Parse JSON cookies.
97
 *
98
 * @param {Object} obj
99
 * @return {Object}
100
 * @public
101
 */
102

103
function JSONCookies (obj) {
104
  var cookies = Object.keys(obj)
432✔
105
  var key
106
  var val
107

108
  for (var i = 0; i < cookies.length; i++) {
432✔
109
    key = cookies[i]
312✔
110
    val = JSONCookie(obj[key])
312✔
111

112
    if (val) {
312✔
113
      obj[key] = val
24✔
114
    }
115
  }
116

117
  return obj
432✔
118
}
119

120
/**
121
 * Parse a signed cookie string, return the decoded value.
122
 *
123
 * @param {String} str signed cookie string
124
 * @param {string|array} secret
125
 * @return {String} decoded value
126
 * @public
127
 */
128

129
function signedCookie (str, secret) {
130
  if (typeof str !== 'string') {
840✔
131
    return undefined
144✔
132
  }
133

134
  if (str.substr(0, 2) !== 's:') {
696✔
135
    return str
264✔
136
  }
137

138
  var secrets = !secret || Array.isArray(secret)
432✔
139
    ? (secret || [])
264!
140
    : [secret]
141

142
  for (var i = 0; i < secrets.length; i++) {
432✔
143
    var val = signature.unsign(str.slice(2), secrets[i])
528✔
144

145
    if (val !== false) {
528✔
146
      return val
312✔
147
    }
148
  }
149

150
  return false
120✔
151
}
152

153
/**
154
 * Parse signed cookies, returning an object containing the decoded key/value
155
 * pairs, while removing the signed key from obj.
156
 *
157
 * @param {Object} obj
158
 * @param {string|array} secret
159
 * @return {Object}
160
 * @public
161
 */
162

163
function signedCookies (obj, secret) {
164
  var cookies = Object.keys(obj)
408✔
165
  var dec
166
  var key
167
  var ret = Object.create(null)
408✔
168
  var val
169

170
  for (var i = 0; i < cookies.length; i++) {
408✔
171
    key = cookies[i]
504✔
172
    val = obj[key]
504✔
173
    dec = signedCookie(val, secret)
504✔
174

175
    if (val !== dec) {
504✔
176
      ret[key] = dec
312✔
177
      delete obj[key]
312✔
178
    }
179
  }
180

181
  return ret
408✔
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc