Skip to content

chore(api): harden HTTP server initialization based on Gosec (G112, G114) #10097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

schen6318
Copy link

Summary

This pull request addresses security concerns raised by Gosec regarding the use of insecure HTTP.server configurations in the Kubernetes Dashboard API and related components.

Purpose

The goal is to enforce safe usage of the Go http.Server by ensuring proper timeout settings are applied to avoid risks such as:

  • Unbounded request durations (G114 / CWE-676)
  • Potential Slowloris attacks due to missing ReadHeaderTimeout (G112 / CWE-400)

Implementation

This PR resolves two classes of security warnings:

  • G114 (CWE-676): Avoid usage of http.ListenAndServe / ListenAndServeTLS directly, which provide no timeout control.
    Replaced these calls with structured http.Server configurations including:
  1. ReadTimeout;
  2. WriteTimeout;
  3. IdleTimeout;
  • G112 (CWE-400): Added missing ReadHeaderTimeout to structured servers to prevent Slowloris-style DoS attacks.

Notes

These changes are based on security findings from Gosec.
No application logic is modified — only server initialization is hardened.
All warnings have been resolved in subsequent Gosec scans.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 1, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: schen6318
Once this PR has been reviewed and has the lgtm label, please assign shu-mutou for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants