feat: redirect anonymous GET / to the panel - #63
Merged
Conversation
Browsers hitting the server root previously fell through to the S3 handler,
which returns a 403 AccessDenied XML for an unauthenticated ListBuckets — a
dead end for anyone typing the server URL. Root GETs are now redirected to
the panel (/onboarding, /login, or /dashboard).
S3 access is unaffected. The redirect only fires for a bare GET / with no
SigV4 Authorization header, no X-Amz-* presigned query params, and no
host-style {bucket}.{hostBase} subdomain — every genuine S3 client request
carries at least one of those markers, and all pass through untouched.
This comment has been minimized.
This comment has been minimized.
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Docker image for testingPull the image for this PR: docker pull ghcr.io/lumeweb/s3-server:sha-7b97f72Or use in docker-compose: services:
s3-server:
image: ghcr.io/lumeweb/s3-server:sha-7b97f72
|
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.
Summary
Redirect an anonymous
GET /(server root) to the panel, so browsers that land on the root URL reach onboarding/login/dashboard instead of a 403 XML error. Genuine S3 traffic is unaffected.Previously a root GET fell through to the S3 handler, where an unauthenticated ListBuckets returns
403 AccessDeniedXML (s3/buckets.go:151) — a dead end for anyone typing the server URL.Approach
GET /is the S3 ListBuckets operation, which requires SigV4 auth. Browsers never sign requests, so the redirect fires only when none of these S3 markers are present:Authorizationheader (authenticated calls)X-Amz-*query params (presigned URLs){bucket}.{hostBase}virtual-host subdomain (host-style bucket listing at/)Any of those pass through to the S3 handler untouched. No path other than exact
/is affected.Changes
internal/handlers/handlers_root_redirect.go— newRootToPanelRedirectmiddleware with the S3-request discriminator.cmd/s3-server/main.go— wraps3Rootwithhandlers.RootToPanelRedirect(s3Root, cfg.S3.HostBases)before mounting at/.internal/handlers/handlers_root_redirect_test.go— unit tests for redirect + S3 pass-through cases.Verification
go build ./...✅go vet✅gofmt -l(clean) ✅go test ./internal/handlers/ -race✅This pull request adds a redirect mechanism that sends anonymous GET requests to the server root ("/") to the panel interface, while ensuring all genuine S3 API requests continue to work unaffected.
Key Changes
New Redirect Middleware
RootToPanelRedirectmiddleware ininternal/handlers/handlers_root_redirect.gothat wraps the S3 handler/_panel/with a 302 Found statusSmart Request Detection
The middleware intelligently distinguishes between browser navigation and actual S3 API calls by checking for:
Authorizationheaders pass throughX-Amz-*query parameters pass through{bucket}.s3.example.com) pass throughImplementation Details
cmd/s3-server/main.goafter the SSL bucket middleware and before the final route handlingImpact
This change improves the user experience by automatically directing web browsers to the panel interface when they visit the server's root URL, while maintaining full S3 API compatibility for all legitimate client requests.