Skip to main content

Advanced sensitive data scanner with Jupyter notebook support and intelligent false positive filtering

Project description

SecretSentry ๐Ÿ›ก๏ธ

The first AI-powered sensitive data scanner built for modern data science and web development workflows

PyPI version Python Support License: MIT

SecretSentry is an advanced sensitive data scanner that goes beyond traditional secret detection. Built specifically for Jupyter notebooks, web development, and data science workflows, it combines machine learning with regex patterns to intelligently filter false positives while detecting API keys, PII, credentials, and other sensitive information.

๐ŸŽฏ Why SecretSentry?

Built for Modern Workflows

  • ๐Ÿ”ฌ Jupyter Notebook Specialist: First scanner designed for .ipynb files
  • ๐Ÿค– AI-Powered Detection: Machine learning models reduce false positives by up to 80%
  • ๐Ÿง  Smart Context Awareness: Understands code context, not just pattern matching
  • ๐ŸŒ Multi-Environment: CLI, Jupyter notebooks, and Python scripts
  • ๐ŸŽ›๏ธ Interactive Analysis: Built-in widgets for exploring findings

Comprehensive Detection

  • ๐Ÿ”‘ 50+ Built-in Patterns: API keys, tokens, secrets, credentials
  • ๐Ÿ‘ค PII Detection: SSNs, credit cards, phone numbers, emails
  • ๐Ÿ’ฐ Financial Data: Salary information, bank accounts, routing numbers
  • ๐ŸŒ Geographic Data: Coordinates, IP addresses, postal codes
  • ๐Ÿฅ Sensitive Categories: Ethnic data, religious information, medical records

Advanced Features

  • ๐Ÿ›ก๏ธ Smart Sanitization: Context-aware gibberish replacement
  • ๐Ÿค– Ensemble Detection: Combines regex + ML for maximum accuracy
  • ๐Ÿ“Š Rich Visualizations: Charts and statistics (with matplotlib/seaborn)
  • ๐Ÿ“ˆ Pandas Integration: Export to DataFrames for analysis
  • ๐ŸŽฏ Confidence Scoring: ML predictions with 0.0-1.0 confidence scores
  • ๐Ÿ”„ CI/CD Ready: Perfect for automation and pipelines
  • ๐Ÿ–ฅ๏ธ Cross-Platform: Works on macOS, Windows, and Linux

๐Ÿš€ Quick Start

Installation

# Basic installation (regex-only detection)
pip install secretsentry

# With machine learning capabilities
pip install secretsentry[ml]

# Advanced ML with transformers (best accuracy)
pip install secretsentry[ml-advanced]

# Full installation with all features
pip install secretsentry[full]

# For Jupyter notebooks only
pip install secretsentry[jupyter]

Basic Usage

from secretsentry import SecretSentry, quick_scan, quick_ml_scan

# Quick scan with regex detection
scanner = quick_scan("./my_project")

# Quick scan with AI/ML enhancement (recommended)
scanner = quick_ml_scan("./my_project", confidence_threshold=0.7)

# Manual scanning with ML capabilities
scanner = SecretSentry(
    use_ml_detection=True,
    ml_confidence_threshold=0.7,
    ml_ensemble_mode=True  # Combines regex + ML
)
findings = scanner.scan_directory("./my_project")
scanner.display_findings()

# Access ML-specific results
ml_findings = scanner.get_ml_findings()
high_confidence = scanner.get_high_confidence_findings(0.8)

# Sanitize files (creates backups automatically)
stats = scanner.sanitize_files(dry_run=True)  # Preview changes
stats = scanner.sanitize_files()  # Actually sanitize

Command Line

# Basic regex scanning
secretsentry scan ./my_project --display

# AI-enhanced scanning (recommended)
secretsentry scan ./my_project --ml --display

# Quick ML scan with optimal settings
secretsentry scan ./my_project --ml-quick

# ML-only detection with custom confidence
secretsentry scan ./my_project --ml-only --ml-confidence 0.8

# Check ML requirements
secretsentry scan --check-ml

# Export findings with ML metadata
secretsentry scan ./my_project --ml --export findings.json

