Skip to content

Commit

Permalink
Clean Path in Options (#23006)
Browse files Browse the repository at this point in the history
At the Moment it is possible to read files in another Directory as
supposed using the Options functions. e.g.
`options.Gitignore("../label/Default) `. This was discovered while
working on #22783, which exposes `options.Gitignore()` through the
public API. At the moment, this is not a security problem, as this
function is only used internal, but I thought it would be a good idea to
make a PR to fix this for all types of Options files, not only
Gitignore, to make it safe for the further. This PR should be merged
before the linked PR.

---------

Co-authored-by: Jason Song <i@wolfogre.com>
  • Loading branch information
JakobDev and wolfogre authored Mar 8, 2023
1 parent 7e3b7c2 commit a12f575
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions modules/options/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro

// Readme reads the content of a specific readme from static or custom path.
func Readme(name string) ([]byte, error) {
return fileFromDir(path.Join("readme", name))
return fileFromDir(path.Join("readme", path.Clean("/"+name)))
}

// Gitignore reads the content of a specific gitignore from static or custom path.
func Gitignore(name string) ([]byte, error) {
return fileFromDir(path.Join("gitignore", name))
return fileFromDir(path.Join("gitignore", path.Clean("/"+name)))
}

// License reads the content of a specific license from static or custom path.
func License(name string) ([]byte, error) {
return fileFromDir(path.Join("license", name))
return fileFromDir(path.Join("license", path.Clean("/"+name)))
}

// Labels reads the content of a specific labels from static or custom path.
func Labels(name string) ([]byte, error) {
return fileFromDir(path.Join("label", name))
return fileFromDir(path.Join("label", path.Clean("/"+name)))
}

// fileFromDir is a helper to read files from static or custom path.
Expand Down
8 changes: 4 additions & 4 deletions modules/options/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro

// Readme reads the content of a specific readme from bindata or custom path.
func Readme(name string) ([]byte, error) {
return fileFromDir(path.Join("readme", name))
return fileFromDir(path.Join("readme", path.Clean("/"+name)))
}

// Gitignore reads the content of a gitignore locale from bindata or custom path.
func Gitignore(name string) ([]byte, error) {
return fileFromDir(path.Join("gitignore", name))
return fileFromDir(path.Join("gitignore", path.Clean("/"+name)))
}

// License reads the content of a specific license from bindata or custom path.
func License(name string) ([]byte, error) {
return fileFromDir(path.Join("license", name))
return fileFromDir(path.Join("license", path.Clean("/"+name)))
}

// Labels reads the content of a specific labels from static or custom path.
func Labels(name string) ([]byte, error) {
return fileFromDir(path.Join("label", name))
return fileFromDir(path.Join("label", path.Clean("/"+name)))
}

// fileFromDir is a helper to read files from bindata or custom path.
Expand Down

0 comments on commit a12f575

Please sign in to comment.