Verify TSIG MAC before checking timestamp so BadSignature is not pree… - #1293
Open
adityaanikam wants to merge 1 commit into
Open
Verify TSIG MAC before checking timestamp so BadSignature is not pree…#1293adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
jschlyter
reviewed
Aug 16, 2026
| now = int(time.time()) | ||
| wrong_key = dns.tsig.Key(keyname, "abcd", "hmac-sha256") | ||
| with self.assertRaises(dns.tsig.BadSignature): | ||
| dns.tsig.validate(w, wrong_key, keyname, tsig, now + 1000, b"", tsig_start) |
Contributor
There was a problem hiding this comment.
Explicitly declaring and using a wrong_key might increase readability.
jschlyter
approved these changes
Aug 16, 2026
jschlyter
left a comment
Contributor
There was a problem hiding this comment.
Looking good. I've also read the RFCs and agree with the change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1287.
validate() checked the timestamp before verifying the MAC, so a request with both a bad signature and a bad timestamp reported BadTime instead of BadSignature, RFC 8945 5.2 expects MAC validity to be established first. rthalley confirmed following the RFC is the right call here, with the behavior change noted in a release note rather than treated as something needing extra caution.
The reorder itself is a two line move, no other logic changed. The existing test_validate had a latent issue that only surfaced once the ordering changed: its BadTime case used a key with a different secret than the one that actually signed the message, so the MAC would also fail, but the old ordering never reached that check, checking time first meant it never mattered. I fixed that case to use the correct signing key so it isolates a genuine timestamp-only failure, and added a new test for the actual scenario from the issue, a bad MAC combined with a bad timestamp now correctly raises BadSignature.