Skip to content

Commit

Permalink
Apply moar review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfleming committed Sep 8, 2024
1 parent 6ec5f86 commit ba653cc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fastly/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ func NullString(v string) *string {

// ToSafeURL produces a safe (no path traversal, no unsafe characters) URL
// from the path components passed in.
//
// Unlike the normal behavior of url.JoinPath, this function skips
// ".." components, ensuring that user-provided components cannot
// remove code-provided components from the resulting path.
func ToSafeURL(unsafeComponents ...string) string {
safeComponents := make([]string, len(unsafeComponents))

for i := range unsafeComponents {
if component := unsafeComponents[i]; component != ".." {
safeComponents[i] = url.PathEscape(component)
if unsafeComponents[i] != ".." {
safeComponents[i] = url.PathEscape(unsafeComponents[i])
}
}

Expand Down

0 comments on commit ba653cc

Please sign in to comment.