NAME
Sentry::DataScrubber - Removes credentials and personal data from request data
SYNOPSIS
my $scrubber = Sentry::DataScrubber->from_current_client;
my $request = {
url => $scrubber->url($url),
query_string => $scrubber->params(\%query),
data => $scrubber->body(\%form),
headers => $scrubber->headers(\%headers),
cookies => $scrubber->cookies(\%cookies),
env => $scrubber->env(\%ENV),
};
DESCRIPTION
Used by the framework plugins and HTTP client integrations before request data leaves the process, and by the client on every event (see "event").
Values of sensitive names (keys, parameters, headers, cookies) are replaced by [Filtered], regardless of send_default_pii. Names are compared in lower case, split into words at -, _, ., spaces and camel case (xApiKey becomes x api key), so that unrelated names like author or session_count are kept. A name is sensitive if
without separators, it contains
password,passwd,passphrase,passcode,passwort,kennwort,secret,token,credential,bearer,csrf,xsrf,sessid,sessionid,sessionkey,oauthverifier,samlresponse,databaseurl,webhookurl, orkeypreceded byaccess,api,client,encryption,license,private,signingorsubscription; also inside a word (accesstoken,PassWord,AWSAccessKeyId,PHPSESSID; but alsosecretaryortoken_count),one of its words is
pass,pw,pwd,pin,otp,dsn,auth,authorization,authenticationorjwt,its last word is
session,sid,signatureorsig, possibly followed by a number (e.g.laravel_session,connect.sid,X-Amz-Signature,X-Hub-Signature-256),it is just
key(API keys in URLs),or it is on the "denylist".
This follows the default deny list of Sentry's Python SDK and Relay's default PII rules, with word boundaries for the ambiguous names.
Without send_default_pii the Cookie and Set-Cookie headers, cookies, client IP headers (X-Forwarded-For, X-Real-IP, Forwarded, Forwarded-For, X-Forwarded, X-Original-Forwarded-For, True-Client-IP, CF-Connecting-IP, CF-Connecting-IPv6, Client-IP, X-Client-IP, X-Cluster-Client-IP, Fastly-Client-IP, Fly-Client-IP, X-Azure-ClientIP, X-Appengine-User-IP, X-Envoy-External-Address, X-ProxyUser-Ip), the headers with which authenticating proxies pass on the user (Remote-User, X-Remote-User, X-Forwarded-User, X-Forwarded-Email, X-Forwarded-Preferred-Username, X-Amzn-Oidc-Identity, X-Amzn-Oidc-Data, X-MS-Client-Principal, X-MS-Client-Principal-Name, X-MS-Client-Principal-Id, X-Goog-Authenticated-User-Email, X-Goog-Authenticated-User-Id, X-Userinfo, X-Forwarded-Groups, Cf-Access-Authenticated-User-Email, and client certificates: X-SSL-Client-Cert, X-SSL-Client-S-DN, X-SSL-Client-DN, X-Client-Cert, X-Forwarded-Client-Cert, X-ARR-ClientCert, X-Amzn-Mtls-Clientcert and its -Leaf, -Subject, -Issuer and -Serial-Number variants) and REMOTE_ADDR are left out or filtered as well. With it, sensitive cookies are still filtered, also inside the Cookie header.
Headers holding URLs (Referer, Origin, X-Original-URL, X-Rewrite-URL, X-Original-URI, X-Forwarded-Uri, X-Forwarded-Url) are scrubbed like the request URL, see "url".
ATTRIBUTES
denylist
my $scrubber = Sentry::DataScrubber->new(
denylist => ['customer_id', qr/\Ainternal-/i]);
Further sensitive names. A string matches names that are equal to it apart from case and separators (customer_id matches CustomerId and CUSTOMER-ID, but not X-Customer-Id); a regex is matched against the name as it is. See "denylist" in Sentry::SDK.
send_default_pii
max_request_body_size
See "send_default_pii" in Sentry::SDK and "max_request_body_size" in Sentry::SDK.
METHODS
from_current_client
my $scrubber = Sentry::DataScrubber->from_current_client;
my $scrubber = Sentry::DataScrubber->from_current_client(@names);
A scrubber configured with the options of the current client. Further sensitive names, e.g. the session cookie of a framework, are added to its "denylist".
from_options
my $scrubber = Sentry::DataScrubber->from_options($client->get_options);
Like "from_current_client", with the options given.
event
my $scrubbed = $scrubber->event($event);
A copy of the event with what the application sets on it scrubbed, like the EventScrubber of Sentry's Python SDK: the request (as described above; a query_string may be a string), extra, user and the data of breadcrumbs and spans (the transaction's own in its trace context too), recursively. Keys named like headers are scrubbed like them there, e.g. HTTP_COOKIE in a copy of the environment; without send_default_pii, keys of personal data (ip_address, remote_addr) are filtered as well. Headers and query strings may also be lists of pairs. Other contexts and tags are left alone, as in Sentry's Python SDK.
is_sensitive
$scrubber->is_sensitive('X-Api-Key'); # true
Whether the value of a name must be filtered, see "DESCRIPTION".
headers
my $headers = $scrubber->headers({ Authorization => '...' });
Accepts names in HTTP (Content-Type) and CGI (HTTP_CONTENT_TYPE) form.
cookies
Returns undef without send_default_pii.
env
Returns the allowed environment variables only.
params
Filters query or form parameters, recursively for nested structures.
body
my $data = $scrubber->body(\%form_params);
Like "params", but returns undef if the parameters are empty or exceed max_request_body_size.
json_body
my $data = $scrubber->json_body($raw_json);
Decodes and filters a JSON request body. Returns undef if the body is empty, exceeds max_request_body_size or is no valid JSON.
key
my $shown = $scrubber->key('session:3f9a1c2e7b5d4a6f'); # "session:*"
A cache key, object key or file path as recorded: without "send_default_pii", its :- or /-separated parts that look like ids or tokens replaced by *.
url
Removes user info and the fragment and replaces the values of sensitive query parameters by [Filtered], unescaped.
url_and_query
my ($url, $query) = $scrubber->url_and_query($url);
The URL without user info, query and fragment, and the query with the values of sensitive parameters replaced by [Filtered] (undef if the URL has none). For data of outgoing requests (url and http.query).