Skip to content

Commit a12f575

Browse files
JakobDevwolfogre
andauthored
Clean Path in Options (#23006)
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 <[email protected]>
1 parent 7e3b7c2 commit a12f575

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

modules/options/dynamic.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro
7979

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

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

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

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

100100
// fileFromDir is a helper to read files from static or custom path.

modules/options/static.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,22 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro
8484

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

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

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

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

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

0 commit comments

Comments
 (0)