-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
net: validate non-string host for socket.connect
#57198
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
779b979
to
a27f43e
Compare
@@ -1311,6 +1311,8 @@ function lookupAndConnect(self, options) { | |||
const host = options.host || 'localhost'; | |||
let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options; | |||
|
|||
validateString(host, 'options.host'); |
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.
Why don't we just validate this on C++? We could just replace the IsString() assertion.
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.
Good point, but since the net
module has JS layer, validating it in JS seems better for performance. Plus, since other validations are handled in this function, keeping this pattern feels more cohesive.
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.
How come validating it on JS is better? I'm not following.
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.
For simple string validations, JS is typically faster since it avoids crossing the JS/C++ boundary. For complex cases, C++ might be more efficient. Let me know if I'm missing anything.
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.
Right now you are adding a branch to both happy and bad path in the benefit of improving bad path (invalid input).
In terms of performance, validating at the C++ and removing that assertion should be the most optimum solution.
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.
Ah, I get it now. The function where the assertion occurs is also used internally in places other than socket.connect
. In those cases, IsString() assertion seems more appropriate than throwing an exception with option.host
. I'll look into it further.
Signed-off-by: Daeyeon Jeong <[email protected]>
a27f43e
to
7a7ae44
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57198 +/- ##
==========================================
- Coverage 90.33% 90.31% -0.02%
==========================================
Files 630 630
Lines 184513 184515 +2
Branches 36076 36067 -9
==========================================
- Hits 166674 166650 -24
- Misses 10953 10961 +8
- Partials 6886 6904 +18
|
This fixes another issue discovered while reviewing #57112.
Internally,
socket.connect
checks the host string, implicitly coercing an array to a string in the process. That leads to the error below.Signed-off-by: Daeyeon Jeong [email protected]