File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,16 @@ func NullString(v string) *string {
36
36
37
37
// ToSafeURL produces a safe (no path traversal, no unsafe characters) URL
38
38
// from the path components passed in.
39
+ //
40
+ // Unlike the normal behavior of url.JoinPath, this function skips
41
+ // ".." components, ensuring that user-provided components cannot
42
+ // remove code-provided components from the resulting path.
39
43
func ToSafeURL (unsafeComponents ... string ) string {
40
44
safeComponents := make ([]string , len (unsafeComponents ))
41
45
42
46
for i := range unsafeComponents {
43
- if component := unsafeComponents [i ]; component != ".." {
44
- safeComponents [i ] = url .PathEscape (component )
47
+ if unsafeComponents [i ] != ".." {
48
+ safeComponents [i ] = url .PathEscape (unsafeComponents [ i ] )
45
49
}
46
50
}
47
51
You can’t perform that action at this time.
0 commit comments