如何阻止我的Angular应用尝试从HttpClient上的PUT / POST和PATCH请求中读取 document.cookie ?
iframe
内运行,不允许访问Cookie!
我无法控制此环境/应用。 put
,post
&来自patch
的{{1}}请求会产生以下错误。
backend.service.ts:127 DOMException:无法读取' cookie' 来自' Document'的文件:该文件是沙箱并且没有 '允许-同源'旗。 在HttpXsrfCookieExtractor.push ../ node_modules/@angular/common/fesm5/http.js.HttpXsrfCookieExtractor.getToken (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:27596:37) 在HttpXsrfInterceptor.push ../ node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:27633:39) 在HttpInterceptorHandler.push ../ node_modules / @ angular / common / fesm5 /http.js.HttpInterceptorHandler.handle (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:27004:33) 在HttpInterceptingHandler.push ../ node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:27677:27) 在MergeMapSubscriber.project(http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:26755:184) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:110070:27) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / mergeMap.js.MergeMapSubscriber._next (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:110060:18) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.next (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:101403:18) 在Observable._subscribe(http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:104821:20) 在Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe (http://localhost:8080/44812272_a91e_4126_ad7b_6a54454 ... _sc-lightcontrol.jar / vendor.js:100628:25)
HttpClient
,putTest()
和postTest()
因上述例外而失败
patchTest()
有效。
getTest()
答案 0 :(得分:0)
如果我为传出请求禁用XSRF protection support,PUT / POST和PATCH请求会起作用,默认情况下会启用该传递请求并尝试读取cookie XSRF-TOKEN。
@NgModule({
...,
imports: [
HttpClientModule,
HttpClientXsrfModule.disable(),
],
...
})