当前位置: 首页 > news >正文

解决Content Security Policy (CSP)问题

在这里插入图片描述

在这里插入图片描述
做的一个简单的自动识别图片文字是否一致的程序 引用的百度的OCR 在公司的代码运行正常 在家运行报错了

Refused to apply inline style because it violates the following Content Security Policy directive: “default-src ‘none’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-QIjW/+aUzfg58HcITJNHkkCTGmLovNUIQbL+Zq2TsIE=’), or a nonce (‘nonce-…’) is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the ‘unsafe-hashes’ keyword is present. Note also that ‘style-src’ was not explicitly set, so ‘default-src’ is used as a fallback. g @ customElements.js:1 customElements.js:1 Refused to apply inline style because it violates the following Content Security Policy directive: “default-src ‘none’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-QIjW/+aUzfg58HcITJNHkkCTGmLovNUIQbL+Zq2TsIE=’), or a nonce (‘nonce-…’) is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the ‘unsafe-hashes’ keyword is present. Note also that ‘style-src’ was not explicitly set, so ‘default-src’ is used as a fallback. g @ customElements.js:1 prepare.js:1 Refused to execute inline script because it violates the following Content Security Policy directive: “default-src ‘none’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-3bzWVxQE32IZQKH9eh8KzyHuhXOlMrboDVVBRd0fWTU=’), or a nonce (‘nonce-…’) is required to enable inline execution. Note also that ‘script-src’ was not explicitly set, so ‘default-src’ is used as a fallback. c @ prepare.js:1 (索引):1 Failed to load resource: the server responded with a status of 404 (Not Found)

Content Security Policy (CSP) 的问题把 inline style 和 inline script 全部拦掉了

解决方法
方法 1:关闭 CSP

用 VS Code 的 Live Server 插件或 http-server 跑,不要用直接打开 file://。
再或者在浏览器里启动的时候加上参数关闭 CSP,比如 Chrome:chrome.exe --disable-web-security --user-data-dir=c:\temp\chrome

方法 2:修改 CSP 规则

如果你控制的是自己服务器,可以在响应头里加:
Content-Security-Policy: default-src * ‘unsafe-inline’ ‘unsafe-eval’ data: blob:
这样就允许内联的

方法 3:修改你现在的代码

你现在的代码里有:

这样就不会触发 inline 的 CSP 限制。

http://www.dtcms.com/a/361431.html

相关文章:

  • Sparse4Dv3 部署到 TensorRT-(1)
  • Gradle vs. Maven,Java 构建工具该用哪个?
  • Paimon MergeTreeWrite、Compaction 和 快照构建
  • 嵌入式解谜日志之Linux操作系统—进程间的通信(IPC):无名管道,有名管道,信号通信5
  • 单片机元件学习
  • 【stm32】定时器(超详细)
  • Git安装教程
  • 【51页PPT】智慧社区解决方案(附下载方式)
  • 审美积累 | 金融类 SaaS 产品落地页设计
  • Empire: LupinOne靶场渗透
  • 贪心算法解决固定长度区间覆盖问题:最少区间数计算
  • CICD实战(2) - 使用Arbess+GitLab+SonarQube实现Java项目快速扫描/构建/部署
  • 【MySQL详解】索引、事务、锁、日志
  • 【C++上岸】C++常见面试题目--数据结构篇(第十六期)
  • 科学研究系统性思维的方法体系:数据收集
  • 11,FreeRTOS队列理论知识
  • linux内核 - ext 文件系统介绍
  • 嵌入式学习日志————I2C通信外设
  • 拥抱智能高效翻译 ——8 款视频翻译工具深度测评
  • Linux Shell 脚本中括号类型及用途
  • 【项目思维】嵌入式产业链与技术生态
  • 2025 最新React前端面试题目 (9月最新)
  • Windows Qt5.15.17源码使用VS2019编译安装
  • 六、练习3:Gitee平台操作
  • 瑞芯微RK3576平台FFmpeg硬件编解码移植及性能测试实战攻略
  • 深入掌握 Flask 配置管理:从基础到高级实战
  • 校园网IP地址要如何管理
  • MySQL基础知识保姆级教程(四)基础语句
  • 人工智能学习:NLP文本处理的基本方法
  • C++函数执行时间统计工具:轻量级性能分析的最佳实践