<script>接受integrity属性,所以我可以安全地加载模块:
<script type="module"
src="https://example.com/module.mjs"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"
></script>
Run Code Online (Sandbox Code Playgroud)
但是在脚本中加载模块时如何保持安全?
import foo from "https://example.com/module.mjs"
Run Code Online (Sandbox Code Playgroud)
import("https://example.com/module.mjs").then(console.log)
Run Code Online (Sandbox Code Playgroud)
const myWorker = new Worker('worker.js')
Run Code Online (Sandbox Code Playgroud) 我有一个带有index.html文件的角度应用程序
在我的index.html页面中考虑我有以下SRI代码(SubResource Integrity)
<html>
<head>
<meta http-equiv="Content-Security-Policy"
content="script-src 'self' scripts/alert.js 'unsafe-inline' 'unsafe-eval' 'sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng='">
<script src="scripts/alert.js"
integrity="sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng="
crossorigin="anonymous"></script>
</head>
</html>Run Code Online (Sandbox Code Playgroud)
如果我使用require JS,那么我必须将'alert.js'的脚本包含到'main.js'文件中,如下所示
require.config({
// alias libraries paths
paths: {
'jquery': '/scripts/alert'
},
// kick start application
deps: ['../app/require.bootstrap']
})Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何在路径中引用alert.js脚本时将integrity属性包含在main.js文件中.