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

Enhanced Nameserver Input Validation #356

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

developStorm
Copy link
Member

@developStorm developStorm commented Mar 2, 2024

The refactored code leverages the built-in net package to perform more rigorous validation of the input nameserver address. It enforces that the input address be a valid IP address, with or without a port.

Tests

// Valid IPv4 address without port
> echo "google.com,1.1.1.1" | go run . -- A
{...,"resolver":"1.1.1.1:53"},"name":"google.com","status":"NOERROR"...}

// Valid IPv4 address with port
> echo "google.com,8.8.8.8:53" | go run . -- A
{...,"resolver":"8.8.8.8:53"},"name":"google.com","status":"NOERROR"...}

// Valid IPv4 address with non-standard port
> echo "google.com,8.8.8.8:5353" | go run . -- A
{"data":{"protocol":"udp","resolver":"8.8.8.8:5353"},"name":"google.com","status":"TIMEOUT"}

// Invalid IP address with port
> echo "google.com,example.com:80" | go run . -- A
FATA[0000] Unable to parse nameserver: invalid IP address 
exit status 1

// Invalid IP address without port
> echo "google.com,example.com" | go run . -- A
FATA[0000] Unable to parse nameserver: invalid IP address 
exit status 1

// Invalid IPv6 address
> echo "google.com,2001:4860:4860:0:0:0:0:8888:53" | go run . -- A
FATA[0000] Unable to parse nameserver: invalid IP address 
exit status 1

// Valid IPv6 address without port
> echo "google.com,2001:4860:4860::8888" | go run . -- A
{"data":{"protocol":"udp","resolver":"[2001:4860:4860::8888]:53"},"error":"write udp [redacted]:51462-\u003e[2001:4860:4860::8888]:53: address 2001:4860:4860::8888: non-IPv4 address","name":"google.com","status":"ERROR"}

// Valid IPv6 address with non-standard port
> echo "google.com,[2001:4860:4860:0:0:0:0:8888]:5353" | go run . -- A
{"data":{"protocol":"udp","resolver":"[2001:4860:4860:0:0:0:0:8888]:5353"},"error":"write udp [redacted]:49824-\u003e[2001:4860:4860::8888]:5353: address 2001:4860:4860::8888: non-IPv4 address","name":"google.com","status":"ERROR"}

Tests that fail on main branch

// Invalid IP address with port
> echo "google.com,example.com:80" | go run . -- A
{"data":{"protocol":"udp","resolver":"example.com:80"},"name":"google.com","status":"TIMEOUT"}

// Invalid IP address without port
> echo "google.com,example.com" | go run . -- A
{"data":{"protocol":"udp","resolver":"example.com:53"},"name":"google.com","status":"REFUSED"}

resolves #284

the refactored function relies on built-in net package to perform more rigorous validation on input nameserver address
Copy link
Contributor

@phillip-stephens phillip-stephens left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the rigorous tests and help on this @developStorm!!

@phillip-stephens phillip-stephens merged commit 610e4c7 into main Mar 13, 2024
4 checks passed
@phillip-stephens phillip-stephens deleted the feat/enhanced-input-ns-validation branch March 13, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate input to zdns
2 participants