Can I prevent sensitive data (credit card, national ID number) from leaking out in the response?
Short answer
Yes, in two ways. To hide the value and send the response, the Mask type of the Modify Response Content action is used; the TC ID. NO and Credit card patterns are ready in the Built-in Mask Regexes list. If the response containing sensitive data is not to be sent at all, the HTTP Response Body condition searches for the pattern in the first part of the response body (at most 16384 bytes), and a Block or Show Content action with Execution Level On response returns an error or information page instead of the actual response. WAF does not inspect responses; this is done with Load Balancer actions.
Problem: Sensitive Data Appears in Application Responses
Because of a faulty query, an error page or a missing authorization check, a credit card or national ID number can leak out in the application response. It is wanted that this data is hidden before it reaches the client or that the response is not sent at all. Both methods are a layer of precaution; the data must be fixed at its source.
Solution: Two Methods
The two methods are alternatives to each other: one changes the response and sends it, the other does not send the response at all.
| Your situation | Suitable method |
|---|---|
| The page should keep opening; only the value should be hidden | Method 1: Modify Response Content → Mask |
| The response containing sensitive data should not be sent at all | Method 2: HTTP Response Body + Block / Show content |
Method 1: Modify Response Content → Mask Recommended
- How it works In the response body, the texts that match the Mask Query pattern are replaced with the Masking Character; the length is preserved and the response is sent to the client.
- Where it is openedLoad Balancer → Actions → Modify Response Content → Modify Type = Mask
- Requirement None
- vService type HTTP (the action works only at the response stage)
Step-by-Step Configuration
The action form is opened with Load Balancer → Actions → Add (how to add).
Action Name = tc-maske, Action Type = Modify Response Content, Modify Type = Mask are selected. Query type is left at the default RegEx; under Built-in mask regexes, TC ID. NO (or Credit card) is clicked and the pattern is added to the Mask Query field. Masking Character is left at the default *. Since the Masking Tolerance default is 1, the first and last characters of the match remain visible (12345678901 → 1*********1); if the whole value is to be hidden, 0 is entered.
The action is saved with Add. To limit it to specific pages, a condition can be selected in the Conditions field.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and the edit form is opened with Edit.
tc-maske is selected in the Details → Actions field.
The form is saved with Save. For the other fields (Omitted characters, Masking tolerance, Min. Occurrences for Masking) and the HTML adding / content replacing types: Can I modify the response body (e.g. inject a script into HTML, mask national ID / card numbers)?
Verification
The page that returns sensitive data is opened, or the output of curl -s https://www.example.com/profil is checked.
1*********1Method 2: HTTP Response Body + Block / Show Content
- How it works Before forwarding the response to the client, TR7 holds it for at most 500 ms until Body Size to Parse(Bytes) bytes are collected, and the condition searches for the pattern in this part; on a match, the Block or Show content that works at the response stage takes the place of the actual response.
- Where it is openedLoad Balancer → Conditions → HTTP Response Body · Load Balancer → Actions → Block / Show Content
- Requirement The compression profile must be off on the vService (TR7 does not turn off compression automatically for this condition).
- vService type HTTP
Step-by-Step Configuration
The condition form is opened with Load Balancer → Conditions → Add (how to add).
Condition Name = tc-yanit, Criteria = HTTP Response Body, and the Regex matching are selected; \b[0-9]{11}\b for the TC ID number or \b[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}\b for the card number is written in the Query field, and Body Size to Parse(Bytes) (at most 16384) is entered. The national ID pattern catches every 11-digit number (e.g. a phone number); the pattern and the scope are kept narrow.
The condition is saved with Add.
The action form is opened with Load Balancer → Actions → Add.
Action Name = tc-yanit-engel, Action Type = Block, Execution Level = On Response are selected; Deny Type is left at the default Standard and Status Code = 500 is selected. If an information page is to be shown instead of an error, Show content is selected, Execution level is set to On response, and the page and the status code are selected.
tc-yanit is selected in the Conditions field; to avoid scanning image and file responses, a path condition can be added with and in the same group.
The action is saved with Add.
The HTTP vService is opened with Edit.
tc-yanit-engel is selected in the Details → Actions field. If the Compression box under Details is checked, it is unchecked.
The form is saved with Save. If the Compression box was unchecked, the vService is restarted on save and open connections are briefly interrupted. In a cluster, the change is transferred to the peer device automatically by default; if Manual Sync Mode is on, it is sent with Synchronize.
Verification
Command: curl -s -o /dev/null -w '%{http_code}' https://www.example.com/profil
500A page that does not contain sensitive data is requested with the same command.
200Common Mistakes
- Thinking masking is the only protection. The data remains visible on the Backend Service and in the application logs; it must be fixed at its source.
- Searching for a pattern in a compressed response. The HTTP Response Body condition does not match reliably in compressed content; compression must be off on the vService (operational recommendations).
- Applying the condition to all responses. Image and file responses are also scanned, and each response can be held for up to 500 ms; it is narrowed with a path condition.
- Thinking WAF will inspect the response. WAF inspects requests; the response content is handled with Load Balancer actions.
How it is done in the documentation
