Pull request #436: AGDNS-4074-limit-reads

Merge in GO/dnsproxy from AGDNS-4074-limit-reads to master

Squashed commit of the following:

commit 33b1ccdad30a5524aa4c871d3fad5f163701d5b2
Author: f.setrakov <[email protected]>
Date:   Wed Jun 3 14:58:26 2026 +0300

    all: limit reads
This commit is contained in:
Fedor Setrakov
2026-06-04 10:18:32 +00:00
parent f214e791e1
commit 261c8ff9ea
2 changed files with 6 additions and 3 deletions
+3 -2
View File
@@ -15,6 +15,7 @@ import (
"github.com/AdguardTeam/dnsproxy/internal/bootstrap"
"github.com/AdguardTeam/golibs/httphdr"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/miekg/dns"
"github.com/quic-go/quic-go"
@@ -159,8 +160,8 @@ func newDoHReq(
return nil, http.StatusUnsupportedMediaType
}
// TODO(d.kolyshev): Limit reader.
buf, err = io.ReadAll(r.Body)
limitBody := ioutil.LimitReader(r.Body, dns.MaxMsgSize)
buf, err = io.ReadAll(limitBody)
if err != nil {
l.DebugContext(ctx, "reading http request body", slogutil.KeyError, err)
+3 -1
View File
@@ -18,6 +18,7 @@ import (
"github.com/AdguardTeam/dnsproxy/internal/bootstrap"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/httphdr"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/miekg/dns"
"github.com/quic-go/quic-go"
@@ -288,7 +289,8 @@ func (p *dnsOverHTTPS) exchangeHTTPSClient(
}
defer slogutil.CloseAndLog(httpReq.Context(), p.logger, httpResp.Body, slog.LevelDebug)
body, err := io.ReadAll(httpResp.Body)
limitBody := ioutil.LimitReader(httpResp.Body, dns.MaxMsgSize)
body, err := io.ReadAll(limitBody)
if err != nil {
return nil, fmt.Errorf("reading %s: %w", p.addrRedacted, err)
}