diff --git a/pkg/locale/input_test.go b/pkg/locale/input_test.go index 06c679223..fa44dbc4f 100644 --- a/pkg/locale/input_test.go +++ b/pkg/locale/input_test.go @@ -16,6 +16,9 @@ func Test_SanitizeMessage(t *testing.T) { {"accents", "čšž", "čšž"}, {"safe html", "čšž", "čšž"}, {"unsafe html", `XSS`, "XSS"}, + + {"regular link", `home`, `home`}, + {"link with target", `home`, `home`}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/xss/rich_text.go b/pkg/xss/rich_text.go index 47dc576f1..7c7cdc21c 100644 --- a/pkg/xss/rich_text.go +++ b/pkg/xss/rich_text.go @@ -17,6 +17,10 @@ func RichText(in string) string { p.AllowStyles("color").Matching(regexp.MustCompile("(?i)^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$")).Globally() p.AllowStyles("background-color").Matching(regexp.MustCompile("(?i)^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$")).Globally() + // some link specifics we need; allow target but assure safety + p.AllowAttrs("target").OnElements("a") + p.AddTargetBlankToFullyQualifiedLinks(false) + sanitized := p.Sanitize(in) // handle escaped strings and unescape them