# Sanitize files (with backup)
secretsentry scan ./my_project --sanitize --dry-run
secretsentry scan ./my_project --sanitize

# List all detection patterns
secretsentry list-patterns

๐Ÿค– AI-Powered Detection

SecretSentry's machine learning capabilities provide context-aware detection that dramatically reduces false positives:

ML Detection Modes

# Ensemble Mode (recommended): Combines regex + ML
scanner = SecretSentry(
    use_ml_detection=True,
    ml_ensemble_mode=True,
    ml_confidence_threshold=0.7
)

# ML-Only Mode: Pure machine learning detection
scanner = SecretSentry(
    use_ml_detection=True,
    ml_ensemble_mode=False,
    ml_confidence_threshold=0.8
)

# Quick ML scan with optimal settings
scanner = quick_ml_scan("./my_project")

ML Features

  • ๐Ÿง  Context Understanding: Analyzes surrounding code context, not just patterns
  • ๐Ÿ“Š Confidence Scoring: Every ML detection includes a 0.0-1.0 confidence score
  • ๐Ÿ”ฌ Feature Extraction: Text entropy, keyword analysis, pattern recognition
  • ๐Ÿ‹๏ธ Multiple Models: Logistic Regression, Isolation Forest, optional Transformers
  • ๐Ÿ’พ Model Caching: Trained models cached for faster subsequent scans
  • ๐Ÿ–ฅ๏ธ Local Processing: All ML inference happens on your machine (no data sent externally)

ML Requirements

# Check what's available on your system
secretsentry scan --check-ml

# Install ML dependencies
pip install secretsentry[ml]           # Basic ML (scikit-learn)
pip install secretsentry[ml-advanced]  # Advanced ML (transformers)

๐ŸŽ“ Jupyter Notebook Integration

SecretSentry shines in Jupyter environments with zero false positives from notebook metadata:

# In Jupyter notebook
from secretsentry import quick_scan, quick_ml_scan

# Quick ML scan with visualizations
scanner = quick_ml_scan("./test_data", show_plots=True)

# Interactive exploration with ML metadata
scanner.create_interactive_viewer()

# Data analysis with ML findings
df = scanner.to_dataframe(include_ml_findings=True)
summary = df.groupby(['pattern_type', 'detection_method']).size()

# Analyze confidence scores
ml_df = df[df['detection_method'] == 'ml']
confidence_analysis = ml_df['confidence_score'].describe()

๐Ÿ“Š What Makes It Special

AI-Enhanced Accuracy

Traditional regex scanners flag these as secrets:

โŒ aws_secret_key: iVBORw0KGgoAAAANSUhEUgAABKYAAAMW...  # Just a PNG image!
โŒ api_key: "cell_type": "code"  # Notebook metadata!  
โŒ secret: #3498db  # CSS color!
โŒ token: "placeholder_for_testing"  # Test data!

SecretSentry with ML understands context and only reports real secrets:

โœ… aws_secret_key: AKIAIOSFODNN7EXAMPLE (confidence: 0.95)
โœ… stripe_key: sk_live_1234567890abcdef123456789 (confidence: 0.89)  
โœ… database_url: postgresql://user:password@localhost/db (confidence: 0.92)

ML Advantages:

  • ๐ŸŽฏ Context Awareness: Understands surrounding code patterns
  • ๐Ÿ“Š Confidence Scoring: Know how certain each detection is
  • ๐Ÿง  Learning: Improves over time with usage patterns
  • ๐Ÿ›ก๏ธ Adaptive: Handles new secret formats without regex updates

Smart Sanitization

SecretSentry doesn't just find secretsโ€”it fixes them safely:

# Before sanitization
API_KEY = "sk_live_1234567890abcdef"
employee_ssn = "123-45-6789"
coordinates = "40.7128, -74.0060"

# After sanitization (context-aware gibberish)
API_KEY = "sk_live_xK8mP9nQ4vL7wR2Z"
employee_ssn = "456-78-9123"  
coordinates = "38.8951, -77.0364"

๐Ÿ”ง Advanced Usage

Custom Patterns

# Add organization-specific patterns
custom_patterns = {
    'employee_id': r'EMP-\d{6}',
    'project_code': r'PROJ-[A-Z]{3}-\d{4}',
    'internal_api': r'internal_key_[a-zA-Z0-9]{32}'
}

scanner = SecretSentry(custom_patterns=custom_patterns)

CI/CD Integration

#!/usr/bin/env python3
# security_check.py
import sys
from secretsentry import SecretSentry

def security_gate():
    # Use ML-enhanced detection for better accuracy in CI/CD
    scanner = SecretSentry(
        use_ml_detection=True,
        ml_ensemble_mode=True,
        ml_confidence_threshold=0.8  # Higher threshold for CI/CD
    )
    findings = scanner.scan_directory(".", show_progress=False)
    
    if findings:
        print(f"โŒ SECURITY CHECK FAILED: {len(findings)} secrets found")
        
        # Show high-confidence ML findings first
        if scanner.use_ml_detection:
            ml_findings = scanner.get_ml_findings()
            high_conf = scanner.get_high_confidence_findings(0.9)
            print(f"๐Ÿค– ML Analysis: {len(ml_findings)} ML findings, {len(high_conf)} high confidence")
        
        scanner.display_findings(max_display=10)
        return 1
    else:
        print("โœ… SECURITY CHECK PASSED: No secrets detected")
        return 0

if __name__ == "__main__":
    sys.exit(security_gate())

CI/CD CLI Usage:

# Basic CI/CD check
secretsentry scan . --ml --quiet || exit 1

# High-confidence only for sensitive deployments  
secretsentry scan . --ml-only --ml-confidence 0.9 --quiet || exit 1

Batch Processing

# Scan multiple projects with ML
from secretsentry import SecretSentry
import os

projects = ["./frontend", "./backend", "./data-science"]
all_results = {}

for project in projects:
    if os.path.exists(project):
        # Use ML for better accuracy across different project types
        scanner = SecretSentry(
            use_ml_detection=True,
            ml_ensemble_mode=True,
            ml_confidence_threshold=0.7
        )
        findings = scanner.scan_directory(project)
        
        # Collect ML statistics
        ml_findings = scanner.get_ml_findings()
        all_results[project] = {
            'total_findings': len(findings),
            'ml_findings': len(ml_findings),
            'high_confidence': len(scanner.get_high_confidence_findings(0.8))
        }
        
        # Export detailed reports with ML metadata
        scanner.export_findings(f"{project.replace('./', '')}_security_report.json")

print("Security Summary:", all_results)

๐Ÿ“ˆ Detection Categories

๐Ÿ”‘ API Keys & Secrets (20+ patterns)
  • AWS Access/Secret Keys
  • GitHub Tokens (classic & fine-grained)
  • Google API Keys
  • Stripe Keys (live & test)
  • Slack Tokens & Webhooks
  • SendGrid API Keys
  • Twilio Keys
  • Mailgun Keys
  • Azure Storage Keys
  • Heroku API Keys
  • Generic API patterns
๐Ÿ’ณ Financial Data (8+ patterns)
  • Credit Cards (Visa, MasterCard, AmEx, Discover, JCB, Diners)
  • Bank Account Numbers
  • Routing Numbers
  • IBAN & SWIFT Codes
  • Salary Information
๐Ÿ‘ค Personal Information (10+ patterns)
  • Social Security Numbers
  • Phone Numbers (US & International)
  • Email Addresses
  • Passport Numbers
  • Driver's License Numbers
  • Medical Record Numbers
๐ŸŒ Geographic Data (5+ patterns)
  • GPS Coordinates
  • IP Addresses (IPv4 & IPv6)
  • MAC Addresses
  • ZIP/Postal Codes
๐Ÿฅ Sensitive Personal Data (5+ patterns)
  • Ethnic/Racial Categories
  • Religious Affiliations
  • Medical Information
  • Disability Status
๐Ÿ” Cryptographic Material (5+ patterns)
  • Private Keys (RSA, SSH)
  • Public Keys & Certificates
  • JWT Tokens
  • OAuth Tokens

