Skip to content

Commit

Permalink
api: Less explicit, but with string checks
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 484a52d
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions api/services_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func IsSafeVarPath(path string) error {
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")
}
Expand Down Expand Up @@ -70,15 +74,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 484a52d

Please sign in to comment.