Programing

위조 방지 토큰을 해독 할 수 없습니다.

lottogame 2020. 12. 14. 07:43
반응형

위조 방지 토큰을 해독 할 수 없습니다.


양식이 있습니다.

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()...

그리고 행동 :

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl, string City)
{
}

가끔 (주 1 회) 오류가 발생합니다.

위조 방지 토큰을 해독 할 수 없습니다. 이 응용 프로그램이 웹 팜 또는 클러스터에서 호스팅되는 경우 모든 컴퓨터가 동일한 버전의 ASP.NET 웹 페이지를 실행하고 구성에서 명시 적 암호화 및 유효성 검사 키를 지정하는지 확인합니다. AutoGenerate는 클러스터에서 사용할 수 없습니다.

나는 webconfig에 추가하려고합니다.

<machineKey validationKey="AutoGenerate,IsolateApps"  
    decryptionKey="AutoGenerate,IsolateApps" />

그러나 오류는 여전히 가끔 나타납니다.

예를 들어 한 사람이 한 컴퓨터에서 들어온 다음 다른 컴퓨터를 시도 할 때이 오류가 발생합니다

또는 때때로 bool과 같은 잘못된 데이터 유형을 jQuery 코드로 양식 필드에 정수로 설정 한 자동 값도 확인하십시오.


이 오류도 방금 받았는데, 제 경우에는 위조 방지 토큰이 같은 형식으로 두 번 적용되어 발생했습니다. 두 번째 인스턴스는 부분보기에서 왔기 때문에 즉시 명확하지 않았습니다.


validationKey = "AutoGenerate"

이것은 ASP.NET이 응용 프로그램이 시작될 때마다 인증 티켓 및 위조 방지 토큰과 같은 것을 암호화하는 데 사용할 새 암호화 키를 생성하도록 지시합니다. 다른 키 (예 : 재시작 전)를 사용하여 요청 항목 (예 : 인증 쿠키)을 암호화하는 요청을받은 경우이 예외가 발생할 수 있습니다.

"AutoGenerate"에서 벗어나 구체적으로 지정 (암호화 키)하면 해당 키에 의존하는 요청이 올바르게 복호화되고 유효성 검사가 앱 다시 시작부터 작동하여 다시 시작됩니다. 예를 들면 :

<machineKey  
validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7
               AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"           
decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
validation="SHA1"
decryption="AES"
/>

MSDN 페이지에서 마음의 내용을 읽을 수 있습니다. 방법 : ASP.NET에서 MachineKey 구성


프레임 워크 버전에 대한 링크<machineKey .../> 에서 태그를 생성 하고 존재하지 않는 경우 Web.config에 삽입하십시오 .<system.web><system.web/>

도움이 되었기를 바랍니다.


이 오류를 표시하는 개발자 컴퓨터를 위해 Google에서 여기로 오면 브라우저에서 쿠키를 삭제 해보세요. Clear Browser 쿠키가 저에게 효과적이었습니다.


부분보기를 호출하는보기가있는 코드 영역에서이 문제가 발생했지만 부분보기를 반환하는 대신보기를 반환했습니다.

나는 변했다 :

return View (index);

...에

return PartialView (index);

내 통제하에 내 문제가 해결되었습니다.


If you use Kubernetes and have more than one pod for your app this will most likely cause the request validation to fail because the pod that generates the RequestValidationToken is not necessarily the pod that will validate the token when POSTing back to your application. The fix should be to configure your nginx-controller or whatever ingress resource you are using and tell it to load balance so that each client uses one pod for all communication.

Update: I managed to fix it by adding the following annotations to my ingress:

https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/

Name    Description Values
nginx.ingress.kubernetes.io/affinity    Sets the affinity type  string (in NGINX only cookie is possible
nginx.ingress.kubernetes.io/session-cookie-name Name of the cookie that will be used    string (default to INGRESSCOOKIE)
nginx.ingress.kubernetes.io/session-cookie-hash Type of hash that will be used in cookie value  sha1/md5/index

I got this error on .NET Core 2.1. I fixed it by adding the Data Protection service in Startup:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDataProtection();
    ....
}

I get this error when the page is old ('stale'). A refresh of the token via a page reload resolves my problem. There seems to be some timeout period.

참고URL : https://stackoverflow.com/questions/23402210/the-anti-forgery-token-could-not-be-decrypted

반응형