-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(gateway): add default landing page when RootRedirect is not set #11091
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
base: master
Are you sure you want to change the base?
Conversation
| if w.suppressed404 { | ||
| return len(b), nil // Discard 404 body | ||
| } | ||
| return w.ResponseWriter.Write(b) |
Check warning
Code scanning / CodeQL
Information exposure through a stack trace Medium
stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 days ago
To fix the issue, we must ensure that stack trace information (the contents of buf in profile/goroutines.go) is not sent to the user via an HTTP response. When writing such diagnostics, the correct action is to log the stack trace on the server (for administrator/developer analysis) and, for the client, to send a generic error message instead.
Specifically:
- In
profile/goroutines.go, ifWriteAllGoroutineStacksis used as a handler to write goroutine stacks to a user-facing HTTP response, it should instead:- Write a simple message to the response, such as "An unexpected error occurred".
- Log the stack trace server-side using Go's
logpackage (or an equivalent).
- If there are places in
core/corehttp/landing.gowhere stack trace information flows into an HTTP response (specifically via theWritemethod), this must be intercepted and only a generic error or status be sent.
As the data flow is traced from profile/goroutines.go:WriteAllGoroutineStacks, the fix is to log the stack trace and only send a generic message to the writer (ideally, the HTTP response writer).
Required changes:
- In
profile/goroutines.go, updateWriteAllGoroutineStacksso that instead of writingbufto theio.Writer, it logs the stack trace server-side and writes a generic message to the writer. - Add an import for
"log"if not present.
-
Copy modified line R6 -
Copy modified lines R26-R29
| @@ -3,6 +3,7 @@ | ||
| import ( | ||
| "io" | ||
| "runtime" | ||
| "log" | ||
| ) | ||
|
|
||
| // WriteAllGoroutineStacks writes a stack trace to the given writer. | ||
| @@ -22,6 +23,9 @@ | ||
| // } | ||
| buf = make([]byte, 2*len(buf)) | ||
| } | ||
| _, err := w.Write(buf) | ||
| // Log stack trace on server for diagnostics | ||
| log.Printf("Goroutine stack trace:\n%s", string(buf)) | ||
| // Write a generic message to the writer instead of stack trace | ||
| _, err := w.Write([]byte("An unexpected internal error occurred. Please contact support.")) | ||
| return err | ||
| } |
display a landing page at gateway root "/" when `Gateway.RootRedirect` is not configured. the page indicates that kubo is working and provides links to documentation and resources. - embed HTML at compile time using go:embed - intercept 404 responses on known gateways (like localhost) with zero-buffering overhead - hide abuse reporting section for localhost/127.0.0.1 - serve landing page on both gateway and RPC API ports
10ea4cf to
052e823
Compare
This is quality of life improvement where the Gateway port displays a landing page at root "/" when
Gateway.RootRedirectis not configured. the page indicates that kubo is working and provides links to documentation and resources.