Added support for DNS cookies (RFC 7873/9018, and partially BCP 38) - #1737
Added support for DNS cookies (RFC 7873/9018, and partially BCP 38)#1737zbalkan wants to merge 115 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds DNS Cookie support to the Technitium DNS Server, implementing RFC 7873 and RFC 9018 specifications. The implementation includes EDNS(0) COOKIE option parsing, server-side cookie generation and validation using HMAC-SHA256, secret management with automatic rotation, and appropriate request/response handling with BADCOOKIE responses.
Changes:
- Added
DnsCookieSecretManagerclass for managing 32-byte HMAC secrets with file persistence and automatic rotation - Added
DnsCookieValidatorclass for generating and validating DNS cookies using RFC 9018 server cookie structure (version 1 with timestamp and HMAC-SHA256-64) - Integrated DNS cookie validation and response handling into
DnsServerwith configuration options for enabling cookies, secret file path, rotation period, TC-on-bad-cookie behavior, and always-echo mode
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 19 comments.
| File | Description |
|---|---|
| DnsServerCore/Dns/Security/DnsCookieSecretManager.cs | Manages cryptographic secrets for DNS cookies with persistence, rotation, and thread-safe access |
| DnsServerCore/Dns/Security/DnsCookieValidator.cs | Implements RFC 9018 server cookie generation and validation with timestamp and HMAC verification |
| DnsServerCore/Dns/DnsServer.cs | Integrates DNS cookie support with request validation, BADCOOKIE response generation, and configuration management |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
114c2df to
224475f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
Comments suppressed due to low confidence (1)
DnsServerCore/Dns/DnsServer.cs:593
- DNS cookies are not initialized when LoadConfigFile encounters an exception other than FileNotFoundException (caught at line 589). This means if the config file exists but is corrupt or causes any error during ReadConfigFrom, DNS cookies will not be available. Consider calling InitDnsCookies() in the catch block at line 589 to ensure DNS cookies are initialized even when config loading fails, similar to how it's called in the FileNotFoundException handler at line 587.
catch (Exception ex)
{
_log.Write("DNS Server encountered an error while loading DNS config file: " + dnsConfigFile + "\r\n" + ex.ToString());
_log.Write("Note: You may try deleting the DNS config file to fix this issue. However, you will lose DNS settings but, other data wont be affected.");
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'll roll back last two commits. I shouldn't blindly listen to the copilot review. Original code was okay. But tomorrow. |
6f34df8 to
f5a0926
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ready. |
|
BTW, this is the first iteration of the progress. The next step is to add another rate-limiter making use of DNS cookies. The flow would be:
|
|
After 2 months, I finally found time to work on where I've left. Now, blocking traffic based on DNS query |
|
At commit
I took another look at whether DNS Cookies and RRL / early UDP reflection limiting can be split into two completely independent PRs. I think this should be a stacked Part I / Part II series, rather than two unrelated PRs targeting DNS Cookies and RRL are separate features at the configuration level, as they are in other implementations. Once both are enabled, though, their behavior is intentionally combined. A valid Server Cookie is a trust signal for response rate limiting, and the early reflection limiter can use cookie state to send a useful recovery response. BIND and Knot DNS follow the same general approach: Cookies and RRL are exposed separately, but valid-cookie UDP traffic is exempt from RRL when both are enabled. The relevant standards also allow Cookies to be deployed independently. Their interaction with RRL is an implementation policy, not a protocol requirement. Two unrelated PRs would leave us with an awkward sequencing problem. We would either temporarily lose the valid-cookie exemption and cookie-aware recovery behavior, or add a third PR later to restore the intended combined policy. Neither makes the change easier to follow. I therefore suggest the following split:
This still gives us two smaller changes that can be reviewed separately, while making the dependency explicit and preserving the behavior we intend to ship. For a change set of roughly 4k LOC, that should make the individual concerns easier to reason about, test, and review without suggesting that the final security policy has no relationship between them. |
Adds DNS Cookies support across DnsServer with EDNS(0) COOKIE parsing, server-side cookie generation/validation, and request/response handling per RFC 7873/9018.
Relies on PR TechnitiumSoftware/TechnitiumLibrary#56
Edit: Solves #1151