首页 > 解决方案 > 尝试使用 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 文件,我正在尝试

有人可以帮帮我吗?

标签: javascriptnode.jsejs

解决方案


推荐阅读