-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
dns: consistency; performance on malicious input #20445
Changes from 3 commits
cd73836
fc93b59
03451b4
ae34731
260ee07
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 |
---|---|---|
|
@@ -62,6 +62,32 @@ assert(existing.length > 0); | |
]); | ||
} | ||
|
||
{ | ||
// Various invalidities, all of which should throw a clean error. | ||
const invalidServers = [ | ||
' ', | ||
'\n', | ||
'\0', | ||
'1'.repeat(3 * 4), | ||
// Check for REDOS issues. | ||
':'.repeat(100000), | ||
'['.repeat(100000), | ||
'['.repeat(100000) + ']'.repeat(100000) + 'a' | ||
]; | ||
invalidServers.forEach((serv) => { | ||
assert.throws( | ||
() => { | ||
dns.setServers([serv]) | ||
}, | ||
{ | ||
name: 'TypeError [ERR_INVALID_IP_ADDRESS]', | ||
code: 'ERR_INVALID_IP_ADDRESS' | ||
}, | ||
`Unexpected error thrown for serv '${serv}'` | ||
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. Nit: It would seem that the most likely case for this assertion to fire is that AssertionError [ERR_ASSERTION]: Missing expected exception: Unexpected error thrown for serv Someone seeing this message may be misled by "Unexpected error thrown" if the reason for the Especially given that a few of assert.throws(
() => {
dns.setServers([serv]);
},
{
name: 'TypeError [ERR_INVALID_IP_ADDRESS]',
code: 'ERR_INVALID_IP_ADDRESS'
}
); ...then the default message would display and that one is pretty clear I think: AssertionError [ERR_ASSERTION]: Missing expected exception. It also improves the output when the wrong error is thrown: AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual
Comparison {
- name: 'RangeError',
- code: 'ERR_OOPS'
+ name: 'TypeError [ERR_INVALID_IP_ADDRESS]',
+ code: 'ERR_INVALID_IP_ADDRESS'
} With the code currently in this branch/PR, the user would get this instead: AssertionError [ERR_ASSERTION]: Unexpected error thrown for serv |
||
); | ||
}); | ||
} | ||
|
||
const goog = [ | ||
'8.8.8.8', | ||
'8.8.4.4', | ||
|
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.
Can you explain the default value here? That is something unexpected for me.
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.
addrSplitMatch[2]
might be undefined (see #20441), in which case I figured the port should be 53 (DNS port).I think this is consistent with existing cases where a default port is selected, e.g. here and here.
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.
@bnoordhuis @apapirovski PTAL
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.
I think it should be fine.
parseInt('')
works out to 0 when coerced to int32 and c-ares uses the default port in that case. IOW, there should be no observable change in behavior, it'll use port 53 either way.