-
Notifications
You must be signed in to change notification settings - Fork 31k
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
SNICallback callback doesn't throw an error with invalid input #2126
Comments
cc @indutny |
Upon investigation, it turned out that it actually throws Do we actually want to throw and kill the application? I think - no. cc @nodejs/collaborators @nodejs/crypto |
@indutny Do I understand that this is not a bug in your opinion and can be closed? Or am I misreading? |
I argue that if we're supplying an invalid object, that should fail right away. It has nothing to do with the client. It's a programmer error. |
@Trott this is my opinion indeed. |
@coolaj86 So somewhere around here, do some minimal and fast checking to confirm that Or do you expect it to throw and (probably) crash the server? (Not trolling, honest question, want to make sure I understand what you expect the behavior to be, you mention "throw an error" earlier, but I think you were just being imprecise.) |
I also ran into this and was surprised when my server did not emit an error. If your SNICallback is unable to produce the required credentials, then something important is almost certainly wrong with your program (or perhaps DNS), no? I see that you can catch this by listening for 'tlsClientError' but agree with @coolaj86 that this doesn't seem related to the client. |
To be clear, in my case the SNICallback was actually passing an error to its callback, not just passing an invalid context. Definitely would have expected my program to crash in that case. |
@Trott I like the first idea that you suggest with doing some minimal checking and "throw an error" by calling a callback with an error (or throwing if no error handler exists). |
It seems like perhaps this should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. Here's my reasoning:
|
Could we have the default behavior of unhandled SNICallback errors (or missing SNICallback) to be to print to the console instead of just being swallowed? It's just one of those stupid things that you don't configure very often, but when you get it wrong, it's really non-obvious what's going on. Getting this error in browsers is misleading, not exactly a clear "oh, I know how to fix that!"
|
Unclear to me what "unhandled SNICallback errors" means. If you're talking about programmer bugs - passing an invalid context to the callback - the problem is that Node.js doesn't find out until much later. We could do basic context sanity checks but that won't be exhaustive, it would only catch banal bugs. I'd also worry that a check might turn out too restrictive and close the door on legitimate uses. |
Cases like this: Undefined CallbackMy code: var oops;
tls.createServer({ SNICallback: oops }); Node stays silent. The browser says:
Delima:
Proposed solution: If the first time that If the first call was successful, log every time that they are all missing. A developer at the least should implement Throws an ErrorMy code:
Node stays silent. The browser says:
Delima: If we knew that an error would happen every time, it would be logical to throw and kill the server. However, some errors happen only occasionally (perhaps a bad bot spoofing sni headers). We don't want to crash the server, especially not as new behavior. Proposed solution: Log each error with a stack indicating a specific file and line, and column number exactly once. Bad TLS ContextMy code:
Node stays silent. The browser says:
Delima: I passed an object, not an error. This means that, as far as I know, I've got valid certs but... oops, I did something wrong and have no way of knowing. Maybe this happens every time. Maybe it's something that only happens under certain conditions. Proposed solution: Log the error. Unexpected ErrorMy code:
Delima: Sometimes I'm intentional about passing an error. Sometimes an error is happening somewhere deep, deep down and bubbling up. When my error is intentional, great. But when the error is coming from somewhere I don't expect, I need help. Proposed solution: Log errors just once (matched by file, line, col as mentioned before) that don't match a certain Maybe a built-in error like this:
Or a special property required like this:
Duplicate callbackMy code:
Log that there was a duplicate callback. Error Logging is Ugly!Delima: I don't want to see errors that I don't care about. Proposed solution: Just like unhandled Promises, let the user know in the error message that they should attach some handler(s) to catch the errors to prevent them from logging. Maybe something like this? conn.on('tlsSniError', cb);
conn.on('tlsContextError', cb);
conn.on('tlsDuplicateSniCbError', cb); |
Related somewhat perhaps: #20969 |
This should throw an error:
Instead it succeeds and then the browser barfs.
I was live coding and couldn't figure out in the 30 seconds I just had to wrap my object in
require('crypto').createSecureContext(...)
, so I just used http. :-(If it had thrown an error it would have made the whole world a better place.
The text was updated successfully, but these errors were encountered: