mirror of
https://github.com/grafana/grafana.git
synced 2025-09-25 11:54:20 +08:00

committed by
GitHub

parent
7b7b95341e
commit
2acffbeb10
@ -199,14 +199,14 @@ func extractFiles(body []byte, pluginName string, filePath string, allowSymlinks
|
||||
}
|
||||
for _, zf := range r.File {
|
||||
newFileName := RemoveGitBuildFromName(pluginName, zf.Name)
|
||||
if !isPathSafe(newFileName, path.Join(filePath, pluginName)) {
|
||||
if !isPathSafe(newFileName, filepath.Join(filePath, pluginName)) {
|
||||
return xerrors.Errorf("filepath: %v tries to write outside of plugin directory: %v. This can be a security risk.", zf.Name, path.Join(filePath, pluginName))
|
||||
}
|
||||
newFile := path.Join(filePath, newFileName)
|
||||
|
||||
if zf.FileInfo().IsDir() {
|
||||
err := os.Mkdir(newFile, 0755)
|
||||
if permissionsError(err) {
|
||||
if os.IsPermission(err) {
|
||||
return fmt.Errorf(permissionsDeniedMessage, newFile)
|
||||
}
|
||||
} else {
|
||||
@ -234,10 +234,6 @@ func extractFiles(body []byte, pluginName string, filePath string, allowSymlinks
|
||||
return nil
|
||||
}
|
||||
|
||||
func permissionsError(err error) bool {
|
||||
return err != nil && strings.Contains(err.Error(), "permission denied")
|
||||
}
|
||||
|
||||
func isSymlink(file *zip.File) bool {
|
||||
return file.Mode()&os.ModeSymlink == os.ModeSymlink
|
||||
}
|
||||
@ -269,7 +265,7 @@ func extractFile(file *zip.File, filePath string) (err error) {
|
||||
|
||||
dst, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
|
||||
if err != nil {
|
||||
if permissionsError(err) {
|
||||
if os.IsPermission(err) {
|
||||
return xerrors.Errorf(permissionsDeniedMessage, filePath)
|
||||
}
|
||||
return errutil.Wrap("Failed to open file", err)
|
||||
|
Reference in New Issue
Block a user