Skip to content

Commit

Permalink
Fix CodeQL check
Browse files Browse the repository at this point in the history
Signed-off-by: Maia Iyer <[email protected]>
  • Loading branch information
maia-iyer committed Sep 30, 2024
1 parent 681f68c commit 09aeeff
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions api/agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,18 @@ type spaHandler struct {
// file located at the index path on the SPA handler will be served. This
// is suitable behavior for serving an SPA (single page application).
func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
relPath := r.URL.Path
// get the absolute path to prevent directory traversal
path, err := filepath.Abs(r.URL.Path)
if err != nil {
absPath, err := filepath.Abs(filepath.Join(h.staticPath, relPath))
if err != nil || !strings.HasPrefix(absPath, h.staticPath) {
// if we failed to get the absolute path respond with a 400 bad request
// and stop
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// prepend the path with the path to the static directory
path = filepath.Join(h.staticPath, path)

// check whether a file exists at the given path
_, err = os.Stat(path)
_, err = os.Stat(absPath)
if os.IsNotExist(err) {
// file does not exist, serve index.html
http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath))
Expand Down

0 comments on commit 09aeeff

Please sign in to comment.