Skip to content

Commit bfa5b20

Browse files
committed
Use LimitReader to avoid DoS by evil endpoints
1 parent 1b87d27 commit bfa5b20

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/auth/token.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ func (g *GoogleProvider) IntrospectToken(ctx context.Context, token string) (jwt
123123
}
124124
defer resp.Body.Close()
125125

126-
// Read the response
127-
body, err := io.ReadAll(resp.Body)
126+
// Read the response with a reasonable limit to prevent DoS attacks
127+
const maxResponseSize = 64 * 1024 // 64KB should be more than enough for tokeninfo response
128+
limitedReader := io.LimitReader(resp.Body, maxResponseSize)
129+
body, err := io.ReadAll(limitedReader)
128130
if err != nil {
129131
return nil, fmt.Errorf("failed to read Google tokeninfo response: %w", err)
130132
}
@@ -297,8 +299,10 @@ func (r *RFC7662Provider) IntrospectToken(ctx context.Context, token string) (jw
297299
}
298300
defer resp.Body.Close()
299301

300-
// Read response body
301-
body, err := io.ReadAll(resp.Body)
302+
// Read response body with a reasonable limit to prevent DoS attacks
303+
const maxResponseSize = 64 * 1024 // 64KB should be more than enough for introspection response
304+
limitedReader := io.LimitReader(resp.Body, maxResponseSize)
305+
body, err := io.ReadAll(limitedReader)
302306
if err != nil {
303307
return nil, fmt.Errorf("failed to read introspection response: %w", err)
304308
}

0 commit comments

Comments
 (0)