๐ŸŽ›๏ธ Configuration

Environment Variables

# Disable progress bars
export SECRETSENTRY_NO_PROGRESS=1

# Custom config file
export SECRETSENTRY_CONFIG=/path/to/config.json

# ML model cache directory (optional)
export SECRETSENTRY_MODEL_CACHE=/path/to/ml/models

# Force ML detection on/off
export SECRETSENTRY_USE_ML=true
export SECRETSENTRY_ML_CONFIDENCE=0.7

Configuration File

{
    "excluded_patterns": ["test_", "example_", "demo_"],
    "excluded_files": ["*.test.js", "test_*.py"],
    "excluded_dirs": ["tests", "examples", "docs"],
    "custom_patterns": {
        "company_id": "COMP-\\d{8}"
    },
    "sanitization": {
        "create_backups": true,
        "backup_suffix": ".backup"
    },
    "ml_detection": {
        "enabled": true,
        "confidence_threshold": 0.7,
        "ensemble_mode": true,
        "use_transformers": false,
        "model_cache_dir": "~/.cache/secretsentry/models"
    }
}

โšก Performance & Requirements

ML Performance

Detection Mode Speed Accuracy Memory Usage Dependencies
Regex Only โšกโšกโšกโšกโšก โœ…โœ…โœ… ๐ŸŸข Low Minimal
ML Basic โšกโšกโšกโšก โœ…โœ…โœ…โœ… ๐ŸŸก Medium scikit-learn
ML Advanced โšกโšกโšก โœ…โœ…โœ…โœ…โœ… ๐Ÿ”ด High transformers

System Requirements

Minimum (Regex-only):

  • Python 3.7+
  • 50MB RAM
  • Any CPU

Recommended (ML Basic):

  • Python 3.8+
  • 512MB RAM
  • 2+ CPU cores
  • 200MB disk space

Optimal (ML Advanced):

  • Python 3.9+
  • 2GB+ RAM
  • 4+ CPU cores
  • 1GB disk space

Installation Time

pip install secretsentry              # ~30 seconds
pip install secretsentry[ml]          # ~2 minutes  
pip install secretsentry[ml-advanced] # ~5 minutes (downloads models)

First Run Performance

  • Regex detection: Instant
  • ML Basic: ~30 seconds (model training on first run)
  • ML Advanced: ~2 minutes (model download + training)
  • Subsequent runs: Fast (models cached)

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

# Clone the repository
git clone https://github.com/yourusername/secretsentry.git
cd secretsentry

# Install development dependencies (includes ML dependencies)
pip install -e ".[full]"
pip install pytest black flake8

# Run tests (includes ML tests)
pytest tests/

# Test ML functionality specifically
python test_ml_detection.py

# Format code
black secretsentry/
flake8 secretsentry/

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by detect-secrets and truffleHog
  • ML capabilities powered by scikit-learn and Transformers
  • Built for the data science and security communities
  • Special thanks to all contributors and the open source community
  • Grateful to the broader AI/ML community for advancing secret detection research

๐Ÿ“ž Support


SecretSentry - Standing guard over your sensitive data ๐Ÿ›ก๏ธ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secretsentry-2.0.0.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secretsentry-2.0.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file secretsentry-2.0.0.tar.gz.

File metadata

  • Download URL: secretsentry-2.0.0.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for secretsentry-2.0.0.tar.gz
Algorithm Hash digest
SHA256 556070798c435564ee69e210dc27482b71aa776114f24df027b334ba174b0f69
MD5 ed28722cc75ad03a61bec12fc689e384
BLAKE2b-256 e35f169dfd0f2098cc4bb455aad8a3e53fa13689c2aa48ce95a87734d7623465

See more details on using hashes here.

File details

Details for the file secretsentry-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: secretsentry-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for secretsentry-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 694f2b82f26d10096b4e2cb0c1322e075c10a696bd65abac8b804cc2b5cdc708
MD5 c78b67e5d08b3d0f31dbe3ad6b5a6bf6
BLAKE2b-256 3ee51c5d8ac3855e28950b82926a58afd934f698ecf1ef07068f17d1058d02cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page