Skip to content

Commit 73159cb

Browse files
committed
feat: Limit response size in HTTP key fetcher to prevent DoS attacks
1 parent d6a81cb commit 73159cb

File tree

1 file changed

+3
-0
lines changed
  • internal/api/handlers/v0/auth

1 file changed

+3
-0
lines changed

internal/api/handlers/v0/auth/http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func (f *DefaultHTTPKeyFetcher) FetchKey(ctx context.Context, domain string) (st
7474
return "", fmt.Errorf("HTTP %d: failed to fetch key from %s", resp.StatusCode, url)
7575
}
7676

77+
// Limit response size to prevent DoS attacks
78+
resp.Body = http.MaxBytesReader(nil, resp.Body, 4096)
79+
7780
body, err := io.ReadAll(resp.Body)
7881
if err != nil {
7982
return "", fmt.Errorf("failed to read response body: %w", err)

0 commit comments

Comments
 (0)