我正在将我的 NodeJS(http+websocket)/vanillaJS 移动到 express+websocket/(希望是 React)。我想用 ExpressJS 为 script-src 实现 CSP-nonce,用于静态文件。我已经设法使用加密和头盔 csp 动态设置标题。
但是,我坚持在每个脚本标签上设置 nonce 值并仍在使用 express.static 函数(在 docs/web/stacko 上也找不到任何东西......)我只是替换了原始 http 模块'<script type="text/javascript"' 部分与 nonce 生成的值。
有没有办法做到这一点并且仍然使用 express-static?(我知道它说的是静态的,但这似乎是一个有用的功能,即使对于静态文件)。如果没有(因为我是新来表达的)是否有标准/最佳实践方式来做到这一点?还是一个众所周知的使用模块?谢谢!