Skip to content

DNS_REGEX Can Hang Node Process #1359

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
astorm opened this issue Apr 14, 2020 · 0 comments · Fixed by #1364
Closed

DNS_REGEX Can Hang Node Process #1359

astorm opened this issue Apr 14, 2020 · 0 comments · Fixed by #1364

Comments

@astorm
Copy link

astorm commented Apr 14, 2020

Problem description

We noticed that it's possible to hang (or seemingly hang) the entire node process with some common (if invalid) hostname/endpoint values. We discovered this while writing some validation code for our own hostname/endpoint values. This was with the grpc@grpc-js project.

The problem seems to be this regular expression

const DNS_REGEX = /^(?:dns:)?(?:\/\/(?:[a-zA-Z0-9-]+\.?)+\/)?((?:[a-zA-Z0-9-]+\.?)+)(?::(\d+))?$/;

and its execution here

const dnsMatch = DNS_REGEX.exec(target);

Reproduction steps

We can reproduce the problem we saw with the behavior of @grpc/grpc-js via this small program. Happy to put together a reproduction with @grpc/grpc-js if you'all think that would be helpful.

const main = () => {
  // host name with an extra port accidentally left on 
  const target = 'foo-internal.aws-us-east-2.tracing.staging-edge.foo-data.net:443:443'
  const DNS_REGEX = /^(?:dns:)?(?:\/\/(?:[a-zA-Z0-9-]+\.?)+\/)?((?:[a-zA-Z0-9-]+\.?)+)(?::(\d+))?$/
  DNS_REGEX.exec(target)
}
main()

The hostname foo-internal.aws-us-east-2.tracing.staging-edge.foo-data.net seems pathologic, but it's based on a legitimate hostname we've been asked to use.

Steps:

  1. Run the above program with NodeJS 8, 10, or 12

Expected Behavior: Program exits normally

Actual Behavior: Program hangs for at least 2 minutes, likely longer

Environment

  • MacOS 10.13/10.14and Ubuntu 18.04
  • Nodes 8, 10, and 12
  • Nodes 10 and 12 installed via nvm, Node 8 installed via apt-get install nodejs
  • grpc/grpc-js@0.8.1

Additional context

Something something NFA backtracking.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant