Sensitive Data Handling
URL redaction is applied by default; attribute redaction is opt-in. What the SDK strips from URLs out of the box, how to extend it with sanitizeUrl, and how to redact attribute values with attributeScrubbers.
The SDK redacts URLs before they are recorded. Attribute values are redacted only where you declare a rule. The two halves have different defaults:
| Default | Option | |
|---|---|---|
| URL redaction | On. Credentials and 19 well-known query parameters are redacted | sanitizeUrl to supply your own |
| Attribute redaction | Off. No rules, nothing is changed | attributeScrubbers to add rules |
Neither replaces the session replay masking options (maskAllInputs, maskAllText, maskClass), which cover recorded DOM content rather than telemetry attributes.
URL redaction
NOTE — This is on without any configuration
Every URL the SDK records is passed through the default sanitizer. No option to set, no change to your init() call.
Default redactions
Credentials in the authority. https://user:pass@api.example.com/v1 becomes https://REDACTED:REDACTED@api.example.com/v1. A bare https://token@host becomes https://REDACTED@host.
The values of 19 query parameters. The parameter name is kept and only its value is replaced, so the telemetry still shows which parameters were on the URL:
https://app.example.com/checkout?token=abc123&plan=pro
https://app.example.com/checkout?token=REDACTED&plan=proThe default list:
password, passwd, secret, api_key, apikey, auth, authorization, token, access_token, refresh_token, jwt, session, sessionid, key, private_key, client_secret, client_id, signature, hash
Matching rules
- Exact name, case-insensitively.
?Token=and?TOKEN=are redacted;?tokenizer=,?keyword=and?monkey=are not. Substring matching is not used:key,auth,hashandsessionall appear inside other parameter names. - Names are decoded before matching.
+becomes a space, percent escapes are resolved, and surrounding whitespace is trimmed, so?%74oken=and?%20token=are both redacted. - Every occurrence is redacted separately.
?token=a&token=bbecomes?token=REDACTED&token=REDACTEDrather than collapsing to one pair. - The fragment is scanned too. The OAuth 2.0 implicit grant delivers
access_tokenin the fragment. Both#access_token=…and hash routes carrying#/checkout?token=…are covered. A fragment with noname=valuepair (#installation,#/orders/42) passes through untouched. - Nothing else is rewritten. The path, encoding, parameter order, host case, default port and trailing slash come back byte-for-byte identical.
Scope
url.fullon every span and every log record the SDK emits, applied immediately before export, so URLs written directly by upstream instrumentation are covered as well as those the SDK writes itself.http.urlon WebSocket connection spans.- The screen name, when
screenNameOption.urlWithSearchParamsistrueand the screen name therefore contains a query string.
Parameters not on the default list
CAUTION — Check your own parameter names against the list
The default list holds well-known names only. session_token and sessionToken are not on it — only session, sessionid, token and access_token are. Neither are hyphenated variants such as api-key. If your application puts a secret in a parameter the list does not name, extend it.
Extend the defaults rather than replacing them:
import { createSanitizeUrl } from '@sophonz/redaction';
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
sanitizeUrl: createSanitizeUrl({
additionalQueryParamsToScrub: ['session_token', 'sessionToken', 'api-key'],
}),
});createSanitizeUrl accepts:
| Option | Type | Default | Meaning |
|---|---|---|---|
additionalQueryParamsToScrub | readonly string[] | [] | Names redacted in addition to the 19 defaults |
queryParamsToScrub | readonly string[] | the 19 defaults | Replaces the default list outright. Prefer the option above |
redactCredentials | boolean | true | Redact user:password@ in the authority |
scrubFragment | boolean | true | Also scan the fragment for parameters |
sanitizeUrl
(
(url: string) => string, optional)
Replaces the URL sanitizer entirely.
WARNING — A custom function replaces the default, it does not run alongside it
If you pass your own function, the 19 default parameters are no longer redacted unless your function redacts them. Use createSanitizeUrl above to keep the defaults and add to them.
Your function runs on the hot path of the page. The SDK wraps every call and records REDACTED when one fails:
| Your function | Result |
|---|---|
| Returns a string | The returned value is recorded |
| Throws | The URL is recorded as REDACTED, and the failure is reported once through diag |
| Returns a non-string | The URL is recorded as REDACTED, and the failure is reported once through diag |
A url.full value of exactly REDACTED means the sanitizer failed on that URL, not that the URL was empty.
Attribute redaction
attributeScrubbers
(
AttributeScrubber[], optional)
Per-key redaction applied to the attributes of every span and every log record. Spans are processed on end and log records on emit, so attributes added late by instrumentation are still covered.
NOTE — There are no default rules
Configure nothing and the processor is not constructed at all. Attribute keys are a structured namespace (http.request.header.authorization, app.screen.name, session.id), so a generic default list would match almost nothing useful while risking a silent match on a load-bearing key such as session.id. Name the keys you want redacted.
A rule is a matcher plus an optional transform:
| Field | Type | Purpose |
|---|---|---|
keys | readonly string[] | Exact attribute keys, matched case-sensitively |
keyPattern | RegExp | readonly RegExp[] | Patterns tested against the key |
shouldScrub | (key: string) => boolean | Arbitrary predicate. Use only where the two above cannot express the match |
scrub | (key: string, value) => value | undefined | Replacement value. Omit for REDACTED; return undefined to remove the attribute |
At least one matcher is required. A rule with none matches nothing and is dropped at startup with a report through diag.
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
attributeScrubbers: [
// Replace the value with 'REDACTED'
{ keys: ['app.user.email'] },
// Match a whole family of keys
{ keyPattern: /^http\.request\.header\./ },
// Transform rather than blank
{
keys: ['app.query'],
scrub: (_key, value) =>
typeof value === 'string' ? value.slice(0, 64) : value,
},
// Remove the attribute entirely
{ keys: ['app.internal'], scrub: () => undefined },
],
});Every matching rule runs, in the order you declare them: each rule's return value is the next rule's input.
Prefer keys and keyPattern over shouldScrub. The declarative matchers compile into one shared set and one shared pattern list, so an attribute no rule cares about costs a single lookup. A shouldScrub rule is excluded from that fast path.
Rule failures
Rules are wrapped, and the handling depends on where the exception is thrown:
| Throws in | Outcome |
|---|---|
scrub | The value becomes REDACTED and the rule stays active. The matcher fired on that key, so the original value is not kept |
shouldScrub | The attribute is left alone and that rule is disabled for the rest of the page's life. Calling it again would throw on every attribute |
Both are reported once per rule through diag, so a rule that fails on every span does not flood the console. A broken rule does not disable the others.