-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix password and username in http.url #5038
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,15 +340,25 @@ export const getRequestInfo = ( | |
|
||
/** | ||
* Makes sure options is of type string or object | ||
* If a string, make sure the URL has no authentication credentials (username/password) | ||
* @param options for the request | ||
*/ | ||
|
||
export const isValidOptionsType = (options: unknown): boolean => { | ||
if (!options) { | ||
return false; | ||
} | ||
|
||
const type = typeof options; | ||
return type === 'string' || (type === 'object' && !Array.isArray(options)); | ||
|
||
if (type === 'string') { | ||
const parsedUrl = url.parse(options as string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost this line could throw and also is discouraged due to security issues. The replacement would be then function parseUrl(input: string): URL | null {
if (URL.parse) {
return URL.parse(input);
}
try {
return url.parse(input);
} catch {}
return null;
} and use it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I’ll extract the logic into a utility function to handle the compatibility and update the PR shortly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the util function should be as follows, avoid using the deprecated // This is identical to `URL.parse`.
function parseUrl(input: string, base?: string): URL | null {
try {
return new URL(input, base);
} catch {}
return null;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @david-luna @legendecas this was recently the source a of a bug report #5060 - I opened a PR #5091 that may conflict with this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @legendecas using the constructor seems a better solution in terms of version support :)
This means for Node.js <v18.17.0 all strings will be considered valid so for these versions the fix wont apply. I wonder if it's okay to have this partial fix/support 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I withdraw this part. I looked in the wrong place in the documentation. The |
||
if (!parsedUrl.auth) { | ||
return true; | ||
} | ||
} | ||
|
||
return type === 'object' && !Array.isArray(options); | ||
}; | ||
|
||
export const extractHostnameAndPort = ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,7 +281,15 @@ describe('Utility', () => { | |
}); | ||
|
||
describe('isValidOptionsType()', () => { | ||
['', false, true, 1, 0, []].forEach(options => { | ||
[ | ||
'', | ||
false, | ||
true, | ||
1, | ||
0, | ||
'https://username:[email protected]/', | ||
[], | ||
].forEach(options => { | ||
it(`should return false with the following value: ${JSON.stringify( | ||
options | ||
)}`, () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to update this function description to better represent the new logic added in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks
I will do that