Skip to content

Commit ba653cc

Browse files
committed
Apply moar review feedback.
1 parent 6ec5f86 commit ba653cc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fastly/helpers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ func NullString(v string) *string {
3636

3737
// ToSafeURL produces a safe (no path traversal, no unsafe characters) URL
3838
// 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.
3943
func ToSafeURL(unsafeComponents ...string) string {
4044
safeComponents := make([]string, len(unsafeComponents))
4145

4246
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])
4549
}
4650
}
4751

0 commit comments

Comments
 (0)