Skip to content

[AuditApi(IncludeRequestBody = false] doesn't remove FormVariables #792

@esd-thg

Description

@esd-thg

Describe the bug
[AuditApi(IncludeRequestBody = false] doesn't ignore FormVariables

To Reproduce
Given this endpoint

[AllowAnonymous]
[HttpPost("~/connect/token")]
[Consumes("application/x-www-form-urlencoded")]
[Produces("application/json")]
[AuditApi(IncludeRequestBody = false, IncludeResponseBody = false)]
public async Task<IActionResult> Exchange()
{
    var request = HttpContext.GetOpenIddictServerRequest();
    // ...
}

and this request

POST /connect/token
Content-Type: application/x-www-form-urlencoded
Accept: application/json

grant_type=client_credentials&client_id=CLIENT_ID&client_secret=SECRET

I'm seeing this in the log

{
  "Action": {
    "HttpMethod": "POST",
    "ActionName": "Exchange",
    "ActionParameters": {},
    "FormVariables": {
      "grant_type": "client_credentials",
      "client_id": "CLIENT_ID",
      "client_secret": "SECRET"
    },
    "ResponseStatus": "OK",
    "ResponseStatusCode": 200,
    "RequestBody": {
      "Type": "application/x-www-form-urlencoded",
      "Length": 151
    }
  },
  // rest omitted
}

Expected behavior
I was expecting IncludeRequestBody = false to remove the form-urlencoded body and not show FormVariables.

Strangely IncludeRequestBody = true only logs

    "RequestBody": {
      "Type": "application/x-www-form-urlencoded",
      "Length": 151
    }

I was expecting something like

    "RequestBody": {
      "Type": "application/x-www-form-urlencoded",
      "Length": 151,
      "Value": "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=SECRET"
    }

Libraries (specify the Audit.NET extensions being used including version):

  • Audit.WebApi.Core: 32.1.1

Target .NET framework:

  • .NET 10

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions