{"id":25620726,"url":"https://github.com/drew2a/sentry-scrubber","last_synced_at":"2026-02-08T10:33:15.802Z","repository":{"id":278359653,"uuid":"935363701","full_name":"drew2a/sentry-scrubber","owner":"drew2a","description":"A lightweight and flexible Python library for scrubbing sensitive information from Sentry events before they are sent to the server.","archived":false,"fork":false,"pushed_at":"2025-08-20T13:34:21.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-25T08:00:00.988Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drew2a.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-19T10:23:45.000Z","updated_at":"2025-08-20T13:33:42.000Z","dependencies_parsed_at":"2025-03-06T21:30:37.346Z","dependency_job_id":null,"html_url":"https://github.com/drew2a/sentry-scrubber","commit_stats":null,"previous_names":["drew2a/sentry-scrubber"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/drew2a/sentry-scrubber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drew2a%2Fsentry-scrubber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drew2a%2Fsentry-scrubber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drew2a%2Fsentry-scrubber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drew2a%2Fsentry-scrubber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drew2a","download_url":"https://codeload.github.com/drew2a/sentry-scrubber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drew2a%2Fsentry-scrubber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29227746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T09:43:19.170Z","status":"ssl_error","status_checked_at":"2026-02-08T09:42:55.556Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-22T07:27:53.062Z","updated_at":"2026-02-08T10:33:15.784Z","avatar_url":"https://github.com/drew2a.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentry Scrubber\n\nA lightweight Python library designed to protect sensitive information in Sentry events.\n\n## Introduction\n\n`sentry-scrubber` is a lightweight Python library designed to protect sensitive information in Sentry events. It\nautomatically detects and scrubs usernames, IP addresses, file paths, and other potentially sensitive data before events\nare sent to Sentry.\n\n## Table of Contents\n\n1. [Installation](#installation)\n2. [Basic Usage](#basic-usage)\n3. [Configuration Options](#configuration-options)\n4. [Integration with Sentry](#integration-with-sentry)\n5. [Advanced Usage](#advanced-usage)\n6. [API Reference](#api-reference)\n\n## Installation\n\n```bash\npip install sentry-scrubber\n```\n\n## Basic Usage\n\n### Quick Start\n\n```python\nimport sentry_sdk\nfrom sentry_scrubber.scrubber import SentryScrubber\n\n# Create a scrubber with default settings\nscrubber = SentryScrubber()\n\n# Initialize Sentry with the scrubber\nsentry_sdk.init(\n    dsn=\"https://your-dsn@sentry.io/project\",\n    before_send=scrubber.scrub_event\n)\n```\n\n### Scrubbing Individual Events\n\n```python\nfrom sentry_scrubber.scrubber import SentryScrubber\n\n# Create a scrubber instance\nscrubber = SentryScrubber()\n\n# Example event with sensitive information\nevent = {\n    \"user\": {\"username\": \"john_doe\"},\n    \"server_name\": \"johns-macbook\",\n    \"contexts\": {\n        \"os\": {\n            \"home_dir\": \"/Users/john_doe/Documents\"\n        }\n    },\n    \"request\": {\n        \"url\": \"https://api.example.com/users/john_doe\",\n        \"env\": {\n            \"SERVER_ADDR\": \"192.168.1.1\"\n        }\n    }\n}\n\n# Scrub the event\nscrubbed_event = scrubber.scrub_event(event)\nprint(scrubbed_event)\n# Result: {'user': {'username': '\u003credacted\u003e'}, 'server_name': '\u003credacted\u003e', 'contexts': {'os': {'home_dir': '/Users/\u003credacted\u003e/Documents'}}, 'request': {'url': 'https://api.example.com/users/\u003credacted\u003e', 'env': {'SERVER_ADDR': '\u003credacted\u003e'}}}\n```\n\n### Scrubbing Text\n\n```python\nfrom sentry_scrubber.scrubber import SentryScrubber\n\nscrubber = SentryScrubber()\nsensitive_occurrences = set()\n\n# Example text with sensitive information\ntext = \"Error in file /home/username/app/main.py at line 42, reported from 192.168.1.1\"\n\n# Scrub the text\nscrubbed_text = scrubber.scrub_text(text, sensitive_occurrences)\nprint(scrubbed_text)  # \"Error in file /home/\u003credacted\u003e/app/main.py at line 42, reported from \u003credacted\u003e\"\nprint(sensitive_occurrences)  # {'username'}\n```\n\n## Configuration Options\n\n### Custom Home Folders\n\n```python\nfrom sentry_scrubber.scrubber import SentryScrubber\n\n# Define custom home folders to detect usernames\ncustom_home_folders = {\n    'users',\n    'home',\n    'projects',  # Custom folder\n    'workspace'  # Custom folder\n}\n\nscrubber = SentryScrubber(home_folders=custom_home_folders)\n```\n\n### Sensitive Dictionary Keys\n\n```python\nfrom sentry_scrubber.scrubber import SentryScrubber\n\n# Define custom keys to scrub\ncustom_keys = {\n    'USERNAME',\n    'USERDOMAIN',\n    'server_name',\n    'COMPUTERNAME',\n    'api_key',  # Custom sensitive key\n    'auth_token',  # Custom sensitive key\n    'password'  # Custom sensitive key\n}\n\nscrubber = SentryScrubber(dict_keys_for_scrub=custom_keys)\n```\n\n### Dictionary Markers for Removal\n\n```python\nfrom sentry_scrubber.scrubber import SentryScrubber\n\n# Define markers that indicate sections to be removed\ndict_markers = {\n    'visibility': 'private',\n    'status': ['error', 'failure'],  # List of values to match\n    'level': ('warning', 'critical'),  # Tuple of values to match\n    'environment': {'staging', 'production'}  # Set of values to match\n}\n\nscrubber = SentryScrubber(dict_markers_to_scrub=dict_markers)\n\n# Example usage\nevent = {\n    'public_info': 'This is public',\n    'private_section': {\n        'visibility': 'private',  # This will cause the entire 'private_section' to be redacted\n        'secret_data': 'sensitive information'\n    },\n    'error_section': {\n        'status': 'error',  # This will cause the entire 'error_section' to be redacted\n        'details': 'Error details'\n    }\n}\n\nscrubbed = scrubber.scrub_event(event)\n# Result: {'public_info': 'This is public', 'private_section': '\u003credacted\u003e', 'error_section': '\u003credacted\u003e'}\n```\n\n### Exclusions\n\n```python\nfrom scrubber import SentryScrubber\n\n# Define values to be excluded from scrubbing\nexclusions = {\n    'local',\n    '127.0.0.1',\n    'localhost',  # Custom exclusion\n    'admin',  # Custom exclusion\n    'test_user'  # Custom exclusion\n}\n\nscrubber = SentryScrubber(exclusions=exclusions)\n```\n\n### Disable IP or Hash Scrubbing\n\n```python\nfrom scrubber import SentryScrubber\n\n# Create a scrubber that doesn't scrub IP addresses\nscrubber_no_ip = SentryScrubber(scrub_ip=False)\n\n# Create a scrubber that doesn't scrub hash values\nscrubber_no_hash = SentryScrubber(scrub_hash=False)\n\n# Create a scrubber that scrubs neither IPs nor hashes\nscrubber_minimal = SentryScrubber(scrub_ip=False, scrub_hash=False)\n```\n\n## Advanced Scrubbing Techniques\n\n### Define Event Fields to Remove\n\n```python\nfrom scrubber import SentryScrubber\n\nscrubber = SentryScrubber()\n\n# Add fields to completely remove from events\nscrubber.event_fields_to_cut.add('device')\nscrubber.event_fields_to_cut.add('debug_data')\n```\n\n### Sensitive Information Pairs\n\n```python\nfrom scrubber import SentryScrubber\n\nscrubber = SentryScrubber()\n\n# Manually add sensitive information and corresponding placeholders\nscrubber.sensitive_strings.add({\"john_doe\", \"secret_token_123\"})\n\n# Now any instance of these strings will be replaced in subsequent scrubs\ntext = \"User john_doe used secret_token_123 to authenticate\"\nscrubbed = scrubber.scrub_text(text)\n# Result: \"User \u003credacted\u003e used \u003credacted\u003e to authenticate\"\n```\n\n## Integration with Sentry\n\n### Django Integration\n\n```python\n# settings.py\nimport sentry_sdk\nfrom sentry_scrubber.scrubber import SentryScrubber\nfrom sentry_sdk.integrations.django import DjangoIntegration\n\nscrubber = SentryScrubber(\n    # Add custom configurations here\n    dict_keys_for_scrub={'api_key', 'csrf_token', 'session_id', 'USERNAME'}\n)\n\nsentry_sdk.init(\n    dsn=\"https://your-dsn@sentry.io/project\",\n    integrations=[DjangoIntegration()],\n    before_send=scrubber.scrub_event\n)\n```\n\n### Flask Integration\n\n```python\n# app.py\nimport sentry_sdk\nfrom sentry_scrubber.scrubber import SentryScrubber\nfrom sentry_sdk.integrations.flask import FlaskIntegration\nfrom flask import Flask\n\n# Initialize scrubber\nscrubber = SentryScrubber()\n\n# Initialize Sentry with Flask integration\nsentry_sdk.init(\n    dsn=\"https://your-dsn@sentry.io/project\",\n    integrations=[FlaskIntegration()],\n    before_send=scrubber.scrub_event\n)\n\napp = Flask(__name__)\n```\n\n### FastAPI Integration\n\n```python\n# main.py\nimport sentry_sdk\nfrom sentry_scrubber.scrubber import SentryScrubber\nfrom fastapi import FastAPI\n\n# Initialize scrubber\nscrubber = SentryScrubber()\n\n# Initialize Sentry\nsentry_sdk.init(\n    dsn=\"https://your-dsn@sentry.io/project\",\n    before_send=scrubber.scrub_event\n)\n\napp = FastAPI()\n```\n\n## API Reference\n\n### SentryScrubber\n\n```python\nSentryScrubber(\n    home_folders: Optional[set] = None,\ndict_keys_for_scrub: Optional[set] = None,\ndict_markers_to_scrub: Optional[dict] = None,\nexclusions: Optional[set] = None,\nscrub_ip: bool = True,\nscrub_hash: bool = True,\nscrub_folders: bool = True,\n)\n```\n\n#### Methods\n\n- `scrub_event(event: Optional[Dict[str, Any]], _=None) -\u003e Optional[Dict[str, Any]]`: Scrubs a Sentry event\n- `scrub_text(text: Optional[str], sensitive_occurrences: Set[str]) -\u003e Optional[str]`: Scrubs sensitive information from\n  text\n- `scrub_entity_recursively(entity, sensitive_strings: set, depth=10)`: Recursively scrubs an entity\n\n#### Properties\n\n- `home_folders`: Set of folder names used to identify usernames in paths\n- `dict_keys_for_scrub`: Set of dictionary keys whose values should be scrubbed\n- `dict_markers_to_scrub`: Dictionary of markers that indicate sections to be redacted\n- `event_fields_to_cut`: Set of fields to remove from events\n- `exclusions`: Set of values to exclude from scrubbing\n- `scrub_ip`: Flag to enable or disable IP scrubbing. Defaults to True.\n- `scrub_hash`: Flag to enable or disable hash scrubbing. Defaults to True.\n- `scrub_folders`: Flag to enable or disable folder scrubbing. Defaults to True.\n            \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrew2a%2Fsentry-scrubber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrew2a%2Fsentry-scrubber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrew2a%2Fsentry-scrubber/lists"}