Skip to content

Commit 4dec249

Browse files
authored
Merge pull request #194 from splunk/VULN-25848
Vuln 25848
2 parents b001500 + 7c7c1fa commit 4dec249

File tree

5 files changed

+1196
-902
lines changed

5 files changed

+1196
-902
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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+
39
## v2.0.0
410

511
### New features and APIs

client/splunk.js

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

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

2343523434
/**
23436-
* RegExp to match field-content in RFC 7230 sec 3.2
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.
2343723438
*
23438-
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
23439-
* field-vchar = VCHAR / obs-text
23440-
* obs-text = %x80-FF
23439+
* cookie-name = token
23440+
* token = 1*tchar
23441+
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
23442+
* "*" / "+" / "-" / "." / "^" / "_" /
23443+
* "`" / "|" / "~" / DIGIT / ALPHA
2344123444
*/
2344223445

23443-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
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]*$/;
2344423489

2344523490
/**
2344623491
* Parse a cookie header.
@@ -23459,43 +23504,80 @@ function parse(str, options) {
2345923504
throw new TypeError('argument str must be a string');
2346023505
}
2346123506

23462-
var obj = {}
23463-
var opt = options || {};
23464-
var pairs = str.split(';')
23465-
var dec = opt.decode || decode;
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;
2346623512

23467-
for (var i = 0; i < pairs.length; i++) {
23468-
var pair = pairs[i];
23469-
var index = pair.indexOf('=')
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+
}
2347023525

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

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

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

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

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

2349123557
return obj;
2349223558
}
2349323559

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+
2349423576
/**
2349523577
* Serialize data into a cookie header.
2349623578
*
23497-
* Serialize the a name value pair into a cookie string suitable for
23498-
* http headers. An optional options object specified cookie parameters.
23579+
* Serialize a name value pair into a cookie string suitable for
23580+
* http headers. An optional options object specifies cookie parameters.
2349923581
*
2350023582
* serialize('foo', 'bar', { httpOnly: true })
2350123583
* => "foo=bar; httpOnly"
@@ -23515,13 +23597,13 @@ function serialize(name, val, options) {
2351523597
throw new TypeError('option encode is invalid');
2351623598
}
2351723599

23518-
if (!fieldContentRegExp.test(name)) {
23600+
if (!cookieNameRegExp.test(name)) {
2351923601
throw new TypeError('argument name is invalid');
2352023602
}
2352123603

2352223604
var value = enc(val);
2352323605

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

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

23533-
if (isNaN(maxAge) || !isFinite(maxAge)) {
23615+
if (!isFinite(maxAge)) {
2353423616
throw new TypeError('option maxAge is invalid')
2353523617
}
2353623618

2353723619
str += '; Max-Age=' + Math.floor(maxAge);
2353823620
}
2353923621

2354023622
if (opt.domain) {
23541-
if (!fieldContentRegExp.test(opt.domain)) {
23623+
if (!domainValueRegExp.test(opt.domain)) {
2354223624
throw new TypeError('option domain is invalid');
2354323625
}
2354423626

2354523627
str += '; Domain=' + opt.domain;
2354623628
}
2354723629

2354823630
if (opt.path) {
23549-
if (!fieldContentRegExp.test(opt.path)) {
23631+
if (!pathValueRegExp.test(opt.path)) {
2355023632
throw new TypeError('option path is invalid');
2355123633
}
2355223634

2355323635
str += '; Path=' + opt.path;
2355423636
}
2355523637

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

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

2356423648
if (opt.httpOnly) {
@@ -23569,6 +23653,30 @@ function serialize(name, val, options) {
2356923653
str += '; Secure';
2357023654
}
2357123655

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+
2357223680
if (opt.sameSite) {
2357323681
var sameSite = typeof opt.sameSite === 'string'
2357423682
? opt.sameSite.toLowerCase() : opt.sameSite;
@@ -23594,6 +23702,42 @@ function serialize(name, val, options) {
2359423702
return str;
2359523703
}
2359623704

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+
2359723741
/**
2359823742
* Try decoding a string using a decoding function.
2359923743
*
@@ -29041,7 +29185,7 @@ module.exports={
2904129185
"_args": [
2904229186
[
2904329187
"elliptic@6.5.4",
29044-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
29188+
"/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript"
2904529189
]
2904629190
],
2904729191
"_development": true,
@@ -29067,7 +29211,7 @@ module.exports={
2906729211
],
2906829212
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
2906929213
"_spec": "6.5.4",
29070-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
29214+
"_where": "/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript",
2907129215
"author": {
2907229216
"name": "Fedor Indutny",
2907329217
"email": "fedor@indutny.com"
@@ -39534,7 +39678,7 @@ module.exports={
3953439678
"_args": [
3953539679
[
3953639680
"needle@3.0.0",
39537-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
39681+
"/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript"
3953839682
]
3953939683
],
3954039684
"_from": "needle@3.0.0",
@@ -39560,13 +39704,13 @@ module.exports={
3956039704
],
3956139705
"_resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz",
3956239706
"_spec": "3.0.0",
39563-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
39707+
"_where": "/Users/sjaskowski/PycharmProjects/splunk-sdk-javascript",
3956439708
"author": {
3956539709
"name": "Tomás Pollak",
3956639710
"email": "tomas@forkhq.com"
3956739711
},
3956839712
"bin": {
39569-
"needle": "./bin/needle"
39713+
"needle": "bin/needle"
3957039714
},
3957139715
"bugs": {
3957239716
"url": "https://github.com/tomas/needle/issues"
@@ -55397,7 +55541,7 @@ module.exports={
5539755541
"test": "nyc mocha tests/tests.js -t 50000 --allow-uncaught --exit --reporter mochawesome"
5539855542
},
5539955543
"dependencies": {
55400-
"cookie": "0.4.2",
55544+
"cookie": "0.7.0",
5540155545
"dotenv": "16.0.0",
5540255546
"elementtree": "0.1.7",
5540355547
"needle": "3.0.0"

0 commit comments

Comments
 (0)