What you will have at the end
Two kinds of masking, measured on one Route. First, the masks of Traffic Explorer: a card number in a request body that was stored in the clear is stored as asterisks once its JSON path is on the mask list, and the viewing of a body is itself an audit record. Second, data-mask on the Route: a rule per field that changes what your own logger Plugins write, while the backend and the client still see the real values. The article also says plainly what each mechanism does not cover.
Prerequisites
- A Route that receives JSON. Here it is
catalog-apifrom Caching responses with proxy-cache, which forwards/catalog/*to an echo service, so the article can show what the backend received. - Traffic logging turned on under Traffic Explorer › Settings, with Request body capture on. The screenshots below were taken as
nora.becker, whose role may view request bodies and manage Routes.
Part one: what the gateway stores
Open Observe › Traffic Explorer › Settings. Under Capture, two switches decide whether bodies are stored at all: Request body, on here, stores a JSON body up to the limit beside it; Response body is off, so records carry response headers and sizes only. The note under them is the point of this article: bodies can carry card numbers and passwords, viewing a body needs the permission for request bodies, and every view is written to the audit log.
Under Masking is the list of values the gateway replaces before a record is stored. On this Environment the request headers are the defaults, authorization, proxy-authorization, cookie, apikey and x-api-key, plus the two that Keycloak and G8 added, x-access-token and x-userinfo; the query arguments token, access_token and apikey; and one body field from an earlier article. Names are case-sensitive, and a body path starts at the root of the JSON, $.card.number or $..password.

A record before the mask
A client sends an order with a card:
curl -X POST -H 'content-type: application/json' http://localhost:9281/catalog/orders \
-d '{"customer":"ACME GmbH","card":{"number":"4111111111111111","holder":"J. Miller","expiry":"12/28"},"amount":1250}'
Open the record in Traffic Explorer, switch to Request, and under Body select Show body. The body is there as it arrived, card number included, because no path named it.

Add the path, send again
Back in Settings › Masking, add $.card.number under Body fields and select Save settings. The note says when it applies: a new mask applies to the records written from now on, and the record above keeps its number. Saving the list is itself a change, written to the audit log as an update of the global rule g8-request-records, which is how the console gives the gateway its masks.

The same request a few seconds later, and its record:

The backend received the full number both times: Traffic Explorer masks decide what is stored about a request, not what is sent on.
The view is a record too
Each time a body was shown above, the audit log received an entry, traffic.body_viewed, with the actor, the time, the request record it belongs to and, under Details, the part of the record and the size of the body shown; Traffic Explorer: connect your log store has a screenshot of one. The permission for request bodies is separate from the permission to read records, so a role can read every record of an Environment and still not open a body.

Part two: what your own loggers write
The masks above belong to G8’s own records. A logger Plugin you add to a Route, http-logger, elasticsearch-logger, syslog or the others from Access logs to the systems you run, writes its own record, and the measurement of this article shows where the line runs: the masked headers of the list, apikey among them, arrive masked in those records too, but a JSON body a logger is told to include arrives as it was sent. For that there is data-mask.
Open the Route, Plugins, Add plugin, data-mask. The form is one table, Request, with a rule per row:
- Type:
body,headerorquery. Action:replacewith a Value,remove, orregexwith a Regex and a Value. Name: the header, the query argument, or the JSON path of the body field; a body rule also needs its Body format,jsonorurlencoded. - The article adds two rules:
body·replace·$.card.holder·****·json, andheader·replace·user-agent·masked.
The note under the table is the sentence to remember: masking runs after the answer, the upstream and the client saw the value, and only the lines the loggers write carry the mask. Body size limit and Form fields read under More say how large a body is still masked and how many form fields are read; a body over the limit is logged unmasked, and only the gateway’s error log says so.

Select Add plugin. For the measurement, an http-logger with Include request body on was added to the same Route, pointing at a small endpoint that prints what it receives. The same order again, and what the backend echoed back:
backend saw json: {'amount': 1250, 'card': {'expiry': '12/28', 'holder': 'J. Miller', 'number': '4111111111111111'}, 'customer': 'ACME GmbH'}
backend saw user-agent: ['curl/8.7.1']
What the logger delivered for the same request:
request.body: {"customer":"ACME GmbH","amount":1250,"card":{"holder":"****","expiry":"12/28","number":"4111111111111111"}}
user-agent: masked
The holder and the user agent carry the rules; the card number does not, because no data-mask rule names it, and the Traffic Explorer path $.card.number applies to G8’s record and not to a logger’s copy of the body. A field that must never reach any log therefore needs both: the path under Traffic Explorer › Settings for G8’s records, and a data-mask rule for every logger that includes the body. The G8 record of this request, opened the same way as above, shows the holder and the user agent as sent: data-mask does not change it.
What the audit log keeps
Three kinds of entries came out of this article: the global rule update when the mask list was saved, with the old and the new rule side by side; the Route update that added data-mask, with the two rules as the difference; and one traffic.body_viewed entry per body shown, naming the actor and the record. None of them holds the card number.
What to do next
- Refuse the card number before it is stored at all: Request validation: JSON Schema and OpenAPI at the gateway.
- Send the masked records to the systems you run: Access logs to the systems you run.
- See the masks at work on identity headers in Keycloak and G8, and the retention of the records in Self-hosted vs SaaS.
- The Plugins side by side are in the capabilities reference and on API Security; the solution page is API security and identity.