Angular 生产中文件上传违反内容安全政策
Angular Content Security Policy violation in production on file upload
我有一个 angular 应用程序,用户可以在其中上传和提交图像,在本地工作时一切正常,但是一旦我构建了我的项目并托管了它,我在尝试上传时遇到违反内容安全策略的错误通过 file input
并显示图像的 预览 的图像。
这是我遇到的错误示例:
Refused to load the image 'data:image/png;base64,/9j/...' because it violates the following
Content Security Policy directive: "default-src https: 'unsafe-eval' 'unsafe-inline'".
Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
用户使用表单内的文件输入选择文件后立即显示错误,预览图像显示为损坏的 link。
我尝试在我的 index.html 元标记中实现一些 CSP,如下所示:
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; style-src 'self'; img-src 'self';" />
但它不起作用,您可以推荐他们的一些文档以了解我的问题吗?
如果您需要任何代码或更多信息,请告诉我,老实说,我不确定首先是什么导致了问题。
也许这能有所帮助? https://github.com/Azure/static-web-apps/issues/2 and this https://docs.microsoft.com/en-us/azure/static-web-apps/routes#default-headers
我无法访问 azure,所以我只能提供资源,但也许通过遵循这些资源,您将能够更改 csp 以满足您的需要。
我有一个 angular 应用程序,用户可以在其中上传和提交图像,在本地工作时一切正常,但是一旦我构建了我的项目并托管了它,我在尝试上传时遇到违反内容安全策略的错误通过 file input
并显示图像的 预览 的图像。
这是我遇到的错误示例:
Refused to load the image 'data:image/png;base64,/9j/...' because it violates the following
Content Security Policy directive: "default-src https: 'unsafe-eval' 'unsafe-inline'".
Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
用户使用表单内的文件输入选择文件后立即显示错误,预览图像显示为损坏的 link。
我尝试在我的 index.html 元标记中实现一些 CSP,如下所示:
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; style-src 'self'; img-src 'self';" />
但它不起作用,您可以推荐他们的一些文档以了解我的问题吗?
如果您需要任何代码或更多信息,请告诉我,老实说,我不确定首先是什么导致了问题。
也许这能有所帮助? https://github.com/Azure/static-web-apps/issues/2 and this https://docs.microsoft.com/en-us/azure/static-web-apps/routes#default-headers 我无法访问 azure,所以我只能提供资源,但也许通过遵循这些资源,您将能够更改 csp 以满足您的需要。