从具有相同域的其他应用程序调用时 Dotnet 核心 COR 问题
Dotnet core CORs issue when calling from other application with Same Domain
我们在 IIS 中托管了一个 dotnet 核心应用程序,url 格式为 application1.domain.com。我们添加了
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder
.WithOrigins(webURL,"https://*.domain.com")
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Content-Disposition");
});
还有这个,
app.Use(async (context, next) =>
{context.Response.Headers.Add("Content-Security-Policy", "default-src 'self' 'unsafe-eval' 'unsafe-inline' *.domain.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' *.domain.com data:; connect-src 'self' *.domain.com; form-action 'self' ;");}
当 https://application2.domain.com/
应用程序尝试在其 html 文件中加载 https://application1.domain.com/angular.js
时,我们在 chrome 中收到以下错误。
Refused to load the script 'https://{application}.domain.com/angular.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' www.google-analytics.com ajax.googeapis.com *.api.splkmobile.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
https://application2.domain.com
结束后还需要进行其他设置吗?
您显示 CSP 具有 script-src 'self' 'unsafe-inline' 'unsafe-eval';
,但违规发生在 script-src 'self' 'unsafe-inline' 'unsafe-eval' www.google-analytics.com ajax.googeapis.com *.api.splkmobile.com
。
这意味着其他 CSP 已在某处发布,而您显示的 CSP 未发布。
您必须找到真正发布 CSP header 的位置,然后将 https://application2.domain.com
添加到其中。
我们在 IIS 中托管了一个 dotnet 核心应用程序,url 格式为 application1.domain.com。我们添加了
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder
.WithOrigins(webURL,"https://*.domain.com")
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Content-Disposition");
});
还有这个,
app.Use(async (context, next) =>
{context.Response.Headers.Add("Content-Security-Policy", "default-src 'self' 'unsafe-eval' 'unsafe-inline' *.domain.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' *.domain.com data:; connect-src 'self' *.domain.com; form-action 'self' ;");}
当 https://application2.domain.com/
应用程序尝试在其 html 文件中加载 https://application1.domain.com/angular.js
时,我们在 chrome 中收到以下错误。
Refused to load the script 'https://{application}.domain.com/angular.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' www.google-analytics.com ajax.googeapis.com *.api.splkmobile.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
https://application2.domain.com
结束后还需要进行其他设置吗?
您显示 CSP 具有 script-src 'self' 'unsafe-inline' 'unsafe-eval';
,但违规发生在 script-src 'self' 'unsafe-inline' 'unsafe-eval' www.google-analytics.com ajax.googeapis.com *.api.splkmobile.com
。
这意味着其他 CSP 已在某处发布,而您显示的 CSP 未发布。
您必须找到真正发布 CSP header 的位置,然后将 https://application2.domain.com
添加到其中。