危险行为 disallowedcontent 让我在某些情况下插入 js
Dangerous behavior disallowedcontent let me insert js in some case
我试图让我的用户可以使用 ckeditor 在他们的 post 中粘贴一些 html 标签。
但是为了避免 XSS 攻击,我已经将其中一些像 script
列入黑名单。
这是我的一部分 config.js
'...'
config.allowedContent = {
: {
elements: CKEDITOR.dtd,
attributes: true,
styles: true,
classes: true
}
};
config.disallowedContent = 'script;';
'...'
config.toolbar_mini = [
{ name: 'paragraph', groups: ['blocks', 'align', 'bidi' ], items: ['Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] },
{ name: 'styles', items: [ 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat' ] },
{ name: 'insert', items: [ 'Imgur', 'tliyoutube2', 'linkfile', 'Source'] },
];
当我点击 Source
添加 html 标签并添加
<script>alert('test')</script
然后我点击 Source
添加非 html 内容并提交我的 post。 CKEDITOR 将按照我的预期正确删除 script
标签。
但如果这样做:
点击Source
然后添加我的脚本标签
<script>alert('test')</script>
并在不退出 Source
模式的情况下提交 post。脚本保存在我的数据库中并执行。
此外,如果我尝试编辑此消息并继续 Source
模式 CKEDITOR 禁用此 script
标签。
显然我必须在我的后端创建验证器来避免这种情况。但我不认为这是 disallowedContent
的正确行为,或者如果是的话我不明白为什么。
我是否错误配置了我的 CKEDITOR 或者这是正确的行为?
Source模式好像没有实现过滤:https://github.com/ckeditor/ckeditor-dev/issues/2326
我会禁用 Source 插件或在 Source 模式下阻止提交。
我试图让我的用户可以使用 ckeditor 在他们的 post 中粘贴一些 html 标签。
但是为了避免 XSS 攻击,我已经将其中一些像 script
列入黑名单。
这是我的一部分 config.js
'...'
config.allowedContent = {
: {
elements: CKEDITOR.dtd,
attributes: true,
styles: true,
classes: true
}
};
config.disallowedContent = 'script;';
'...'
config.toolbar_mini = [
{ name: 'paragraph', groups: ['blocks', 'align', 'bidi' ], items: ['Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] },
{ name: 'styles', items: [ 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat' ] },
{ name: 'insert', items: [ 'Imgur', 'tliyoutube2', 'linkfile', 'Source'] },
];
当我点击 Source
添加 html 标签并添加
<script>alert('test')</script
然后我点击 Source
添加非 html 内容并提交我的 post。 CKEDITOR 将按照我的预期正确删除 script
标签。
但如果这样做:
点击Source
然后添加我的脚本标签
<script>alert('test')</script>
并在不退出 Source
模式的情况下提交 post。脚本保存在我的数据库中并执行。
此外,如果我尝试编辑此消息并继续 Source
模式 CKEDITOR 禁用此 script
标签。
显然我必须在我的后端创建验证器来避免这种情况。但我不认为这是 disallowedContent
的正确行为,或者如果是的话我不明白为什么。
我是否错误配置了我的 CKEDITOR 或者这是正确的行为?
Source模式好像没有实现过滤:https://github.com/ckeditor/ckeditor-dev/issues/2326
我会禁用 Source 插件或在 Source 模式下阻止提交。