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 exception when calling resolveTxt with invalid unicode #199

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.27 (2024-07-18)

- Fix error handling when an invalid unicode domain is passed to DnsScraper.

## 2.3.26 (2024-06-17)

- Use oauth API for reddit scraping.
Expand Down
24 changes: 18 additions & 6 deletions lib/scrapers/dns.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keybase-proofs",
"version": "2.3.26",
"version": "2.3.27",
"description": "Publicly-verifiable proofs of identity",
"main": "lib/main.js",
"scripts": {
Expand Down
16 changes: 13 additions & 3 deletions src/scrapers/dns.iced
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ exports.DnsScraper = class DnsScraper extends BaseScraper

# ---------------------------------------------------------------------------

_resolve_txt : (domain, cb) ->
# We can use a DNS library passed in (in the case of native-dns running on
# the server)
dnslib = @libs.dns or dns
try
dnslib.resolveTxt domain, (err, records) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

i didn't realize you could try/catch callback functions like this, cool!

Copy link
Member Author

Choose a reason for hiding this comment

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

you should also be able to do something like

try
   await foo defer err, res
catch err
cb err, res

but is silently broken in iced2 😢 IIRC the code after catch is not emitted at all for some reason

Copy link
Member Author

Choose a reason for hiding this comment

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

This only catches exceptions thrown in the sync part of resolveTxt though, if theres some exception in some callback afterwards, or even in the callback we supply here, it's not going to be caught by the try block.

cb err, records
catch err
cb err

# ---------------------------------------------------------------------------

# calls back with a v_code or null if it was ok
_check_status: ({domain, proof_text_check}, cb) ->
@log "+ DNS check for #{domain}"

# We can use a DNS library passed in (in the case of native-dns running on the server)
dnslib = @libs.dns or dns
await dnslib.resolveTxt domain, defer err, records
await @_resolve_txt domain, defer err, records
rc = if err?
@log "| DNS error: #{err}"
v_codes.DNS_ERROR
Expand Down