Fix HTTP server timeout exposure and XSS in monitoring exporter#1007
Merged
or-else merged 2 commits intoJul 5, 2026
Conversation
Copilot
AI
changed the title
Fix security vulnerabilities found by gosec scan
Fix HTTP server timeout exposure and XSS in monitoring exporter
Jul 5, 2026
Copilot created this pull request from a session on behalf of
or-else
July 5, 2026 12:42
View session
or-else
approved these changes
Jul 5, 2026
There was a problem hiding this comment.
Pull request overview
This PR addresses security findings from gosec by hardening HTTP server configurations against Slowloris-style attacks, mitigating an XSS vector in the monitoring exporter, and using crypto/rand for boundary generation where appropriate.
Changes:
- Replaced a bare
http.ListenAndServeHTTP→HTTPS redirect listener with anhttp.Serverconfigured with timeouts and header limits. - Escaped error output in the exporter’s
/pushHTML response and replacedListenAndServewith a timeout-configuredhttp.Server. - Updated email validator boundary generation to use
crypto/randwith a time-based fallback on entropy failure.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
server/validate/email/validate.go |
Switches boundary generation from math/rand to crypto/rand with error handling. |
server/http.go |
Hardens the HTTP→HTTPS redirect server by using http.Server timeouts/header limits. |
monitoring/exporter/main.go |
Escapes HTML in /push output and adds timeouts to the exporter HTTP server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
64
to
76
| go func() { | ||
| if err := http.ListenAndServe(globals.tlsRedirectHTTP, tlsRedirect(addr)); err != nil && err != http.ErrServerClosed { | ||
| redirectServer := &http.Server{ | ||
| Addr: globals.tlsRedirectHTTP, | ||
| Handler: tlsRedirect(addr), | ||
| ReadHeaderTimeout: 10 * time.Second, | ||
| IdleTimeout: 30 * time.Second, | ||
| WriteTimeout: 90 * time.Second, | ||
| MaxHeaderBytes: 1 << 14, | ||
| } | ||
| if err := redirectServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
| logs.Info.Println("HTTP redirect failed:", err) | ||
| } | ||
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four security vulnerabilities identified by
gosecscan: two Slowloris-susceptible HTTP servers, one XSS injection point, and use ofmath/randwherecrypto/randwas already available.Changes
server/http.go— HTTP→HTTPS redirect server used barehttp.ListenAndServewith no timeouts. Replaced withhttp.ServercarryingReadHeaderTimeout: 10s / IdleTimeout: 30s / WriteTimeout: 90s, matching the main server config.monitoring/exporter/main.go— Same no-timeout issue on the exporter server. Also, the/pushendpoint embeddederr.Error()directly into an HTML response:server/validate/email/validate.go—randomBoundary()calledmath/rand.Readdespitecrypto/randalready being imported for OTP generation. Switched tocrand.Readwith error handling (time-based fallback on entropy failure).