각도로 표시된 문서에서 각도 httpclient
은 게시 요청의 헤더에 쿠키 XSRF-TOKEN
의 값을 자동으로 보냅니다. Documentation linkangular4 httpclient csrf가 x-xsrf 토큰을 보내지 않음
그러나 나를 위해 헤더를 보내지 않습니다. 여기 쿠키
router.get('/set-csrf',function(req,res,next){
res.setHeader('Set-Cookie', "XSRF-TOKEN=abc;Path=/; HttpOnly; SameSite=Strict");
res.send();
})
을 설정하는
Nodejs 코드는 내가 app.module.ts에서 HttpClient를 사용했습니다 내 코드입니다
imports: [
HttpClientModule
]
** 위의 코드는 디버깅을위한 목적. 나는 set-csrf 엔드 포인트가 없다.
하지만 게시물 요청을 보낼 때 헤더를 보내지 않습니다. 디버깅 할 수 없습니다.
나는 github 저장소에도 문제를 추가했다. HttpXsrfInterceptor는 요청이 GET 또는 HEAD인지 또는 http로 시작하는지 검사합니다. true의 경우, 헤더의 추가는 건너 뜁니다. 여기
는이 HTTP/s의 일부를 생략 한 이유는 확실하지 않다 HttpXsrfInterceptor classintercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const lcUrl = req.url.toLowerCase();
// Skip both non-mutating requests and absolute URLs.
// Non-mutating requests don't require a token, and absolute URLs require special handling
// anyway as the cookie set
// on our origin is not the same as the token expected by another origin.
if (req.method === 'GET' || req.method === 'HEAD' || lcUrl.startsWith('http://') ||
lcUrl.startsWith('https://')) {
return next.handle(req);
}
const token = this.tokenService.getToken();
// Be careful not to overwrite an existing header of the same name.
if (token !== null && !req.headers.has(this.headerName)) {
req = req.clone({headers: req.headers.set(this.headerName, token)});
}
return next.handle(req);
}
의 코드입니다. 내 것이 issue in github
CORS 요청을 사용합니까? – Alexandr
"Access-Control-Allow-Headers", "*"' – netuser
헤더를 추가하고 있습니다. 각도는 http [s] 링크를 다른 방식으로 처리해야합니다. 예를 들어 각 도메인의 마지막 csrf 토큰을 별도로 저장하십시오. 어쩌면 다른 인터셉터 윈치가 csrf를 그런 식으로 처리하게하는 것이 좋을까요? – Alexandr