javascript - 尝试使用 EJS 时的内容安全策略指令包括
问题描述
我有一个像这样的简单 ejs 文件:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<% include ../../partials/nav.ejs %>
<h1>Hello</h1>
<h4><%= uid %></h4>
</body>
</html>
这是使用 NodeJS 提供的:
app.get('/testing/test/:uid', function (req, res) {
res.render('test', {uid: req.params.uid})
});
目前 nav.ejs 是一个空白文件。
当我删除该<% include ../../partials/nav.ejs %>
行时,页面加载得很好,并且来自 URL 的 uid 被插入到<h4>
标签中。但是,只要我包含该行,我就会收到以下错误:
Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-o6wSC15InKzMdQsAjlOwalELkGSpN0I4/fzIfw2Ckvg='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.
但是,我并不真正理解这一点,因为我在 nav.ejs 或我的主 ehs 文件中都没有样式。没有脚本或类似的东西。它实际上只是一个空白的 ejs 文件,我正在尝试
有人可以帮帮我吗?
解决方案
推荐阅读
- java - 何时以及为什么使用注解绑定?
- c# - 自定义路由在 ASP.NET MVC 应用程序 C# 中给出错误 404
- c++ - Dijkstra 算法运行缓慢
- swiftui - 是否可以从视图绘制线到另一个视图
- php - 我需要在哪里放置 phpunit 的钩子?
- spring - Spring Boot OAUTH2 作用域的不同 uri
- javascript - 使用 Axios 向后端发送 MSAL 令牌
- flutter - Flutter Driver 从滚动选择器中选择
- python - 使用 Panda 的 Apply 函数在使用 Python 的 Google Places API 查询中循环遍历坐标列表 (csv)
- c - 使用c中的scanf将字符输入到枚举变量中