mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
SECURITY: Remove XSS in composer preview when applying image scale buttons.
This commit is contained in:
@ -878,15 +878,13 @@ export default Ember.Component.extend({
|
|||||||
if ($preview.find(".codeblock-image").length === 0) {
|
if ($preview.find(".codeblock-image").length === 0) {
|
||||||
this.$(".d-editor-preview *")
|
this.$(".d-editor-preview *")
|
||||||
.contents()
|
.contents()
|
||||||
.filter(function() {
|
|
||||||
return this.nodeType === 3; // TEXT_NODE
|
|
||||||
})
|
|
||||||
.each(function() {
|
.each(function() {
|
||||||
$(this).replaceWith(
|
if (this.nodeType !== 3) return; // TEXT_NODE
|
||||||
$(this)
|
const $this = $(this);
|
||||||
.text()
|
|
||||||
.replace(imageScaleRegex, "<span class='codeblock-image'>$&</a>")
|
if ($this.text().match(imageScaleRegex)) {
|
||||||
);
|
$this.wrap("<span class='codeblock-image'></span>");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,4 +754,20 @@ QUnit.test("Image resizing buttons", async assert => {
|
|||||||
uploads[9] = "";
|
uploads[9] = "";
|
||||||
await click(find(".button-wrapper .scale-btn[data-scale='75']")[5]);
|
await click(find(".button-wrapper .scale-btn[data-scale='75']")[5]);
|
||||||
assertImageResized(assert, uploads);
|
assertImageResized(assert, uploads);
|
||||||
|
|
||||||
|
await fillIn(
|
||||||
|
".d-editor-input",
|
||||||
|
`
|
||||||
|

|
||||||
|
|
||||||
|
\`<script>alert("xss")</script>\`
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
await triggerEvent($(".d-editor-preview img"), "mouseover");
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
find("script").length === 0,
|
||||||
|
"it does not unescapes script tags in code blocks"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user