Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic on webhook with nil body #1890

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions selfservice/hook/web_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (e *WebHook) execute(data *templateContext) error {
return fmt.Errorf("failed to parse web hook config: %w", err)
}

var body io.Reader
var body *bytes.Reader
NickUfer marked this conversation as resolved.
Show resolved Hide resolved
if conf.method != "TRACE" {
// According to the HTTP spec any request method, but TRACE is allowed to
// have a body. Even this is a really bad practice for some of them, like for
Expand All @@ -263,6 +263,9 @@ func (e *WebHook) execute(data *templateContext) error {
}
}

if body == nil {
body = bytes.NewReader(make([]byte, 0))
}
if err = doHttpCall(conf.method, conf.url, conf.auth, body); err != nil {
return fmt.Errorf("failed to call web hook %w", err)
}
Expand All @@ -271,7 +274,7 @@ func (e *WebHook) execute(data *templateContext) error {

func createBody(l *logrusx.Logger, templateURI string, data *templateContext) (*bytes.Reader, error) {
if len(templateURI) == 0 {
return nil, nil
return bytes.NewReader(make([]byte, 0)), nil
}

f := fetcher.NewFetcher()
Expand Down