ar-io/ar-io-node

TypeError due to subdomain logic

Closed this issue · 1 comments

When I specify an ARNS_ROOT_HOST that includes a subdomain and then try to query that node from localhost, I receive:

$ curl localhost:4000/ar-io/healthcheck
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Internal Server Error</pre>
</body>
</html>

I notice in middleware/arns.ts that if ROOT_HOST_SUBDOMAIN_LENGTH is greater than req.subdomains.length (true when requesting from localhost), it is possible for arnsSubdomain to evaluate to undefined.

If arnsSubdomain is undefined, then

(arnsSubdomain.length > 48 && !arnsSubdomain.match(/_/))

results in TypeError: Cannot read properties of undefined (reading 'length').

Potential fix: return early if req.subdomains.length is also less than ROOT_HOST_SUBDOMAIN_LENGTH

Thanks for the very well written issue! We'll fix this up in the next release.