plugin/cache: Fix cache poisoning exploit (#5174)

This commit is contained in:
Chris O'Haver 2022-05-01 08:57:03 -04:00 committed by GitHub
parent 5a4437bb23
commit c4bc1a5471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 25 deletions

View file

@ -191,7 +191,7 @@ func TestCache(t *testing.T) {
c, crr := newTestCache(maxTTL)
for _, tc := range cacheTestCases {
for n, tc := range cacheTestCases {
m := tc.in.Msg()
m = cacheMsg(m, tc)
@ -204,11 +204,15 @@ func TestCache(t *testing.T) {
crr.set(m, k, mt, c.pttl)
}
i, _ := c.get(time.Now().UTC(), state, "dns://:53")
i := c.getIgnoreTTL(time.Now().UTC(), state, "dns://:53")
ok := i != nil
if ok != tc.shouldCache {
t.Errorf("Cached message that should not have been cached: %s", state.Name())
if !tc.shouldCache && ok {
t.Errorf("Test %d: Cached message that should not have been cached: %s", n, state.Name())
continue
}
if tc.shouldCache && !ok {
t.Errorf("Test %d: Did not cache message that should have been cached: %s", n, state.Name())
continue
}