Skip to content

Scrubbing sensitive data ​

Parsemend stores what your SDK sends. Anything you do not want in an issue has to be removed inside your application, before the SDK sends the event, so the value never leaves your server.

Verified against sentry/sentry 4.29, sentry/sentry-laravel 4.27 and @sentry/node 10.74.

Parsemend does not scrub on arrival

There is no server-side data scrubber, and no sensitive-fields or safe-fields setting in the panel. An event is stored as the SDK sent it, including the raw envelope. Everything on this page runs in your application.

What gets sent without you asking ​

send_default_pii in PHP and sendDefaultPii in Node control personal data such as the user's IP address, cookies and request headers. In the PHP SDK it is off unless you turn it on.

That option does not cover outgoing HTTP requests. When your application calls another API, the SDK records the request, and the query string goes with it as http.query:

SDKWhere http.query appears
Laravel, HTTP client (Http::get() and friends)The breadcrumb for the request, and the http.client span when tracing is on
Node, fetchThe breadcrumb for the request

The url field next to it has the query string removed. http.query keeps it whole. OAuth token exchanges are the usual casualty: client_secret, code, access_token and fb_exchange_token all travel in the query string, so one exception thrown after a token exchange stores your app secret in the issue.

PHP and Laravel ​

Three options take a callable:

OptionRuns onReturn null to
before_breadcrumbEach breadcrumb, when it is recordedDrop the breadcrumb
before_sendEach error event, just before it is sentDrop the event
before_send_transactionEach transaction, with its spans, just before it is sentDrop the transaction

Laravel ​

Create config/sentry.php with only the hooks. The package merges its own defaults and your SENTRY_* env vars in underneath, so nothing else needs copying:

php
<?php

// config/sentry.php
use App\Support\SentryScrubber;

return [
    'before_breadcrumb' => [SentryScrubber::class, 'beforeBreadcrumb'],
    'before_send_transaction' => [SentryScrubber::class, 'beforeSendTransaction'],
];

Use [Class::class, 'method'] rather than a closure. A closure cannot be serialized, so php artisan config:cache fails on it.

php
<?php

namespace App\Support;

use Sentry\Breadcrumb;
use Sentry\Event;

final class SentryScrubber
{
    public static function beforeBreadcrumb(Breadcrumb $breadcrumb): Breadcrumb
    {
        if (($breadcrumb->getMetadata()['http.query'] ?? '') === '') {
            return $breadcrumb;
        }

        return $breadcrumb->withMetadata('http.query', '[Filtered]');
    }

    public static function beforeSendTransaction(Event $transaction): Event
    {
        foreach ($transaction->getSpans() as $span) {
            if (($span->getData('http.query') ?? '') !== '') {
                $span->setData(['http.query' => '[Filtered]']);
            }
        }

        return $transaction;
    }
}

Two details in there are deliberate:

  • withMetadata() returns a copy. A breadcrumb is immutable, so return the new instance rather than the one you were given.
  • Span data is overwritten, not removed. setData() merges into the existing data and there is no method that deletes a key, so the value is replaced with [Filtered].

Plain PHP ​

The same options go straight into init:

php
\Sentry\init([
    'dsn' => 'https://[email protected]/42',
    'before_breadcrumb' => [SentryScrubber::class, 'beforeBreadcrumb'],
    'before_send_transaction' => [SentryScrubber::class, 'beforeSendTransaction'],
]);

Or stop recording outgoing requests ​

If you do not need them, the Laravel package can skip outgoing requests entirely:

bash
SENTRY_BREADCRUMBS_HTTP_CLIENT_REQUESTS_ENABLED=false
SENTRY_TRACE_HTTP_CLIENT_REQUESTS_ENABLED=false

The first stops the breadcrumbs, the second the spans. You lose the trail of API calls leading up to an error, which is often the most useful part of it, so filtering is usually the better trade.

Node ​

js
import * as Sentry from '@sentry/node'

Sentry.init({
  dsn: 'https://[email protected]/42',

  beforeBreadcrumb(breadcrumb) {
    if (breadcrumb.data?.['http.query']) {
      breadcrumb.data['http.query'] = '[Filtered]'
    }

    return breadcrumb
  },

  beforeSend(event) {
    // Error events: remove anything else your code attaches.
    return event
  },

  beforeSendTransaction(event) {
    return event
  },
})
OptionSignatureReturn null to
beforeBreadcrumb(breadcrumb, hint?) => Breadcrumb | nullDrop the breadcrumb
beforeSend(event, hint) => ErrorEvent | null, or a promise of oneDrop the event
beforeSendTransaction(event, hint) => TransactionEvent | null, or a promise of oneDrop the transaction
beforeSendSpan(span) => SpanJSONNot possible: it must return the span

Check that it works ​

Make an outgoing request with a query string, then throw an exception in the same request. Open the issue in the issue context bundle: sample_events carries the breadcrumbs leading in, and the request's http.query should read [Filtered].

If a secret already reached Parsemend ​

Scrubbing applies to events sent after you deploy it. Events already stored keep what they arrived with, so treat any credential that appeared in an issue as exposed and rotate it.

Parsemend, by MAVA Design