forked from Mirrors/gomuks
media: escape html in fallback avatars
This commit is contained in:
parent
8770205965
commit
2dc9954030
2 changed files with 11 additions and 2 deletions
|
@ -38,6 +38,7 @@ import (
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/hlog"
|
"github.com/rs/zerolog/hlog"
|
||||||
_ "golang.org/x/image/webp"
|
_ "golang.org/x/image/webp"
|
||||||
|
"golang.org/x/net/html"
|
||||||
|
|
||||||
"go.mau.fi/util/exhttp"
|
"go.mau.fi/util/exhttp"
|
||||||
"go.mau.fi/util/ffmpeg"
|
"go.mau.fi/util/ffmpeg"
|
||||||
|
@ -147,7 +148,7 @@ func isAllowedAvatarMime(mime string) bool {
|
||||||
|
|
||||||
func (w *avatarResponseWriter) WriteHeader(statusCode int) {
|
func (w *avatarResponseWriter) WriteHeader(statusCode int) {
|
||||||
if statusCode != http.StatusOK && statusCode != http.StatusNotModified {
|
if statusCode != http.StatusOK && statusCode != http.StatusNotModified {
|
||||||
data := []byte(fmt.Sprintf(fallbackAvatarTemplate, w.bgColor, w.character))
|
data := []byte(fmt.Sprintf(fallbackAvatarTemplate, w.bgColor, html.EscapeString(w.character)))
|
||||||
w.Header().Set("Content-Type", "image/svg+xml")
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
||||||
w.Header().Del("Content-Disposition")
|
w.Header().Del("Content-Disposition")
|
||||||
|
|
|
@ -40,9 +40,17 @@ function makeFallbackAvatar(backgroundColor: string, fallbackCharacter: string):
|
||||||
<circle cx="500" cy="500" r="500" fill="${backgroundColor}"/>
|
<circle cx="500" cy="500" r="500" fill="${backgroundColor}"/>
|
||||||
<text x="500" y="750" text-anchor="middle" fill="#fff" font-weight="bold" font-size="666"
|
<text x="500" y="750" text-anchor="middle" fill="#fff" font-weight="bold" font-size="666"
|
||||||
font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"
|
font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"
|
||||||
>${fallbackCharacter}</text>
|
>${escapeHTMLChar(fallbackCharacter)}</text>
|
||||||
</svg>`)
|
</svg>`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHTMLChar(char: string): string {
|
||||||
|
switch (char) {
|
||||||
|
case "&": return "&"
|
||||||
|
case "<": return "<"
|
||||||
|
case ">": return ">"
|
||||||
|
default: return char
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAvatarURL = (userID: UserID, content?: Partial<MemberEventContent>): string | undefined => {
|
export const getAvatarURL = (userID: UserID, content?: Partial<MemberEventContent>): string | undefined => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue