1. Home
  2. ...
  3. Tracing interceptors
  4. Log Obfuscation

Log Obfuscation

Hiding selected header or body data from the Trace log.

This interceptor is used to obfuscate selected data (present in the header or body of the request or response) from Trace logs.

NOTE

To create Trace logs (accessed by clicking the Icon icon), you must use the Log interceptor. If you wish the data to be encrypted rather than obfuscated, this can be configured in the Log interceptor itself.

Configuring the interceptor

To configure the Log Obfuscation interceptor, you must inform the Location (body or header) of the information to be hidden. If the information that you want to omit is located in the body of the request, inform a custom regular expression (Custom regex) to identify this information. If it is in the header, inform the Attribute, in lowercase. At last, define the symbols to be used in its place (in the field Replace to).

TIP

The Replace to field also accepts backreferences (v5 only), which makes it possible to preserve parts of the original value in the log β€” such as the first and last digits of a document number. See Preserving part of the original value.

TIP

It is possible to hide multiple pieces of information with a single Log Obfuscation interceptor using a suitable regular expression (as explained here). This is valid for information located in the body of the request.

Examples of hiding a single piece of information

Imagine that the body of a request contains the following information:

You have to create a suitable regular expression to hide a field. For example, if you want to obfuscate the "name" field, you can add the following settings:

As a result, Trace will show the following log for this request:

To obfuscate the "occupation" field, you can add the following settings:

As a result, Trace will show the following log for this request:

Finally, to obfuscate the "characteristics" field, you can add the following settings:

As a result, Trace will show the following log for this request:

Combining those three interceptors sequentially, Trace will show the following Log for this request:

However, a better way to obfuscate multiple fields is to use a single comprehensive regular expression (see examples below).

Example of hiding information contained in the header

To obfuscate information contained in the header of the request, select the location and inform the attribute.

WARNING

The attribute must be written using lowercase letters.

Attributes entered in capital letters or starting with a capital letter will not be hidden and thus will appear in the Trace log.

Example configuration to hide the authorization attribute:

As a result, Trace will show the following log for this request:

Configure one Log Obfuscation interceptor for each attribute you want to obfuscate. For header attributes, you can't configure multiple information within the same interceptor.

See below how to obfuscate multiple information from fields that are in the body of the request.

Regular expression for multiple information fields

When the data set is part of a JSON, a regular expression for multiple information follows the structure:

NOTE

The \s* of the regular expression is used to ignore any white spaces between key and value.

Both keys (information) and regex for each type of value must be separated by "|".

The regex for the corresponding value types are:

  • numbers, booleans and null: [\+\-\w.]+

  • strings: "[^"]*"

  • simple arrays: \[[^\]]*\]

  • simple objects: \{[^\}]*\}

Examples of hiding multiple pieces of information

Now, imagine that the body of a request contains the following information:

For example, to simultaneously hide the "name", "occupation" and "characteristics" fields, you can add the following settings:

As a result, Trace will show the following log for this request:

On the other hand, to simultaneously hide the "name", "citizenship", "maritalStatus", "active", "height" and "weight" fields, it's enough to replace the previous regex with:

As a result, Trace will show the following log for this request:

NOTE

Unlike the case where multiple interceptors were used, the symbols applied to obfuscate the information are necessarily the same.

Preserving part of the original value (backreferences)

v5 only

Besides literal text, the Replace to field also accepts backreferences: references to the capture groups defined in the regular expression of the Custom regex field. This makes it possible to apply a partial obfuscation, keeping in the log only the parts of the original value that you want to preserve.

Supported syntax

Token
Meaning
$1, $2, …Content of the corresponding numbered capture group.
${name}Content of the named capture group (?<name>...).
\$Literal dollar sign ($).
\\Literal backslash (\).
WARNING

Since $ and \ now have a special meaning in the Replace to field, a literal dollar sign must be escaped as \$. A lone $ β€” not followed by a number or by {name} β€” is rejected during validation.

Examples of partial obfuscation

To keep the first 3 and the last 2 digits of a field located in the body of the request, you can use the following configuration:

  • Custom regex: ("document"\s*:\s*")([^"]{3})[^"]*?([^"]{2})(?=")
  • Replace to: $1$2*******$3

If the body of the request contains:

As a result, the Trace will display the following log for this request:

To keep the first 2 characters of a header attribute, you can use the following configuration:

  • Attribute: token
  • Custom regex: ([0-9]{2})[0-9]*
  • Replace to: $1**

In this case, the original value 123456 will appear in the Trace as 12**.

The same reference can be made by the name of the capture group, instead of its number:

  • Custom regex: (?<start>[0-9]{2})[0-9]*
  • Replace to: ${start}**

The result is identical to the one of the previous example.

NOTE

The number of symbols defined in Replace to is fixed and does not follow the length of the original value. This way, the log does not reveal how many characters were hidden.

Configuration validations

The combination of Custom regex + Replace to is validated when the revision is saved β€” including against every environment with an active deployment β€” and also on deployment. Invalid configurations are rejected with the HTTP status 400.

The messages are returned in English by the Manager. In them, %s is replaced by the name of the interceptor and, when applicable, by the name of the group or by the invalid reference.

Case
Message
Invalid regular expression in Custom regexInterceptor '%s' has an invalid regular expression in 'Custom regex'.
Reference to a numbered group that does not exist (for example, $3 with a regular expression that has 2 groups)Interceptor '%s' field 'Replace to' references capture group 3, but the regular expression defines only 2 capture group(s).
Reference to a named group that does not existInterceptor '%s' field 'Replace to' references named group '%s', which is not defined in the regular expression.
Lone $, unclosed ${ or \ at the endInterceptor '%s' field 'Replace to' contains an invalid reference ('%s'). Use \$ for a literal '$'.
NOTE

When the Custom regex uses an environment variable, its value is not known at the moment the revision is saved. In this case, only the syntax of Replace to is validated on saving; the validations that depend on the regular expression happen on deployment, with the variable already resolved.

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more