0

fix: disable redirects to guard against possible SSRFs

This commit is contained in:
Gabe Kangas 2023-04-24 17:46:58 -07:00
parent b8fe446152
commit f40135dbf2
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
2 changed files with 15 additions and 2 deletions

View File

@ -29,7 +29,14 @@ func GetWebfingerLinks(account string) ([]map[string]interface{}, error) {
query.Add("resource", fmt.Sprintf("acct:%s", account)) query.Add("resource", fmt.Sprintf("acct:%s", account))
requestURL.RawQuery = query.Encode() requestURL.RawQuery = query.Encode()
response, err := http.DefaultClient.Get(requestURL.String()) // Do not support redirects.
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
response, err := client.Get(requestURL.String())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -80,7 +80,13 @@ func HandleCallbackCode(code, state string) (*Request, *Response, error) {
data.Set("redirect_uri", request.Callback.String()) data.Set("redirect_uri", request.Callback.String())
data.Set("code_verifier", request.CodeVerifier) data.Set("code_verifier", request.CodeVerifier)
client := &http.Client{} // Do not support redirects.
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
r, err := http.NewRequest("POST", request.Endpoint.String(), strings.NewReader(data.Encode())) // URL-encoded payload r, err := http.NewRequest("POST", request.Endpoint.String(), strings.NewReader(data.Encode())) // URL-encoded payload
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err