Skip to content

V1.2.0 遇到 CSP 问题 #269

@OOKAMISAMA

Description

@OOKAMISAMA

例行检查 / Checklist

  • 我已确认目前没有类似 issue (I have checked for similar issues)
  • 我已确认我已升级到最新版本 (I have updated to the latest version)
  • 我已完整查看过项目 README,尤其是常见问题部分 (I have read the README, especially the FAQ section)
  • 我理解并愿意跟进此 issue,协助测试和提供反馈 (I am willing to follow up on this issue, assist with testing, and provide feedback)
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭 (I understand and agree to the above, and I understand that the maintainers have limited time, so issues that do not follow the rules may be ignored or closed directly)

问题描述 / Bug Description

目前 1.2.0 版如果遇到配置比较严谨的 Nginx 会被内容安全策略(Content Security Policy, CSP)挡住,导致页面渲染失败。
触发的具体策略是 禁止浏览器执行通过字符串转换来的动态JavaScript代码(如使用 eval() 函数),而网页中的 index-cOsThIc2.js 文件尝试了此类操作,因此被浏览器拦截并报错。

Nginx中的配置内容是
add_header Content-Security-Policy "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;

临时解决方案,在 CSP 策略中放行 eval,存在动态执行脚本的 XSS 风险。
add_header Content-Security-Policy "default-src 'self' 'unsafe-eval' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;

复现步骤 / Steps to Reproduce

  1. Nginx配置 CSP 禁止浏览器使用 eval 即可复现

预期结果 / Expected Behavior

期望可以不使用 eval 等动态执行字符串的方法来实现,降低安全风险。

相关截图 / Screenshots

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions