mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-29 15:02:30 +00:00
dkim: Consider only 3 TXT records when fetching keys
Today, when looking up DKIM keys via DNS, we go through all the TXT records that are published. This is already more lenient than what's allowed by many implementations (as documented in the code). Potentially, someone could craft a domain with a lot of TXT records to make us waste time processing those keys. To help reduce that possibility, this patch limits the lookup to 3 records. This is still more than normal and may be limited further to 1 in the future.
This commit is contained in:
@@ -66,6 +66,34 @@ func TestSkipBadRecords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxKeyRecords(t *testing.T) {
|
||||
ctx := WithLookupTXTFunc(t.Context(), testLookupTXT)
|
||||
defer clear(results)
|
||||
|
||||
// Only the first maxKeyRecords records are used, even if the rest are
|
||||
// valid keys.
|
||||
key := "v=DKIM1; p=" + exampleRSAKeyB64
|
||||
results["selector._domainkey.example.com"] = []string{
|
||||
key, key, key, key, key,
|
||||
}
|
||||
pks, err := findPublicKeys(ctx, "example.com", "selector")
|
||||
if err != nil || len(pks) != maxKeyRecords {
|
||||
t.Errorf("findPublicKeys expected %d keys / nil, got %d / %v",
|
||||
maxKeyRecords, len(pks), err)
|
||||
}
|
||||
|
||||
// Records after the first maxKeyRecords are ignored, even if the first
|
||||
// ones are not valid keys.
|
||||
results["selector._domainkey.example.com"] = []string{
|
||||
"not a tag", "not a tag", "not a tag", key,
|
||||
}
|
||||
pks, err = findPublicKeys(ctx, "example.com", "selector")
|
||||
if err != nil || len(pks) != 0 {
|
||||
t.Errorf("findPublicKeys expected 0 keys / nil, got %d / %v",
|
||||
len(pks), err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePublicKey(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
|
||||
Reference in New Issue
Block a user