Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
fix(webhooks): handle invalid destinations safely
Gabe Kangasa3247cd621cd
diff --git a/services/webhooks/webhooks_test.go b/services/webhooks/webhooks_test.goindex 9c51242166..7b5eb0f635 100644--- a/services/webhooks/webhooks_test.go+++ b/services/webhooks/webhooks_test.go@@ -111,6 +111,23 @@ func TestPublicSend(t *testing.T) {wg.Wait()}+func TestMalformedWebhookURLReturnsError(t *testing.T) {+ repo := webhookrepository.New(testDatastore)+ hook, err := repo.InsertWebhook("http://example.com", []models.EventType{models.MessageSent}, "secret")+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = repo.DeleteWebhook(hook) })++ err = testSvc.sendWebhook(Job{+ payload: WebhookEvent{Type: models.MessageSent, EventData: struct{}{}},+ webhook: models.Webhook{ID: hook, URL: "http://example.com/\x01"},+ })+ if err == nil {+ t.Fatal("expected malformed webhook URL to return an error")+ }+}+// Every event dispatched to webhooks is also published to the shared// dispatcher, regardless of whether any HTTP webhook destinations exist —// this is how in-process consumers (the plugin host) receive events.diff --git a/services/webhooks/workerpool.go b/services/webhooks/workerpool.goindex 482ba14458..d306d88d5f 100644--- a/services/webhooks/workerpool.go+++ b/services/webhooks/workerpool.go@@ -6,6 +6,7 @@ import ("net/http""runtime""sync"+ "time"log "github.com/sirupsen/logrus"@@ -122,6 +123,9 @@ func (s *Service) sendWebhook(job Job) error {}req, err := http.NewRequest("POST", job.webhook.URL, bytes.NewReader(jsonText))+ if err != nil {+ return err+ }signature, err := s.generateSignature(jsonText, job)if err != nil {return err@@ -130,7 +134,7 @@ func (s *Service) sendWebhook(job Job) error {req.Header.Set("owncast-signature", signature)req.Header.Set("Content-Type", "application/json")- client := &http.Client{}+ client := &http.Client{Timeout: 30 * time.Second}resp, err := client.Do(req)if err != nil {