Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Prevent remote image injection with /img/emoji/ in url (#1245)

Meisam3cbc2fdd2ee2
diff --git a/core/chat/events/events.go b/core/chat/events/events.go
index a66f444779..8c2e4ae83b 100644
--- a/core/chat/events/events.go
+++ b/core/chat/events/events.go
@@ -139,7 +139,7 @@ func sanitize(raw string) string {
p.AllowElements("br", "p")
// Allow img tags from the the local emoji directory only
- p.AllowAttrs("src").Matching(regexp.MustCompile(`(?i)/img/emoji`)).OnElements("img")
+ p.AllowAttrs("src").Matching(regexp.MustCompile(`(?i)^/img/emoji`)).OnElements("img")
p.AllowAttrs("alt", "title").Matching(regexp.MustCompile(`:\S+:`)).OnElements("img")
p.AllowAttrs("class").OnElements("img")
diff --git a/core/chat/messageRendering_test.go b/core/chat/messageRendering_test.go
index 609b5d3ae9..6a740f8cb6 100644
--- a/core/chat/messageRendering_test.go
+++ b/core/chat/messageRendering_test.go
@@ -33,7 +33,7 @@ blah blah blah
// Test to make sure we block remote images in chat messages.
func TestBlockRemoteImages(t *testing.T) {
- messageContent := `<img src="https://via.placeholder.com/350x150"> test ![](https://via.placeholder.com/350x150)`
+ messageContent := `<img src="https://via.placeholder.com/img/emoji/350x150"> test ![](https://via.placeholder.com/img/emoji/350x150)`
expected := `<p> test </p>`
result := events.RenderAndSanitize(messageContent)