{"id":3419,"date":"2024-11-10T13:10:17","date_gmt":"2024-11-10T05:10:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3419\/"},"modified":"2024-11-10T13:10:17","modified_gmt":"2024-11-10T05:10:17","slug":"js%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2%e5%88%ab%e5%a4%96%e6%9d%a5js","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3419\/","title":{"rendered":"js\u5982\u4f55\u9632\u6b62\u522b\u5916\u6765js"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08csp\uff09\u53ef\u4ee5\u9632\u6b62\u5916\u90e8 js \u6267\u884c\u3002csp \u662f\u4e00\u79cd http \u54cd\u5e94\u5934\uff0c\u5141\u8bb8\u7f51\u7ad9\u7ba1\u7406\u5458\u63a7\u5236\u6d4f\u89c8\u5668\u53ef\u4ee5\u52a0\u8f7d\u7684\u811a\u672c\u6e90\u3002\u901a\u8fc7\u8bbe\u7f6e &#8220;script-src&#8221; \u6307\u4ee4\uff0c\u53ef\u4ee5\u9650\u5236\u6d4f\u89c8\u5668\u4ec5\u4ece\u7f51\u7ad9\u81ea\u8eab\u57df\u52a0\u8f7d\u811a\u672c\uff0c\u4ece\u800c\u9632\u6b62\u6765\u81ea\u5176\u4ed6\u6765\u6e90\u7684\u5916\u90e8 js \u6267\u884c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110812001845186.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u9632\u6b62\u522b\u5916\u6765js\u63d2\u56fe\" alt=\"js\u5982\u4f55\u9632\u6b62\u522b\u5916\u6765js\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff1f<\/strong><\/p>\n<p><strong>\u7b80\u8981\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 JavaScript \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\u7684\u65b9\u6cd5\u4e4b\u4e00\u662f\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08CSP\uff09\u3002CSP \u5141\u8bb8\u7f51\u7ad9\u7ba1\u7406\u5458\u63a7\u5236\u6d4f\u89c8\u5668\u53ef\u4ee5\u52a0\u8f7d\u7684\u811a\u672c\u6e90\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u89e3\u7b54\uff1a<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08CSP\uff09\uff1f<\/strong><\/p>\n<p>CSP \u662f\u4e00\u79cd HTTP \u54cd\u5e94\u5934\uff0c\u5b83\u6307\u793a\u6d4f\u89c8\u5668\u5141\u8bb8\u6216\u963b\u6b62\u4ece\u7279\u5b9a\u6765\u6e90\u52a0\u8f7d\u8d44\u6e90\uff0c\u5305\u62ec\u811a\u672c\u3001\u6837\u5f0f\u8868\u548c\u56fe\u50cf\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 CSP \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff1f<\/strong><\/p>\n<p>\u8981\u4f7f\u7528 CSP \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff0c\u60a8\u9700\u8981\u5728 HTTP \u54cd\u5e94\u5934\u4e2d\u8bbe\u7f6e &#8220;script-src&#8221; \u6307\u4ee4\u3002\u8be5\u6307\u4ee4\u6307\u5b9a\u6d4f\u89c8\u5668\u53ef\u4ee5\u4ece\u54ea\u4e9b\u6e90\u52a0\u8f7d\u811a\u672c\u3002\u60a8\u53ef\u4ee5\u5c06\u5176\u8bbe\u7f6e\u4e3a\u4ec5\u5141\u8bb8\u6765\u81ea\u7f51\u7ad9\u81ea\u8eab\u57df\u7684\u811a\u672c\u52a0\u8f7d\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>Content-Security-Policy: script-src 'self';<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u963b\u6b62\u6d4f\u89c8\u5668\u52a0\u8f7d\u6765\u81ea\u4efb\u4f55\u5176\u4ed6\u6e90\u7684\u811a\u672c\u3002<\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u7684 CSP \u7b56\u7565\u4e0d\u4f1a\u610f\u5916\u963b\u6b62\u60a8\u7f51\u7ad9\u4e0a\u5fc5\u9700\u7684\u811a\u672c\u3002<\/li>\n<li>\u5b9a\u671f\u5ba1\u67e5\u60a8\u7684 CSP \u7b56\u7565\u4ee5\u786e\u4fdd\u5176\u662f\u6700\u65b0\u7684\u3002<\/li>\n<li>CSP \u53ea\u80fd\u9632\u6b62\u6d4f\u89c8\u5668\u52a0\u8f7d\u5916\u90e8\u811a\u672c\uff0c\u4f46\u4e0d\u80fd\u9632\u6b62\u5176\u4ed6\u7c7b\u578b\u7684\u653b\u51fb\uff0c\u4f8b\u5982\u8de8\u7ad9\u811a\u672c\uff08XSS\uff09\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u9632\u6b62\u522b\u5916\u6765js\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08csp\uff09\u53ef\u4ee5\u9632\u6b62\u5916\u90e8 js \u6267\u884c\u3002csp \u662f\u4e00\u79cd http \u54cd\u5e94\u5934\uff0c\u5141\u8bb8\u7f51\u7ad9\u7ba1\u7406\u5458\u63a7\u5236\u6d4f\u89c8\u5668\u53ef\u4ee5\u52a0\u8f7d\u7684\u811a\u672c\u6e90\u3002\u901a\u8fc7\u8bbe\u7f6e &#8220;script-src&#8221; \u6307\u4ee4\uff0c\u53ef\u4ee5\u9650\u5236\u6d4f\u89c8\u5668\u4ec5\u4ece\u7f51\u7ad9\u81ea\u8eab\u57df\u52a0\u8f7d\u811a\u672c\uff0c\u4ece\u800c\u9632\u6b62\u6765\u81ea\u5176\u4ed6\u6765\u6e90\u7684\u5916\u90e8 js \u6267\u884c\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff1f \u7b80\u8981\u56de\u7b54\uff1a \u4f7f\u7528 JavaScript \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\u7684\u65b9\u6cd5\u4e4b\u4e00\u662f\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08CSP\uff09\u3002CSP \u5141\u8bb8\u7f51\u7ad9\u7ba1\u7406\u5458\u63a7\u5236\u6d4f\u89c8\u5668\u53ef\u4ee5\u52a0\u8f7d\u7684\u811a\u672c\u6e90\u3002 \u8be6\u7ec6\u89e3\u7b54\uff1a \u4ec0\u4e48\u662f\u5185\u5bb9\u5b89\u5168\u7b56\u7565\uff08CSP\uff09\uff1f CSP \u662f\u4e00\u79cd HTTP \u54cd\u5e94\u5934\uff0c\u5b83\u6307\u793a\u6d4f\u89c8\u5668\u5141\u8bb8\u6216\u963b\u6b62\u4ece\u7279\u5b9a\u6765\u6e90\u52a0\u8f7d\u8d44\u6e90\uff0c\u5305\u62ec\u811a\u672c\u3001\u6837\u5f0f\u8868\u548c\u56fe\u50cf\u3002 \u5982\u4f55\u4f7f\u7528 CSP \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff1f \u8981\u4f7f\u7528 CSP \u9632\u6b62\u5916\u90e8 JS \u6267\u884c\uff0c\u60a8\u9700\u8981\u5728 HTTP \u54cd\u5e94\u5934\u4e2d\u8bbe\u7f6e &#8220;script-src&#8221; \u6307\u4ee4\u3002\u8be5\u6307\u4ee4\u6307\u5b9a\u6d4f\u89c8\u5668\u53ef\u4ee5\u4ece\u54ea\u4e9b\u6e90\u52a0\u8f7d\u811a\u672c\u3002\u60a8\u53ef\u4ee5\u5c06\u5176\u8bbe\u7f6e\u4e3a\u4ec5\u5141\u8bb8\u6765\u81ea\u7f51\u7ad9\u81ea\u8eab\u57df\u7684\u811a\u672c\u52a0\u8f7d\uff0c\u5982\u4e0b\u6240\u793a\uff1a Content-Security-Policy: script-src &#8216;self&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u963b\u6b62\u6d4f\u89c8\u5668\u52a0\u8f7d\u6765\u81ea\u4efb\u4f55\u5176\u4ed6\u6e90\u7684\u811a\u672c\u3002 \u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a \u786e\u4fdd\u60a8\u7684 CSP \u7b56\u7565\u4e0d\u4f1a\u610f\u5916\u963b\u6b62\u60a8\u7f51\u7ad9\u4e0a\u5fc5\u9700\u7684\u811a\u672c\u3002 \u5b9a\u671f\u5ba1\u67e5\u60a8\u7684 CSP \u7b56\u7565\u4ee5\u786e\u4fdd\u5176\u662f\u6700\u65b0\u7684\u3002 CSP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3419","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3419"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3419\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}