Knowledge base · 3TL Bridge

3TL Bridge: Data Masking

By Donovan Kinney · Updated

Data Masking

3TL Bridge applies data masking at the transformation layer — as each event flows through the pipeline, before it reaches any sink. Masking runs as part of the Rhai transformation script and is subject to the same versioning, test coverage, and deployment workflow as any other transformation logic.


How Masking Works

Masking is implemented as Rhai script logic within a transformation workspace. Each event document passes through the script, which modifies, redacts, or replaces sensitive fields before the document is written to the sink.

Because masking is applied in the pipeline transformation layer:

  • Sensitive fields never appear in the sink, regardless of sink type
  • Masking logic is saved and auditable alongside the rest of the transformation workspace
  • Different masking profiles can be applied per pipeline — for example, full PII in a development pipeline, masked in a production replication pipeline

Built-in Masking Functions

The Rhai engine includes four built-in masking functions available in any transformation script:

Function Input Output Example
mask_email(value) Email address First character visible, rest replaced [email protected] → j***@example.com
mask_phone(value) Phone number Last 4 digits visible, rest replaced +1-555-123-4567 → ***********4567
mask_year_only(value) Date (RFC3339, YYYY-MM-DD, or EJSON $date) Day and month set to January 1st, year preserved 2024-06-15 → 2024-01-01
hash_sha256(value) Any value Deterministic SHA-256 hex digest [email protected] → a8b64...

Example script using built-in functions:

fn transform(data, attributes) {
    data.email = mask_email(data.email);
    data.phone = mask_phone(data.phone);
    data.date_of_birth = mask_year_only(data.date_of_birth);
    data.national_id = hash_sha256(data.national_id);
    result(data, attributes)
}

For masking patterns not covered by the built-in functions — name replacement, partial redaction, conditional masking based on field presence — write custom logic directly in Rhai and test it in the workspace test suite before deployment.


Deterministic Hashing

hash_sha256 produces a consistent hex digest for any given input. The same value always produces the same hash, which allows data to be correlated across systems using the hash without exposing the original value.

This is a one-way operation — the original value cannot be recovered from the hash.


Use Cases

  • Mask PII fields in MongoDB change events before replicating to an analytics Kafka topic consumed by third-party reporting tools
  • Apply mask_year_only to date-of-birth fields to preserve year-level granularity for age-bracket analytics while removing exact birth dates
  • Use hash_sha256 on user identifiers to enable cross-system joins on hashed keys without exposing raw PII

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes, including personalized advertising (“performance”), to provide you with additional functions (“functional”), and to show content from social media platforms, such as embedded videos (“social media”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in section 9 of our Privacy Policy.

Manage consent preferences