fix: handler overflow panic#1066
Merged
oliverbaehler merged 2 commits intoJul 2, 2026
Merged
Conversation
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
prometherion
approved these changes
Jul 2, 2026
There was a problem hiding this comment.
Pull request overview
This PR removes panic-based control flow in the webserver error paths and introduces a local recovery middleware to prevent request-handler panics from cascading, while also updating Helm APF FlowSchema rules to include TokenReview calls.
Changes:
- Replaced
gorilla/handlersrecovery handler with a customrecoveryMiddlewareon the mux router. - Removed intentional
panic(...)calls after writing error responses; added earlyreturnstatements after handling errors. - Updated the Helm FlowSchema to include
authentication.k8s.io/tokenreviewscreaterequests.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/webserver/webserver.go | Switches to custom recovery middleware and adjusts several handlers to return after writing errors. |
| internal/webserver/middleware/user_in_group.go | Adds error responses + early returns when user/group resolution fails inside group-check middleware. |
| internal/webserver/middleware/jwt.go | Adds early returns after TokenReview failure/unauthorized handling. |
| internal/webserver/errors/panic.go | Stops panicking after writing JSON error responses; sets explicit HTTP status codes. |
| go.mod | Removes github.com/gorilla/handlers dependency. |
| go.sum | Removes github.com/gorilla/handlers checksums. |
| charts/capsule-proxy/templates/flowschema.yaml | Adds APF FlowSchema rule for tokenreviews create. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
350
to
354
| if err != nil { | ||
| server.HandleError(writer, err, "cannot retrieve user and group from the request") | ||
|
|
||
| return | ||
| } |
Comment on lines
32
to
37
| if err != nil { | ||
| log.Error(err, "Cannot retrieve username and group from request") | ||
| errors.HandleError(writer, err, "cannot retrieve user and group from the request") | ||
|
|
||
| return | ||
| } |
Comment on lines
58
to
63
| if err != nil { | ||
| log.Error(err, "Cannot retrieve username and group from request") | ||
| errors.HandleError(writer, err, "cannot retrieve user and group from the request") | ||
|
|
||
| return | ||
| } |
Comment on lines
+619
to
+621
| if err, ok := recovered.(error); ok && errors.Is(err, http.ErrAbortHandler) { | ||
| return | ||
| } |
Comment on lines
+623
to
+624
| n.log.Error(fmt.Errorf("%v", recovered), "panic while handling request") | ||
| http.Error(writer, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| } | ||
|
|
||
| if statusErr := tr.Status.Error; len(statusErr) > 0 { | ||
| invalidatedToken.Insert(token) |
Comment on lines
551
to
556
| request, username, groups, err := req.ResolveUserAndGroups(request, n.authTypes, n.usernameClaimField, n.writer, n.ignoredImpersonationGroups, n.impersonationGroupsRegexp, n.skipImpersonationReview, n.xfcc_header) | ||
| if err != nil { | ||
| server.HandleError(writer, err, "cannot retrieve user and group from the request") | ||
|
|
||
| return | ||
| } |
This was referenced Jul 2, 2026
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
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.
No description provided.