Skip to content

Commit

Permalink
api: Semi explicit
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Sep 4, 2024
1 parent af2bc7d commit 403d0a5
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions api/services_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -31,18 +30,13 @@ var ServiceTokensCmd = func(sh *service.Handler) rest.Endpoint {
}

func IsSafeVarPath(path string) error {
absPath, err := filepath.Abs(path)
if err != nil {
return err
}

varDir := os.Getenv("LXD_DIR")
if varDir == "" {
varDir = "/var/lib/lxd"
if strings.Contains(path, "/") || strings.Contains(path, "\\") || strings.Contains(path, "..") {
return fmt.Errorf("test err")
}

if !strings.HasPrefix(absPath, varDir) {
return errors.New("Absolute path is outside the default LXD path")
_, err := filepath.Abs(path)
if err != nil {
return err
}

return nil
Expand Down Expand Up @@ -70,15 +64,6 @@ func serviceTokensPost(s *state.State, r *http.Request) response.Response {
return response.SmartError(err)
}

if strings.Contains(req.JoinerName, "/") || strings.Contains(req.JoinerName, "\\") || strings.Contains(req.JoinerName, "..") {
return response.SmartError(err)
}

_, err = filepath.Abs(req.JoinerName)
if err != nil {
return response.SmartError(err)
}

_ = os.MkdirAll(req.JoinerName, 0700)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

sh, err := service.NewHandler(s.Name(), req.ClusterAddress, s.OS.StateDir, false, false, types.ServiceType(serviceType))
Expand Down

0 comments on commit 403d0a5

Please sign in to comment.