有没有人成功地将 CSP 添加到 Nuxt 应用程序?
我尝试过Helmet,但它似乎与 nuxt.config.js 文件不兼容。
还尝试在 Nuxt的Render 属性上添加 csp ,但在某些脚本需要 nonce 时遇到了问题。
这是我的 nuxt.config.js 中 Render 属性的要点,这对吗?
你如何在 Nuxt 中生成随机数?
render: {
csp: {
hashAlgorithm: 'sha256',
policies: {
'script-src': [
'self',
'unsafe-inline',
'http://assets.adobedtm.com',
'https://cdn.polyfill.io/',
'https://www.everestjs.net',
'https://www.google-analytics.com',
'http://localhost:8001',
"'sha256-<hash>'"
],
},
reportOnly: false,
addMeta: true
}
},
Run Code Online (Sandbox Code Playgroud) 我正在使用WordPress REST API构建密码更改表单.用户输入一个新密码,然后通过AJAX提交给自定义端点,该端点执行以下操作:
$userID = get_current_user_id();
wp_set_password($password, $userID);
//Log user in and update auth cookie
wp_set_current_user($userID);
wp_set_auth_cookie($userID);
//Set the cookie immediately
$_COOKIE[AUTH_COOKIE] = wp_generate_auth_cookie($userID, 2 * DAY_IN_SECONDS);
//Return fresh nonce
return new WP_Rest_Response(array(
'nonce' => wp_create_nonce('wp_rest')
));
Run Code Online (Sandbox Code Playgroud)
端点应自动将用户登录并返回新的nonce,以便他们不必再使用新密码登录.
问题是返回的nonce完全相同且无效.我只能在页面刷新后获得新的nonce.似乎WordPress依赖于生成随机数的一些$_COOKIE或$_SESSION变量在页面刷新之前不会更新.
谢谢你的帮助.
我有一个使用Azure活动目录在azure中运行的应用程序.一些用户刚刚报告尝试访问该应用时出现此错误.我可以访问它,所以很多其他用户,只有某些用户遇到问题,就会出现错误消息
IDX10311:RequireNonce为true(默认值),但validationContext.Nonce为null.Nonce无法验证.如果您不需要检查现时,请将OpenIdConnectProtocolValidator.RequireNonce设置为false
我用谷歌搜索它,但我找不到解决方案,还有其他人遇到过这个问题吗?我该如何解决?
我正在编写一个应用程序,用户可以通过端到端加密在设备之间进行通信.为此,我使用libsodium加密库.非对称加密函数crypto_box(...)需要一个nonce作为参数之一.
我对如何处理nonce有点困惑.是否需要使用不同的nonce加密每个人的消息?这似乎不正确,因为我必须将使用过的nonces存储在具有公共访问权限的服务器上,攻击者可以再次使用其中一个使用过的nonce.
从A到B发送的所有消息都具有不同的nonce或者nonce用于从A发送到B的消息是否足以用于从C发送到B?
有人可以向我解释一下.
我需要向 webpack 创建的内联脚本添加一个随机数,但我找不到任何关于如何配置它的文档。我找到了这个公关:https : //github.com/webpack/webpack/pull/3210/files但我不知道如何__webpack_nonce__在我的开发环境中进行设置。
我了解创建自己的模板时使用随机数的过程。但是我正在开发一个 ReactJS 应用程序,它只使用 Wordpress REST API 来提取数据,所以用户永远不会访问 index.php,而是对 WP Rest Api 进行 Ajax 调用。
现在我无法让 nonce 工作。这是我到目前为止所做的:
我添加了以下端点:
register_rest_route('frontend', '/customer/', array(
'methods' => 'GET',
'callback' => 'get_customer'
));
register_rest_route('frontend', '/customer/', array(
'methods' => 'POST',
'callback' => 'create_user_and_login'
));
Run Code Online (Sandbox Code Playgroud)
这些是我的功能:
function get_customer()
{
return get_current_user_id();
}
function create_user_and_login(){
// dummy data for testing
$credentials = ['user_login' => 'mail@mymail.de', 'user_password' => 'XXXX', 'remember' => true];
// create a new user/customer via woocommerce
$customerId = wc_create_new_customer($credentials['user_login'], $credentials['user_login'], $credentials['user_password']);
if(is_a($customerId,'WP_Error')) {
return $customerId;
} …Run Code Online (Sandbox Code Playgroud) 我在 ASP.NET MVC 4 中开发了 MVC 应用程序。我在几个页面中使用了 javascripts。一些 javascripts 被引用为
@Scripts.Render("~/Scripts/bootstrap")
@Scripts.Render("~/Scripts/js")
Run Code Online (Sandbox Code Playgroud)
还有一些内联脚本,比如
<script type="javascript">
// javascript code
</script>
Run Code Online (Sandbox Code Playgroud)
我想为这个网站实施内容安全政策。该站点托管在 IIS 中。所以在 IIS 中,我在 HTTP 响应头中添加 content-security-policy 头作为
object-src 'none';
?script-src 'nonce-{random}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
?base-uri 'self';
?report-uri https://csp.withgoogle.com/csp/<unique_id>/<application_version>
Run Code Online (Sandbox Code Playgroud)
因此,每个响应都将包含此标头。
问题:
我正在尝试使用WSE 3.0从MVC3 .NET Web应用程序调用Java Web Service.
但是,Web服务在UsernameToken的Nonce元素上需要"EncodingType"属性.以下是一个示例SOAP信封,可以正常使用此Java Web服务:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="http://schema.mydomain.org/sms/v1_0">
<soap:Header>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>myUsername</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">XQkp6oYc3DRv41cxkSTW8w==</wsse:Nonce>
<wsu:Created>2011-09-13T20:50:08.355Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<v1:ping/>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
以下是从VS2010生成的代理生成的SOAP信封(在Fiddler中捕获):
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsse:Security env:mustUnderstand="true">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-111f922b-72c1-4057-bce4-f6555552ce6a">
<wsse:Username>myUsername</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPassword</wsse:Password>
<wsse:Nonce>qYse3Lor9sAJ9pKPefgkKQ==</wsse:Nonce>
<wsu:Created>2011-09-13T20:50:38Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
<soap:Body>
<v1:ping/>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
如果缺少此属性,则此Web服务将返回"提供了无效的安全令牌(处理用户名令牌时发生错误)"
如何添加EncodingType属性?
在内容安全策略的上下文中,如果元素具有nonce相应策略中指定的属性,则可以从策略中排除元素。
显然这适用于一些 HTML 元素,例如<script nonce="...">和<style nonce="..."。然而,对于某些人来说,它不起作用,例如<iframe nonce="..." >。
在MDN 文档中写了提示:
注:该CSP
nonce源只能申请nonceable元素(例如作为<img>元素没有nonce属性,也没有办法把它与该CSP源关联)。
是否有完整的 nonceable 元素列表?
MDN 列出了nonce脚本和样式标签的属性。另一方面,该元素没有列出该nonce属性,但无论如何都可以使用。还有更多这样的元素吗?<link>
附带问题:为什么是<img>而<iframe>不是 nonceable?
我的 xyz.js 文件中有以下代码。
\ninit : function() {\n if (!this.iframe) {\n this.iframe = document.createElement("iframe");\n this.iframe.src = "javascript:false;";\n document.body.appendChild(this.iframe);\nRun Code Online (Sandbox Code Playgroud)\n我已将代码从不安全内联更新为随机数\在我调用的上面代码\xc2\xa0document.body.appendChild(this.iframe);
并低于错误
\n\n\n1683098036010:402 拒绝运行 JavaScript URL,因为它违反了以下内容安全策略指令:“script-src 'self' 'nonce-EDNnf03nceIOfn39fn3e9h3sdfa' 'unsafe-eval'”。启用内联执行需要“unsafe-inline”关键字、哈希值(“sha256-...”)或随机数(“nonce-...”)。请注意,哈希不适用于事件处理程序、样式属性和 javascript: 导航,除非存在“unsafe-hashes”关键字
\n
我尝试按如下方式添加随机数,但它不起作用\xc2\xa0
\nthis.iframe.nonce = "EDNnf03nceIOfn39fn3e9h3sdfa";\nthis.iframe.script='nonce="EDNnf03nceIOfn39fn3e9h3sdfa"';\nthis.iframe.script.nonce="EDNnf03nceIOfn39fn3e9h3sdfa";\nthis.iframe.setAttribute('nonce', "EDNnf03nceIOfn39fn3e9h3sdfa");\nRun Code Online (Sandbox Code Playgroud)\n正如在代码中我设置了 this.iframe.src = "javascript:false;"; 这不应该引发该错误。
\n任何人都可以提供这方面的更新吗
\n