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
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
.ipynbfiles - ๐ค 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
- ๐ Documentation: Full docs
- ๐ Issues: Report bugs
- ๐ฌ Discussions: Community forum
- ๐ง Contact: your.email@example.com
SecretSentry - Standing guard over your sensitive data ๐ก๏ธ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
556070798c435564ee69e210dc27482b71aa776114f24df027b334ba174b0f69
|
|
| MD5 |
ed28722cc75ad03a61bec12fc689e384
|
|
| BLAKE2b-256 |
e35f169dfd0f2098cc4bb455aad8a3e53fa13689c2aa48ce95a87734d7623465
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
694f2b82f26d10096b4e2cb0c1322e075c10a696bd65abac8b804cc2b5cdc708
|
|
| MD5 |
c78b67e5d08b3d0f31dbe3ad6b5a6bf6
|
|
| BLAKE2b-256 |
3ee51c5d8ac3855e28950b82926a58afd934f698ecf1ef07068f17d1058d02cb
|