Skip to content

Commit

Permalink
Fix incorrect string validation for URL
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Jan 6, 2023
1 parent b1a8898 commit 90f2b38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ class CookieJar {
}

setCookie(cookie, url, options, cb) {
validators.validate(validators.isNonEmptyString(url), cb, options);
validators.validate(validators.isUrlStringOrObject(url), cb, options);

let err;

if (validators.isFunction(url)) {
Expand Down Expand Up @@ -1314,7 +1315,8 @@ class CookieJar {

// RFC6365 S5.4
getCookies(url, options, cb) {
validators.validate(validators.isNonEmptyString(url), cb, url);
validators.validate(validators.isUrlStringOrObject(url), cb, url);

const context = getCookieContext(url);
if (validators.isFunction(options)) {
cb = options;
Expand Down
5 changes: 5 additions & 0 deletions lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function isInstanceStrict(data, prototype) {
}
}

function isUrlStringOrObject(data) {
return isNonEmptyString(data) || isObject(data); // TODO: Check for URL properties that are used.
}

function isInteger(data) {
return typeof data === "number" && data % 1 === 0;
}
Expand Down Expand Up @@ -92,4 +96,5 @@ exports.isDate = isDate;
exports.isEmptyString = isEmptyString;
exports.isString = isString;
exports.isObject = isObject;
exports.isUrlStringOrObject = isUrlStringOrObject;
exports.validate = validate;

0 comments on commit 90f2b38

Please sign in to comment.