Skip to content

Commit

Permalink
Ensure the dashboard zip is sane (elastic#6921)
Browse files Browse the repository at this point in the history
* Ensure the dashboard zip is sane

This adds a check that all files from the dashboard zip file
are pointing to the right target, and don't override other configs.

* changelog

* addressed comment

(cherry picked from commit a34c9eb)
  • Loading branch information
tsg committed May 2, 2018
1 parent 157e051 commit 5b97e49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix for kafka logger. {pull}6430[6430]
- Remove double slashes in Windows service script. {pull}6491[6491]
- Ensure Kubernetes labels/annotations don't break mapping {pull}6490[6490]
- Ensure that the dashboard zip files can't contain files outside of the kibana directory. {pull}6921[6921]

*Auditbeat*

Expand Down
10 changes: 10 additions & 0 deletions libbeat/dashboards/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ func (imp Importer) unzip(archive, target string) error {
unzipFile := func(file *zip.File) error {
filePath := filepath.Join(target, file.Name)

// check that the resulting file path is indeed under target
// Note that Rel calls Clean.
relPath, err := filepath.Rel(target, filePath)
if err != nil {
return err
}
if strings.HasPrefix(filepath.ToSlash(relPath), "../") {
return fmt.Errorf("Zip file contains files outside of the target directory: %s", relPath)
}

if file.FileInfo().IsDir() {
return os.MkdirAll(filePath, file.Mode())
}
Expand Down

0 comments on commit 5b97e49

Please sign in to comment.