> For the complete documentation index, see [llms.txt](https://docs.pharos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pharos.ai/platform-overview/pharos-platform-architecture/logs/access-controls/data-masking.md).

# Data Masking

How Pharos redacts sensitive information from logs before storage using targeted, regex-based masking rules—and why masking should be applied sparingly.

Data masking protects sensitive information in logs by redacting it **before the log is stored**, replacing matched values with a fixed redaction marker. This helps satisfy security and compliance requirements (HIPAA, GDPR, PCI-DSS) while preserving enough of the message to stay useful for troubleshooting.

{% hint style="info" %}
This page covers the concepts. For step-by-step setup—accessing the Masking screen, building rules, the predefined pattern library, and the performance simulator—see [Sensitive Data Masking](https://docs.pharos.ai/configuration-guide/advanced/sensitive-data-masking.md) in the Configuration Guide.
{% endhint %}

***

## The Sensitive Data Problem

Confidential data ends up in log text without anyone intending it. Salesforce writes the offending value straight into its own error message, and application code logs values alongside the errors it reports:

```
Apex Exception:  "Failed to process payment for card 4532-1234-5678-9012"   → card number
Flow Error:      "User SSN validation failed: 123-45-6789"                   → SSN
Integration Log: "API request: {password: 'P@ssw0rd123'}"                    → credentials
Custom Log:      "Patient record: diagnosis='Stage 4 Cancer'"               → PHI
```

Left unmasked, that data creates real compliance exposure:

* **HIPAA** — Protected Health Information (PHI) must be secured
* **GDPR** — personal data requires appropriate technical protection
* **PCI-DSS** — payment card data must be masked or encrypted
* **Internal policy** — company-specific data-classification rules

## Pharos's Solution: Targeted Masking

Pharos provides **regex-based masking rules** that redact sensitive information as each log is created. Matched text is replaced with a redaction marker, so the same errors remain observable without exposing the underlying data:

```
Apex Exception:  "Failed to process payment for card ********"
Flow Error:      "User SSN validation failed: ********"
Integration Log: "API request: {password: '********'}"
```

You still know an error occurred and where—the sensitive substring is simply gone.

***

## How Data Masking Works

Sensitive values reach a log because something emitted them into text: Salesforce's own error messages, your Apex and Flows, and the payloads your integrations exchange. Pharos stores that text as it was received—it does not read your business records, and a record a log refers to is recorded as an ID and an object type, nothing more. Masking works on that emitted text, which is where the exposure is.

Masking happens **before logs are persisted**, so the original value never reaches storage:

1. **Capture** — Pharos receives the log text as it was emitted: the error message, the stack trace, and any payload the log carries.
2. **Match** — each qualifying masking rule applies its regex patterns to find sensitive data.
3. **Redact** — matches are replaced with a redaction marker.
4. **Persist** — only the masked version is stored.
5. **Display** — masked values appear everywhere the log is shown: list views, the Flow debugger, exports, and notifications.

Redaction is **irreversible**—the original data is never recoverable once masked.

### What a Rule Contains

A masking rule pairs two things:

* **Filter criteria** decide *which* logs the rule evaluates—`Field` / `Operator` / `Value` conditions on the Log record (for example, `Category` equals `Apex`). Narrow criteria keep the rule from running on every log.
* **Regex patterns** decide *what* to redact—chosen from a **predefined pattern library** (email, credit card, SSN, API tokens, and more) or entered as custom expressions.

Patterns run against the log's free-text fields—**Summary**, **Details**, **Stack Trace**, **Stack Trace Parse Result**, and **Deploy Results**. Those are the fields that carry emitted text, and so the only ones in which a sensitive value can appear.

Masking rules are created and managed in **Pharos Admin → Masking** (not through code or custom metadata). Unlike notification rules, **every matching masking rule is applied** to a log, so one record can be cleaned of several data types at once. When multiple rules qualify, they run in the order they appear in the list.

***

## Common Sensitive Data Types

The predefined pattern library covers the data types most often found in logs, grouped roughly as:

| Category                  | Examples                                                                                        |
| ------------------------- | ----------------------------------------------------------------------------------------------- |
| **Personal (PII)**        | Email address, SSN, phone number                                                                |
| **Financial**             | Credit card number, IBAN                                                                        |
| **Credentials & secrets** | API keys, bearer/JWT/Slack/GitHub tokens, passwords in URLs, private-key and basic-auth headers |
| **Network & identifiers** | IPv4 address, MAC address, UUID/GUID                                                            |

You can start from a predefined pattern and adjust it, or write your own regex. Every pattern can be validated against sample text before you save it—see the [configuration guide](https://docs.pharos.ai/configuration-guide/advanced/sensitive-data-masking.md#adding-regex-patterns).

***

## Performance Considerations

Masking is not free. Each rule runs its regex patterns against every matching log at creation time, consuming CPU and heap. That cost grows with the number of matching logs, the volume of text in those five fields, and the number of patterns run—so masking is meant for a **small set of targeted use cases, not blanket coverage.**

To keep the cost under control:

* **Scope filter criteria tightly** so a rule fires only on logs that can actually contain the sensitive data.
* **Keep regexes lean**—anchor them and bound quantifiers to avoid expensive backtracking.
* **Use as few rules and patterns as the requirement allows.**
* **Measure before rolling out.** The Masking screen's **Performance Impact** simulator projects the CPU time and heap a rule will consume, with a per-rule breakdown. See [Performance Impact](https://docs.pharos.ai/configuration-guide/advanced/sensitive-data-masking.md#performance-impact).

{% hint style="warning" %}
Apply masking sparingly. Broad filter criteria or heavy regexes running on every log can add meaningful processing overhead during log creation.
{% endhint %}

***

## Limitations

Regex-based masking is powerful but bounded—plan coverage with these in mind:

* **Regex can't catch everything.** Unstructured free text, context-dependent values (is `12345` a ZIP or an account number?), and obfuscated formats can slip through. Pair masking with developer discipline—don't log secrets in the first place.
* **False positives happen.** An overly broad pattern can redact non-sensitive data and make troubleshooting harder. Prefer specific patterns and test them.
* **Masking is irreversible.** Over-masking permanently discards information, so validate rules in a sandbox before production.

***

## Compliance Scenarios

Masking helps satisfy common regulatory frameworks. Typical data to target:

| Framework                   | Mask                                                                                         |
| --------------------------- | -------------------------------------------------------------------------------------------- |
| **HIPAA** (healthcare)      | Patient names, Medical Record Numbers, SSNs, diagnoses and treatment details, dates of birth |
| **GDPR** (EU personal data) | Names, email addresses, phone numbers, IP addresses                                          |
| **PCI-DSS** (payment cards) | Card numbers, CVV/CVC codes, cardholder names                                                |

***

## Summary

* **Targeted, regex-based rules** redact sensitive data before it is stored—irreversibly.
* **Managed in Pharos Admin → Masking**, each rule combines filter criteria (which logs) with regex patterns (what to redact), and all matching rules apply.
* **A predefined pattern library** covers the most common PII, financial, credential, and identifier types.
* **Performance matters**—scope tightly, keep regexes lean, use masking sparingly, and validate cost with the Performance Impact simulator.

For setup instructions and screenshots, see [Sensitive Data Masking](https://docs.pharos.ai/configuration-guide/advanced/sensitive-data-masking.md).
