Skip to content
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(runtime/tls): handle invalid host for connectTls/startTls #9453

Merged
merged 1 commit into from
Feb 11, 2021

Conversation

erik
Copy link
Contributor

@erik erik commented Feb 9, 2021

Tiny fix, converts a process-killing panic into a standard runtime error.

Before:

> await Deno.connectTls({hostname: '8.8.8.8', port: 443})
thread 'main' panicked at 'Invalid DNS lookup: InvalidDNSNameError', runtime/ops/tls.rs:208:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Object({"id": Number(2), "error": Object({"code": Number(-32000), "message": String("Execution context was destroyed.")})})', runtime/inspector.rs:978:8
stack backtrace:
...

After:

> await Deno.connectTls({hostname: '8.8.8.8', port: 443})
Uncaught Error: Invalid DNS lookup
    at processResponse (deno:core/core.js:213:11)
    at Object.jsonOpAsync (deno:core/core.js:230:12)
    at async Object.connectTls (deno:runtime/js/40_tls.js:32:17)
    at async <anonymous>:2:1

Fixes #9452.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lucacasonato
Copy link
Member

I'm not to happy about it being a generic Error - anyone have any suggestions what Deno.errors error could be used instead?

@erik
Copy link
Contributor Author

erik commented Feb 9, 2021

There are a few other generic error references in the function already. If there's a good alternative available, I can update those as well

let dnsname =
DNSNameRef::try_from_ascii_str(&domain).expect("Invalid DNS lookup");
let dnsname = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|_| generic_error("Invalid DNS lookup"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you actually put the original rust error message into the generic_error too? Debugging the error in the JS side is very hard otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucacasonato so in this case it seems there isn't a good rust error message to base it off of.

See here for the error type we're looking at: https://briansmith.org/rustdoc/src/webpki/name.rs.html#77-82

I could update the generic error message if you have a more clear message in mind.

let dnsname =
DNSNameRef::try_from_ascii_str(&domain).expect("Invalid DNS lookup");
let dnsname = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|_| generic_error("Invalid DNS lookup"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erik is right that InvalidDNSNameError provides no further context. I suggest merging this as-is.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM then

@bnoordhuis bnoordhuis merged commit a097c40 into denoland:master Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deno.connectTls panics when given invalid hostname
4 participants