Hi,
I’d like to customize the reply/embedded-post. This requires a modification to the _computeCooked method in post-cooked via a plugin; essentially when this.attrs.embeddedPost is true, render something else.
I noticed it’s easier to override or reopen ‘conventional’ Ember classes or the widgets created using ‘createWidget’. What would be the best way to achieve this for the PostCooked class?
你找到解决办法了吗?如果你能分享出来,我将非常高兴。
我不太确定,我还没仔细研究。我想替换
return true;
}
this._toggleQuote($aside);
});
$title.data("has-quote-controls", true);
}
}
});
}
_computeCooked() {
const cookedDiv = createDetachedElement("div");
cookedDiv.classList.add("cooked");
if (
(this.attrs.firstPost || this.attrs.embeddedPost) &&
this.ignoredUsers &&
this.ignoredUsers.length > 0 &&
this.ignoredUsers.includes(this.attrs.username)
) {
cookedDiv.classList.add("post-ignored");
中的_computedCooked,按类别进行替换。
我想将
cookedDiv.innerHTML = this.attrs.cooked;
替换为根据类别自定义的内容。但这确实有道理。使用 decorateCooked 也应该可以实现。阅读了一些资料后,decorateCookedElement 似乎是正确的选择,因为我不想使用 jQuery。太感谢了
折腾了一天之后,我找到了这个答案。
Is it possible to mount a widget into a post from decorateCooked? The polls plugin seems to do some funky stuff with Ember components/controllers/templates, and a set of widgets seem like they might be easier to work with.
看来之前的努力白费了,我需要换个方向。
当我将 elem.innerHTML 设置为 <script>alert(1)</script> 时,它会被反转为未转义的形式:<script>alert(1)</script>(我在作曲器中输入时就能看到,如果直接输入未转义的内容,预览中会被移除)。这是个问题吗?还是 CSP 会阻止它?
https://meta.discourse.org/t/mitigate-xss-attacks-with-content-security-policy/104243! csp 错误|690x191
包含 <script> 标签作为解释一部分的帖子似乎也会触发这些 CSP 错误。我现在非常困惑。我是否还需要担心存储型 XSS?还是 CSP 会直接拦截它?在作曲器中,我使用的是 CKEditor,它可以防止自 XSS(self-XSS)。如果我确实需要担心,似乎应该过滤掉不安全的标签。目前我使用的是:
value = Loofah.fragment(value).scrub!(:escape).to_s
但这似乎完全没有效果,因为将 elem.innerHTML 设置为这个值后,HTML 实体仍然会被反转为原始 HTML。
编辑:我终于找到了困惑的根源:使用“检查元素”功能时,它不会显示真实的 HTML,而是会直接转换 HTML 实体。
如果你在检查器中点击“编辑为 HTML