Skip to content

Add RFC 6764 domain validation to prevent DNS hijacking attacks#576

Merged
tobixen merged 2 commits intomasterfrom
issue574
Nov 29, 2025
Merged

Add RFC 6764 domain validation to prevent DNS hijacking attacks#576
tobixen merged 2 commits intomasterfrom
issue574

Conversation

@tobixen
Copy link
Copy Markdown
Member

@tobixen tobixen commented Nov 29, 2025

Solves #574

🤖 Generated with Claude Code

tobixen and others added 2 commits November 29, 2025 01:38
Implements RFC 6764 Section 8 security requirement to validate that
discovered service endpoints remain within the same domain as the
queried domain. This prevents DNS hijacking attacks where malicious
DNS records redirect clients to attacker-controlled servers.

Security Issue:
Without domain validation, if DNS is hijacked, an attacker can redirect
example.com to evil.hackers.are.us. Even with TLS and valid certificates
for evil.hackers.are.us, credentials would be leaked to the attacker.

RFC 6764 Section 8 states:
"In the absence of a secure DNS option, clients SHOULD check that the
target FQDN returned in the SRV record matches the original service
domain that was queried. If the target FQDN is not in the queried
domain, clients SHOULD verify with the user that the SRV target FQDN
is suitable for use before executing any connections to the host."

Implementation:
1. Added _is_subdomain_or_same() function to validate discovered domains
   - Allows same domain (example.com -> example.com)
   - Allows subdomains (example.com -> calendar.example.com)
   - Rejects different domains (example.com -> evil.com)

2. Applied validation to SRV record discovery
   - Checks hostname from SRV records
   - Logs warning and rejects if domain mismatch
   - Falls back to next discovery method

3. Applied validation to well-known URI redirects
   - Checks redirect Location header
   - Rejects redirects to different domains
   - Returns None to try alternative discovery

4. Updated security documentation
   - Removed TODO comment (now implemented)
   - Added RFC 6764 Section 8 reference
   - Documented domain validation mitigation

Testing:
- Doctests verify _is_subdomain_or_same() logic
- Handles edge cases: subdomains, case sensitivity, trailing dots

This provides defense-in-depth alongside TLS certificate verification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tobixen tobixen merged commit aef792d into master Nov 29, 2025
4 checks passed
@tobixen tobixen deleted the issue574 branch November 29, 2025 08:27
tobixen added a commit that referenced this pull request Dec 1, 2025
Resolves #574 - DNS service discovery should not cause redirections to other domains.  That is a security risk unless using DNSSEC.

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant