Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
pkg/tool: improve SanitizePath (#5558)
- Loading branch information
Showing
4 changed files
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,5 +17,7 @@ func IsSameSiteURLPath(url string) bool { | |
|
|
||
| // SanitizePath sanitizes user-defined file paths to prevent remote code execution. | ||
| func SanitizePath(path string) string { | ||
| return strings.TrimLeft(path, "./") | ||
| path = strings.TrimLeft(path, "/") | ||
| path = strings.Replace(path, "../", "", -1) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
unknwon
Author
Member
|
||
| return path | ||
| } | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.11.81.1217 | ||
| 0.11.82.1218 |
How about ".../", "..../" and so on? Or, isn't it safer to fail when path.IsAbs() fails?