How to redact headers from WAF logging using Java CDK v2?

0

How do you exclude header fields from logging using the Java v2 CDK patch 2.85? This does not work:

var header = CfnLoggingConfiguration.SingleHeaderProperty .builder() .name("header") .build();

var headerMatcher = CfnLoggingConfiguration.FieldToMatchProperty.builder() .singleHeader(header) .build();

CfnLoggingConfiguration loggingConfig = CfnLoggingConfiguration.Builder ... .redactedFields(List.of(headerMatcher)) ...

because this runs into this error message on a cdk deployment:

#/RedactedFields/0/SingleHeader: required key [Name] not found #/RedactedFields/0/SingleHeader: extraneous key [name] is not permitted

It would seem that the class SingleHeaderProperty has the property "name", but the JSON serialization is supposed to use upper case "Name", which is also used in the JavaDoc.

1 Answer
0

Hi, Cloudformation doc says that header name is not case-sensitive

See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-wafv2-loggingconfiguration-fieldtomatch.html

SingleHeader
Redact a single header. Provide the name of the header to inspect, for example, User-Agent 
or Referer. 
This setting isn't case sensitive.

Example JSON: "SingleHeader": { "Name": "haystack" }

Required: No

Type: SingleHeader

Update requires: No interruption

So, can you try with "name" and see if it works?

profile pictureAWS
EXPERT
answered 10 months ago
  • Thanks for the answer: The header is not case sensitive, but the problem seems to be the JSON key "Name", not the name of the header, which, as you quote from the docs, should be upper case, but is generated as lower case "name" by the CDK classes. The key "name" is hard coded in the implementation class of the CfnLoggingConfiguration.SingleHeaderProperty interface and cannot be set by the caller.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions