MODiX icon indicating copy to clipboard operation
MODiX copied to clipboard

Failing to deserialize antiforgery token

Open patrickklaeren opened this issue 5 years ago • 1 comments

Since the upgrade to .NET Core 3.1, #649, there have been (more?) exceptions regarding the antiforgery token on the web end.

Initial investigation seems to point towards needing to configure data protection, but there are contradicting reports this has something to do with the host machine.

{
  "Timestamp": "2020-01-13T16:59:56.2779053+00:00",
  "Level": 4,
  "MessageTemplate": {
    "Text": "An exception was thrown while deserializing the token.",
    "Tokens": [
      {
        "Length": 54,
        "Text": "An exception was thrown while deserializing the token.",
        "StartIndex": 0
      }
    ]
  },
  "Properties": {
    "EventId": {
      "TypeTag": null,
      "Properties": [
        {
          "Name": "Id",
          "Value": {
            "Value": 7
          }
        },
        {
          "Name": "Name",
          "Value": {
            "Value": "TokenDeserializeException"
          }
        }
      ]
    },
    "SourceContext": {
      "Value": "Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery"
    },
    "RequestId": {
      "Value": "0HLSO87AB2H8T:00000001"
    },
    "RequestPath": {
      "Value": "/infractions"
    },
    "SpanId": {
      "Value": "|47da2c35-4466b393ddbe52e4."
    },
    "TraceId": {
      "Value": "47da2c35-4466b393ddbe52e4"
    },
    "ParentId": {
      "Value": ""
    },
    "ConnectionId": {
      "Value": "0HLSO87AB2H8T"
    }
  },
  "Exception": {
    "StackTrace": "   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)\n   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)",
    "Message": "The antiforgery token could not be decrypted.",
    "InnerException": {
      "ClassName": "System.Security.Cryptography.CryptographicException",
      "Message": "The key {d86bdc04-1e6f-4c44-88c1-1f9ac58fcf5f} was not found in the key ring.",
      "Data": null,
      "InnerException": null,
      "HelpURL": null,
      "StackTraceString": "   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)\n   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)\n   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)\n   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)",
      "RemoteStackTraceString": null,
      "RemoteStackIndex": 0,
      "ExceptionMethod": null,
      "HResult": -2146233087,
      "Source": "Microsoft.AspNetCore.DataProtection",
      "WatsonBuckets": null
    },
    "Source": "Microsoft.AspNetCore.Antiforgery"
  }
}

patrickklaeren avatar Jan 14 '20 00:01 patrickklaeren

Also occurs on a self hosted CentOS instance, behind NGINX.

patrickklaeren avatar Jan 14 '20 00:01 patrickklaeren

As part of a new effort to refocus on priorities, I will close this. If you feel this is imperative to the bot, a new issue can be opened to supersede this.

patrickklaeren avatar Mar 26 '24 14:03 patrickklaeren