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 cf6debd
Show file tree
Hide file tree
Showing 2 changed files with 13 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
9 changes: 9 additions & 0 deletions lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ function isInstanceStrict(data, prototype) {
}
}

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

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

0 comments on commit cf6debd

Please sign in to comment.