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_onlyto date-of-birth fields to preserve year-level granularity for age-bracket analytics while removing exact birth dates - Use
hash_sha256on user identifiers to enable cross-system joins on hashed keys without exposing raw PII