Skip to content

Commit 2bd126d

Browse files
committed
bundle-server: serve correct bundle routes for request
Update 'bundleServer.serve()' to serve the correct bundle list file for the request URI. If the URI has no trailing slash (e.g. 'https://<host>:<port>/<org>/<repo>'), serve the 'repo-bundle-list' file contents, which prepends '<repo>' to the relative bundle paths. If the URI has a trailing slash, serve 'bundle-list' as normal. Also, prevent users from directly reading 'bundle-list' and 'repo-bundle-list' based on the URI; the latter's relative paths would be incorrect, and in general these files are an internal implementation detail that should not be visible to users. If a user requests one of these files, return a 404. Signed-off-by: Victoria Dye <[email protected]>
1 parent 03cf2a0 commit 2bd126d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

cmd/git-bundle-web-server/bundle-server.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"syscall"
1313
"time"
1414

15+
"github.com/github/git-bundle-server/internal/bundles"
1516
"github.com/github/git-bundle-server/internal/common"
1617
"github.com/github/git-bundle-server/internal/core"
1718
"github.com/github/git-bundle-server/internal/log"
@@ -101,7 +102,20 @@ func (b *bundleWebServer) serve(w http.ResponseWriter, r *http.Request) {
101102

102103
var fileToServe string
103104
if filename == "" {
104-
fileToServe = filepath.Join(repository.WebDir, "bundle-list")
105+
if path[len(path)-1] == '/' {
106+
// Trailing slash, so the bundle URIs should be relative to the
107+
// request's URL as if it were a directory
108+
fileToServe = filepath.Join(repository.WebDir, bundles.BundleListFilename)
109+
} else {
110+
// No trailing slash, so the bundle URIs should be relative to the
111+
// request's URL as if it were a file
112+
fileToServe = filepath.Join(repository.WebDir, bundles.RepoBundleListFilename)
113+
}
114+
} else if filename == bundles.BundleListFilename || filename == bundles.RepoBundleListFilename {
115+
// If the request identifies a non-bundle "reserved" file, return 404
116+
w.WriteHeader(http.StatusNotFound)
117+
fmt.Printf("Failed to open file\n")
118+
return
105119
} else {
106120
fileToServe = filepath.Join(repository.WebDir, filename)
107121
}

0 commit comments

Comments
 (0)