Skip to content

Commit 742de23

Browse files
committed
Use LimitReader to avoid DoS by evil endpoints
1 parent f75c226 commit 742de23

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
}
@@ -298,8 +300,10 @@ func (r *RFC7662Provider) IntrospectToken(ctx context.Context, token string) (jw
298300
}
299301
defer resp.Body.Close()
300302

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

0 commit comments

Comments
 (0)