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:

DefaultOption
URL redactionOn. Credentials and 19 well-known query parameters are redactedsanitizeUrl to supply your own
Attribute redactionOff. No rules, nothing is changedattributeScrubbers 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=pro

The 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, hash and session all 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=b becomes ?token=REDACTED&token=REDACTED rather than collapsing to one pair.
  • The fragment is scanned too. The OAuth 2.0 implicit grant delivers access_token in the fragment. Both #access_token=… and hash routes carrying #/checkout?token=… are covered. A fragment with no name=value pair (#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.full on 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.url on WebSocket connection spans.
  • The screen name, when screenNameOption.urlWithSearchParams is true and 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:

OptionTypeDefaultMeaning
additionalQueryParamsToScrubreadonly string[][]Names redacted in addition to the 19 defaults
queryParamsToScrubreadonly string[]the 19 defaultsReplaces the default list outright. Prefer the option above
redactCredentialsbooleantrueRedact user:password@ in the authority
scrubFragmentbooleantrueAlso 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 functionResult
Returns a stringThe returned value is recorded
ThrowsThe URL is recorded as REDACTED, and the failure is reported once through diag
Returns a non-stringThe 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:

FieldTypePurpose
keysreadonly string[]Exact attribute keys, matched case-sensitively
keyPatternRegExp | readonly RegExp[]Patterns tested against the key
shouldScrub(key: string) => booleanArbitrary predicate. Use only where the two above cannot express the match
scrub(key: string, value) => value | undefinedReplacement 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 inOutcome
scrubThe value becomes REDACTED and the rule stays active. The matcher fired on that key, so the original value is not kept
shouldScrubThe 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.