Skip to content

Commit

Permalink
neutralize all query params
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-garciad committed Feb 9, 2024
1 parent 40512ae commit 561a7fb
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions steps/http/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net/url"
"path"
"reflect"
"strings"
"time"

"github.com/TelefonicaTC2Tech/golium"
Expand All @@ -49,17 +50,11 @@ const (
DefaultTestURL = "https://jsonplaceholder.typicode.com/"
)

// Sanitize HTTP parameter pollution. CWE:235
func sanitize(queryParams map[string][]string) string {
params := url.Values{}
for key, values := range queryParams {
for _, value := range values {
if !params.Has(key) {
params.Add(key, value)
}
}
}
return params.Encode()
// Neutralize HTTP parameter pollution. CWE:235
func neutralize(p string) string {
p = strings.ReplaceAll(p, "\r", "")
p = strings.ReplaceAll(p, "\n", "")
return p
}

// Session contains the information of a HTTP session (request and response).
Expand Down Expand Up @@ -95,9 +90,17 @@ func (s *Session) URL() (*url.URL, error) {
// * - Reference: https://forum.golangbridge.org/t/how-to-concatenate-paths-for-api-request/5791
// * - Docs: https://pkg.go.dev/path#Join
// */

rawQueryN := sanitize(s.Request.QueryParams)
u.RawQuery = rawQueryN
params := url.Values{}
for key, values := range s.Request.QueryParams {
for _, value := range values {
if !params.Has(key) {
keyN := neutralize(key)
valueN := neutralize(value)
params.Add(keyN, valueN)
}
}
}
u.RawQuery = neutralize(params.Encode())

return u, nil
}
Expand Down

0 comments on commit 561a7fb

Please sign in to comment.