-
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webview: Escape *everything* that isn't intended as HTML.
If a message topic contained HTML metacharacters such as `<` and `&`, we would nevertheless pass it right through into the rendered HTML. Because topics are arbitrary text controlled by other users, that is a bug and potentially a security vulnerability. I tested with a topic of `hello <strong>topic</strong>`, as a proof of concept -- and indeed I got the words "hello topic", with the latter word in bold. Fix that. Also fix the many other places our code would recklessly interpolate into HTML a value which is intended as text, not HTML. Some of the places we fix happen to never contain HTML metacharacters; others it'd take some work to be sure, and some look quite suspicious. Rather than try to be clever to save a few microseconds where the escaping happens not to matter, apply the only sane policy: *every* value that isn't intended to function as live HTML, we escape. The syntax used in this commit is kind of ugly, but it's a darn sight better than suffering HTML injection, and it was quick to sweep through systematically. Nicer syntax to come.
- Loading branch information
Showing
7 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
/* @flow */ | ||
import escape from 'lodash.escape'; | ||
import type { ReactionType } from '../../types'; | ||
import emojiMap from '../../emoji/emojiMap'; | ||
|
||
const getRealmEmojiHtml = (realmEmoji: ReactionType): string => | ||
`<img class="realm-reaction" src="${realmEmoji.source_url}"/> | ||
`<img class="realm-reaction" src="${escape(realmEmoji.source_url)}"/> | ||
`; | ||
|
||
export default (messageId: number, reaction: ReactionType, realmEmoji: Object): string => | ||
`<span onClick="" class="reaction${reaction.selfReacted ? ' self-voted' : ''}" data-name="${ | ||
reaction.name | ||
}" data-code="${reaction.code}" data-type="${reaction.type}">${ | ||
`<span onClick="" class="reaction${escape(reaction.selfReacted ? ' self-voted' : '')}" | ||
data-name="${escape(reaction.name)}" | ||
data-code="${escape(reaction.code)}" | ||
data-type="${escape(reaction.type)}">${ | ||
realmEmoji[reaction.name] | ||
? getRealmEmojiHtml(realmEmoji[reaction.name]) | ||
: emojiMap[reaction.name] | ||
} ${reaction.count} | ||
} ${escape(reaction.count)} | ||
</span>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/* @flow */ | ||
import escape from 'lodash.escape'; | ||
import type { Message } from '../../types'; | ||
import { humanDate } from '../../utils/date'; | ||
|
||
export default (timestamp: number, nextMessage: Message): string => ` | ||
<div class="timerow" data-msg-id="${nextMessage.id}"> | ||
<div class="timerow" data-msg-id="${escape(nextMessage.id)}"> | ||
<div class="timerow-left"></div> | ||
${humanDate(new Date(timestamp * 1000))} | ||
${escape(humanDate(new Date(timestamp * 1000)))} | ||
<div class="timerow-right"></div> | ||
</div> | ||
`; |