Skip to content

Commit e57b31e

Browse files
authored
Merge pull request #193 from splunk/revert-190-VULN-25848
Revert "Upgrade 'cookie' npm package to 0.7.0"
2 parents 5b48d60 + 017c630 commit e57b31e

File tree

5 files changed

+902
-1196
lines changed

5 files changed

+902
-1196
lines changed

CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# Splunk Enterprise SDK for JavaScript Changelog
22

3-
4-
## v2.0.1
5-
6-
### Minor changes
7-
* Upgrade 'cookie' npm package to 0.7.0 ([PR#161](https://github.com/splunk/splunk-sdk-javascript/pull/190))
8-
93
## v2.0.0
104

115
### New features and APIs

client/splunk.js

Lines changed: 38 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -23429,63 +23429,18 @@ exports.serialize = serialize;
2342923429
* @private
2343023430
*/
2343123431

23432-
var __toString = Object.prototype.toString
23432+
var decode = decodeURIComponent;
23433+
var encode = encodeURIComponent;
2343323434

2343423435
/**
23435-
* RegExp to match cookie-name in RFC 6265 sec 4.1.1
23436-
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
23437-
* which has been replaced by the token definition in RFC 7230 appendix B.
23436+
* RegExp to match field-content in RFC 7230 sec 3.2
2343823437
*
23439-
* cookie-name = token
23440-
* token = 1*tchar
23441-
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
23442-
* "*" / "+" / "-" / "." / "^" / "_" /
23443-
* "`" / "|" / "~" / DIGIT / ALPHA
23438+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
23439+
* field-vchar = VCHAR / obs-text
23440+
* obs-text = %x80-FF
2344423441
*/
2344523442

23446-
var cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
23447-
23448-
/**
23449-
* RegExp to match cookie-value in RFC 6265 sec 4.1.1
23450-
*
23451-
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
23452-
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
23453-
* ; US-ASCII characters excluding CTLs,
23454-
* ; whitespace DQUOTE, comma, semicolon,
23455-
* ; and backslash
23456-
*/
23457-
23458-
var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/;
23459-
23460-
/**
23461-
* RegExp to match domain-value in RFC 6265 sec 4.1.1
23462-
*
23463-
* domain-value = <subdomain>
23464-
* ; defined in [RFC1034], Section 3.5, as
23465-
* ; enhanced by [RFC1123], Section 2.1
23466-
* <subdomain> = <label> | <subdomain> "." <label>
23467-
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
23468-
* Labels must be 63 characters or less.
23469-
* 'let-dig' not 'letter' in the first char, per RFC1123
23470-
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
23471-
* <let-dig-hyp> = <let-dig> | "-"
23472-
* <let-dig> = <letter> | <digit>
23473-
* <letter> = any one of the 52 alphabetic characters A through Z in
23474-
* upper case and a through z in lower case
23475-
* <digit> = any one of the ten digits 0 through 9
23476-
*/
23477-
23478-
var domainValueRegExp = /^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
23479-
23480-
/**
23481-
* RegExp to match path-value in RFC 6265 sec 4.1.1
23482-
*
23483-
* path-value = <any CHAR except CTLs or ";">
23484-
* CHAR = %x01-7F
23485-
* ; defined in RFC 5234 appendix B.1
23486-
*/
23487-
23488-
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
23443+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
2348923444

2349023445
/**
2349123446
* Parse a cookie header.
@@ -23504,80 +23459,43 @@ function parse(str, options) {
2350423459
throw new TypeError('argument str must be a string');
2350523460
}
2350623461

23507-
var obj = {};
23508-
var len = str.length;
23509-
// RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
23510-
var max = len - 2;
23511-
if (max < 0) return obj;
23512-
23513-
var dec = (options && options.decode) || decode;
23514-
var index = 0;
23515-
var eqIdx = 0;
23516-
var endIdx = 0;
23517-
23518-
do {
23519-
eqIdx = str.indexOf('=', index);
23520-
23521-
// no more cookie pairs
23522-
if (eqIdx === -1) {
23523-
break;
23524-
}
23462+
var obj = {}
23463+
var opt = options || {};
23464+
var pairs = str.split(';')
23465+
var dec = opt.decode || decode;
2352523466

23526-
endIdx = str.indexOf(';', index);
23467+
for (var i = 0; i < pairs.length; i++) {
23468+
var pair = pairs[i];
23469+
var index = pair.indexOf('=')
2352723470

23528-
if (endIdx === -1) {
23529-
endIdx = len;
23530-
} else if (eqIdx > endIdx) {
23531-
// backtrack on prior semicolon
23532-
index = str.lastIndexOf(';', eqIdx - 1) + 1;
23471+
// skip things that don't look like key=value
23472+
if (index < 0) {
2353323473
continue;
2353423474
}
2353523475

23536-
var keyStartIdx = startIndex(str, index, eqIdx);
23537-
var keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
23538-
var key = str.slice(keyStartIdx, keyEndIdx);
23476+
var key = pair.substring(0, index).trim()
2353923477

2354023478
// only assign once
23541-
if (undefined === obj[key]) {
23542-
var valStartIdx = startIndex(str, eqIdx + 1, endIdx);
23543-
var valEndIdx = endIndex(str, endIdx, valStartIdx);
23479+
if (undefined == obj[key]) {
23480+
var val = pair.substring(index + 1, pair.length).trim()
2354423481

23545-
if (str.charCodeAt(valStartIdx) === 0x22 /* " */ && str.charCodeAt(valEndIdx - 1) === 0x22 /* " */) {
23546-
valStartIdx++;
23547-
valEndIdx--;
23482+
// quoted values
23483+
if (val[0] === '"') {
23484+
val = val.slice(1, -1)
2354823485
}
2354923486

23550-
var val = str.slice(valStartIdx, valEndIdx);
2355123487
obj[key] = tryDecode(val, dec);
2355223488
}
23553-
23554-
index = endIdx + 1
23555-
} while (index < max);
23489+
}
2355623490

2355723491
return obj;
2355823492
}
2355923493

23560-
function startIndex(str, index, max) {
23561-
do {
23562-
var code = str.charCodeAt(index);
23563-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index;
23564-
} while (++index < max);
23565-
return max;
23566-
}
23567-
23568-
function endIndex(str, index, min) {
23569-
while (index > min) {
23570-
var code = str.charCodeAt(--index);
23571-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index + 1;
23572-
}
23573-
return min;
23574-
}
23575-
2357623494
/**
2357723495
* Serialize data into a cookie header.
2357823496
*
23579-
* Serialize a name value pair into a cookie string suitable for
23580-
* http headers. An optional options object specifies cookie parameters.
23497+
* Serialize the a name value pair into a cookie string suitable for
23498+
* http headers. An optional options object specified cookie parameters.
2358123499
*
2358223500
* serialize('foo', 'bar', { httpOnly: true })
2358323501
* => "foo=bar; httpOnly"
@@ -23597,13 +23515,13 @@ function serialize(name, val, options) {
2359723515
throw new TypeError('option encode is invalid');
2359823516
}
2359923517

23600-
if (!cookieNameRegExp.test(name)) {
23518+
if (!fieldContentRegExp.test(name)) {
2360123519
throw new TypeError('argument name is invalid');
2360223520
}
2360323521

2360423522
var value = enc(val);
2360523523

23606-
if (value && !cookieValueRegExp.test(value)) {
23524+
if (value && !fieldContentRegExp.test(value)) {
2360723525
throw new TypeError('argument val is invalid');
2360823526
}
2360923527

@@ -23612,37 +23530,35 @@ function serialize(name, val, options) {
2361223530
if (null != opt.maxAge) {
2361323531
var maxAge = opt.maxAge - 0;
2361423532

23615-
if (!isFinite(maxAge)) {
23533+
if (isNaN(maxAge) || !isFinite(maxAge)) {
2361623534
throw new TypeError('option maxAge is invalid')
2361723535
}
2361823536

2361923537
str += '; Max-Age=' + Math.floor(maxAge);
2362023538
}
2362123539

2362223540
if (opt.domain) {
23623-
if (!domainValueRegExp.test(opt.domain)) {
23541+
if (!fieldContentRegExp.test(opt.domain)) {
2362423542
throw new TypeError('option domain is invalid');
2362523543
}
2362623544

2362723545
str += '; Domain=' + opt.domain;
2362823546
}
2362923547

2363023548
if (opt.path) {
23631-
if (!pathValueRegExp.test(opt.path)) {
23549+
if (!fieldContentRegExp.test(opt.path)) {
2363223550
throw new TypeError('option path is invalid');
2363323551
}
2363423552

2363523553
str += '; Path=' + opt.path;
2363623554
}
2363723555

2363823556
if (opt.expires) {
23639-
var expires = opt.expires
23640-
23641-
if (!isDate(expires) || isNaN(expires.valueOf())) {
23557+
if (typeof opt.expires.toUTCString !== 'function') {
2364223558
throw new TypeError('option expires is invalid');
2364323559
}
2364423560

23645-
str += '; Expires=' + expires.toUTCString()
23561+
str += '; Expires=' + opt.expires.toUTCString();
2364623562
}
2364723563

2364823564
if (opt.httpOnly) {
@@ -23653,30 +23569,6 @@ function serialize(name, val, options) {
2365323569
str += '; Secure';
2365423570
}
2365523571

23656-
if (opt.partitioned) {
23657-
str += '; Partitioned'
23658-
}
23659-
23660-
if (opt.priority) {
23661-
var priority = typeof opt.priority === 'string'
23662-
? opt.priority.toLowerCase()
23663-
: opt.priority
23664-
23665-
switch (priority) {
23666-
case 'low':
23667-
str += '; Priority=Low'
23668-
break
23669-
case 'medium':
23670-
str += '; Priority=Medium'
23671-
break
23672-
case 'high':
23673-
str += '; Priority=High'
23674-
break
23675-
default:
23676-
throw new TypeError('option priority is invalid')
23677-
}
23678-
}
23679-
2368023572
if (opt.sameSite) {
2368123573
var sameSite = typeof opt.sameSite === 'string'
2368223574
? opt.sameSite.toLowerCase() : opt.sameSite;
@@ -23702,42 +23594,6 @@ function serialize(name, val, options) {
2370223594
return str;
2370323595
}
2370423596

23705-
/**
23706-
* URL-decode string value. Optimized to skip native call when no %.
23707-
*
23708-
* @param {string} str
23709-
* @returns {string}
23710-
*/
23711-
23712-
function decode (str) {
23713-
return str.indexOf('%') !== -1
23714-
? decodeURIComponent(str)
23715-
: str
23716-
}
23717-
23718-
/**
23719-
* URL-encode value.
23720-
*
23721-
* @param {string} val
23722-
* @returns {string}
23723-
*/
23724-
23725-
function encode (val) {
23726-
return encodeURIComponent(val)
23727-
}
23728-
23729-
/**
23730-
* Determine if value is a Date.
23731-
*
23732-
* @param {*} val
23733-
* @private
23734-
*/
23735-
23736-
function isDate (val) {
23737-
return __toString.call(val) === '[object Date]' ||
23738-
val instanceof Date
23739-
}
23740-
2374123597
/**
2374223598
* Try decoding a string using a decoding function.
2374323599
*
@@ -29185,7 +29041,7 @@ module.exports={
2918529041
"_args": [
2918629042
[
2918729043
29188-
"/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript"
29044+
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
2918929045
]
2919029046
],
2919129047
"_development": true,
@@ -29211,7 +29067,7 @@ module.exports={
2921129067
],
2921229068
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
2921329069
"_spec": "6.5.4",
29214-
"_where": "/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript",
29070+
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
2921529071
"author": {
2921629072
"name": "Fedor Indutny",
2921729073
"email": "[email protected]"
@@ -39678,7 +39534,7 @@ module.exports={
3967839534
"_args": [
3967939535
[
3968039536
39681-
"/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript"
39537+
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
3968239538
]
3968339539
],
3968439540
"_from": "[email protected]",
@@ -39704,13 +39560,13 @@ module.exports={
3970439560
],
3970539561
"_resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz",
3970639562
"_spec": "3.0.0",
39707-
"_where": "/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript",
39563+
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
3970839564
"author": {
3970939565
"name": "Tomás Pollak",
3971039566
"email": "[email protected]"
3971139567
},
3971239568
"bin": {
39713-
"needle": "bin/needle"
39569+
"needle": "./bin/needle"
3971439570
},
3971539571
"bugs": {
3971639572
"url": "https://github.com/tomas/needle/issues"
@@ -55541,7 +55397,7 @@ module.exports={
5554155397
"test": "nyc mocha tests/tests.js -t 50000 --allow-uncaught --exit --reporter mochawesome"
5554255398
},
5554355399
"dependencies": {
55544-
"cookie": "0.7.0",
55400+
"cookie": "0.4.2",
5554555401
"dotenv": "16.0.0",
5554655402
"elementtree": "0.1.7",
5554755403
"needle": "3.0.0"

0 commit comments

Comments
 (0)