Skip to content

Added basic DNS cookie support with rate limiting#1737

Open
zbalkan wants to merge 35 commits intoTechnitiumSoftware:masterfrom
zbalkan:feat/add-dns-cookie-support
Open

Added basic DNS cookie support with rate limiting#1737
zbalkan wants to merge 35 commits intoTechnitiumSoftware:masterfrom
zbalkan:feat/add-dns-cookie-support

Conversation

@zbalkan
Copy link
Copy Markdown
Contributor

@zbalkan zbalkan commented Feb 18, 2026

Adds DNS Cookies support across DnsServer with EDNS(0) COOKIE parsing, server-side cookie generation/validation, and request/response handling per RFC 7873/9018.

  • EDNS COOKIE parsing/serialization (code 10) via EDnsCookieOptionData; 8-byte client cookie; 8–32-byte server cookie.
  • DnsCookieSecretManager for 32-byte HMAC secrets with persistence and rotation.
  • DnsCookieValidator builds v1 server cookies (version, timestamp, HMAC‑SHA256‑64) and validates within 5 minutes; server replies BADCOOKIE with TC and a fresh cookie on failure.
  • Response path echoes/attaches server cookies when absent or forced and updates OPT safely.

Relies on PR TechnitiumSoftware/TechnitiumLibrary#56

Edit: Solves #1151
Edit 2: Removed configuration for cookies for the sake of simplicity

Copilot AI review requested due to automatic review settings February 18, 2026 13:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DnsCookieSecretManager class for managing 32-byte HMAC secrets with file persistence and automatic rotation
  • Added DnsCookieValidator class 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 DnsServer with 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.

Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
Comment thread DnsServerCore/Dns/Security/DnsCookieValidator.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieValidator.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
@zbalkan zbalkan force-pushed the feat/add-dns-cookie-support branch from 114c2df to 224475f Compare February 19, 2026 10:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieValidator.cs
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs
@zbalkan
Copy link
Copy Markdown
Contributor Author

zbalkan commented Feb 19, 2026

I'll roll back last two commits. I shouldn't blindly listen to the copilot review. Original code was okay. But tomorrow.

@zbalkan zbalkan force-pushed the feat/add-dns-cookie-support branch from 6f34df8 to f5a0926 Compare February 20, 2026 07:40
@zbalkan zbalkan requested a review from Copilot February 20, 2026 10:08
@zbalkan zbalkan marked this pull request as draft February 20, 2026 10:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieValidator.cs Outdated
Comment thread DnsServerCore/Dns/Security/DnsCookieSecretManager.cs
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread DnsServerCore/Dns/DnsServer.cs Outdated
Comment thread DnsServerCore/Dns/DnsServer.cs
@zbalkan zbalkan marked this pull request as ready for review February 20, 2026 13:11
@zbalkan
Copy link
Copy Markdown
Contributor Author

zbalkan commented Feb 20, 2026

Ready.

@zbalkan
Copy link
Copy Markdown
Contributor Author

zbalkan commented Mar 6, 2026

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:

  • If there is no valid cookie for N amount of queries, escalate to DNS-over-TCP
  • If there are valid UDP cookies, proceed with DNS-over-UDP.

zbalkan added 2 commits April 24, 2026 21:33
… response attach, malformed FORMERR, abuse throttling, and runtime toggle)
…e. drop without responding beyond a threshold
@zbalkan zbalkan changed the title Added basic DNS cookie support Added basic DNS cookie support with rate limiting Apr 24, 2026
@zbalkan
Copy link
Copy Markdown
Contributor Author

zbalkan commented Apr 24, 2026

After 2 months, I finally found time to work on where I've left. Now, blocking traffic based on DNS query BADCOOKIE event has become another rate limiter. It can be enabled/disabled by a checkbox under Settings>General tab. The other values are hardcoded. The idea is to minimize the workload under a DDoS by responding queries with bad cookies ASAP with a truncate message, and beyond a threshold, dropping them altogether with no response. Blocking must be cheaper than resolving for this to work as intended.

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.

2 participants