Skip to content

Commit 549e609

Browse files
committed
fix(newrelic): construct URLs via net/url
Guard against potential injection from appName Signed-off-by: 3bbbeau <[email protected]>
1 parent fc16e0e commit 549e609

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pkg/services/newrelic.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"net/url"
910
"strconv"
1011
"strings"
1112
texttemplate "text/template"
@@ -126,8 +127,17 @@ type newrelicApplicationsResponse struct {
126127
}
127128

128129
func (s newrelicService) getApplicationId(client *http.Client, appName string) (string, error) {
129-
applicationsApi := fmt.Sprintf("%s/v2/applications.json?filter[name]=%s", s.opts.ApiURL, appName)
130-
req, err := http.NewRequest(http.MethodGet, applicationsApi, nil)
130+
u, err := url.Parse(s.opts.ApiURL)
131+
if err != nil {
132+
log.Errorf("Failed to parse ApiURL: %s", err)
133+
return "", err
134+
}
135+
u.Path = "/v2/applications.json"
136+
q := u.Query()
137+
q.Set("filter[name]", appName)
138+
u.RawQuery = q.Encode()
139+
140+
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
131141
if err != nil {
132142
return "", fmt.Errorf("Failed to create filtered application request: %s", err)
133143
}
@@ -204,8 +214,15 @@ func (s newrelicService) Send(notification Notification, dest Destination) (err
204214
}
205215
}
206216
}
207-
markerApi := fmt.Sprintf(s.opts.ApiURL+"/v2/applications/%s/deployments.json", appId)
208-
req, err := http.NewRequest(http.MethodPost, markerApi, bytes.NewBuffer(jsonValue))
217+
218+
u, err := url.Parse(s.opts.ApiURL)
219+
if err != nil {
220+
log.Errorf("Failed to parse ApiURL: %s", err)
221+
return err
222+
}
223+
u.Path = fmt.Sprintf("/v2/applications/%s/deployments.json", appId)
224+
225+
req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewBuffer(jsonValue))
209226
if err != nil {
210227
log.Errorf("Failed to create deployment marker request: %s", err)
211228
return err

0 commit comments

Comments
 (0)