Skip to content

Commit 5fef212

Browse files
committed
Merge branch 'fix-scanning-alerts'
2 parents 8601866 + 7cf8d62 commit 5fef212

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.github/workflows/images.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ jobs:
9090

9191
images:
9292
runs-on: ubuntu-latest
93+
permissions:
94+
contents: read
9395
needs: build-and-push-image
9496
env:
9597
OUTPUTS_DIR: /tmp/outputs

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Tests
22
on: [push]
33
jobs:
44
tests:
5+
permissions:
6+
contents: read
57
strategy:
68
matrix:
79
env:

pkg/cinodefs/httphandler/http.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5252
}
5353
}
5454

55+
// sanitizeRedirectPath ensures redirect targets do not lead to open redirects.
56+
func sanitizeRedirectPath(p string) string {
57+
if len(p) > 1 && p[0] == '/' && p[1] != '/' && p[1] != '\\' {
58+
return p
59+
}
60+
return "/"
61+
}
62+
5563
func (h *Handler) serveGet(w http.ResponseWriter, r *http.Request, log *slog.Logger) {
5664
path := r.URL.Path
5765
if strings.HasSuffix(path, "/") {
@@ -70,14 +78,14 @@ func (h *Handler) serveGet(w http.ResponseWriter, r *http.Request, log *slog.Log
7078
// Can't get the entrypoint, but since it's a directory
7179
// (only with unsaved changes), redirect to the directory itself
7280
// that will in the end load the index file if present.
73-
http.Redirect(w, r, r.URL.Path+"/", http.StatusTemporaryRedirect)
81+
http.Redirect(w, r, sanitizeRedirectPath(r.URL.Path+"/"), http.StatusTemporaryRedirect)
7482
return
7583
case h.handleHTTPError(err, w, log, "Error finding entrypoint"):
7684
return
7785
}
7886

7987
if fileEP.IsDir() {
80-
http.Redirect(w, r, r.URL.Path+"/", http.StatusTemporaryRedirect)
88+
http.Redirect(w, r, sanitizeRedirectPath(r.URL.Path+"/"), http.StatusTemporaryRedirect)
8189
return
8290
}
8391

0 commit comments

Comments
 (0)