Leaklens is a lightweight, real-time secret detection tool that prevents accidental leaks by identifying passwords, API keys, JWTs, and private keys at the moment theyβre pasted or shared. Built with security-first design, it offers automatic redaction, deterministic output, and CLI/HTTP modes for easy integration into modern workflows.
-
π 4 Detection Rules
- β PEM private keys (RSA, EC, DSA, generic)
- β JWT tokens (3-part base64 format)
- β Password assignments (password, api_key, secret, etc.)
- β High-entropy token detection (conservative, ignores UUIDs/hashes)
-
π‘οΈ Security First
- β Automatic secret redaction (never leaks full secrets)
- β No input logging (user data never logged)
- β Rate limiting (100 req/min per IP in HTTP mode)
- β Request size limits (1MB max)
- β Deterministic output (no timing leaks)
-
π Dual Mode Operation
- β CLI Mode: Analyze text from command line, stdin, or files
- β HTTP Server Mode: REST API with health check and analyze endpoints
-
β‘ Advanced Processing
- β Overlap merging (combines duplicate detections)
- β Deterministic sorting (consistent output)
- β Risk scoring (high/medium/low)
- β Line number and byte position tracking
-
β‘ Fast & Lightweight
- β Standard library only (no external dependencies)
- β Single binary deployment
- β Cross-platform (Windows, Linux, macOS)
-
π§ͺ Well Tested
- β 95+ unit tests
- β 95%+ code coverage
- β Comprehensive test suite
See FEATURES.md for the complete feature list.
# Clone the repository
git clone https://github.com/yourusername/pasteguard.git
cd pasteguard
# Build
go build -o pasteguard .
# Or install globally
go install .Download pre-built binaries from the Releases page.
# Analyze text from command line
pasteguard --text "password = secret123"
# Analyze from stdin
echo "api_key = sk-1234567890" | pasteguard
# Analyze a file
cat config.txt | pasteguardExample Output:
{
"overall_risk": "high",
"risk_rationale": "High severity issues detected",
"findings": [
{
"type": "password_assignment",
"severity": "high",
"confidence": "medium",
"reason": "secr...t123",
"line_number": 1
}
]
}# Start the server (default port :8787)
pasteguard serve
# Start on custom port
pasteguard serve --addr :8080Test the API:
Using curl (Unix/Linux/Git Bash):
# Health check
curl http://localhost:8787/health
# Analyze text
curl -X POST http://localhost:8787/analyze \
-H "Content-Type: application/json" \
-d '{"text": "password = secret123"}'Using PowerShell (Windows):
# Health check
Invoke-RestMethod -Uri http://localhost:8787/health
# Analyze text
$body = @{
text = "password = secret123"
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8787/analyze `
-Method POST `
-ContentType "application/json" `
-Body $bodyUsing curl.exe in PowerShell (if curl.exe is available):
# Use curl.exe explicitly (not the PowerShell alias)
curl.exe -X POST http://localhost:8787/analyze `
-H "Content-Type: application/json" `
-d '{\"text\": \"password = secret123\"}'# Basic usage
pasteguard --text "your text here"
# Empty string (handled correctly)
pasteguard --text ""
# Pipe from stdin
echo "your text" | pasteguard
# From file
cat file.txt | pasteguardpasteguard serve --addr :8787GET /health
Using curl (Unix/Linux/Git Bash):
curl http://localhost:8787/healthUsing PowerShell:
Invoke-RestMethod -Uri http://localhost:8787/healthResponse:
{"status": "ok"}POST /analyze
Using curl (Unix/Linux/Git Bash):
curl -X POST http://localhost:8787/analyze \
-H "Content-Type: application/json" \
-d '{"text": "password = secret123"}'Using PowerShell (Recommended):
$body = @{
text = "password = secret123"
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8787/analyze `
-Method POST `
-ContentType "application/json" `
-Body $bodyUsing curl.exe in PowerShell (if available):
# Note: Use curl.exe explicitly, not the PowerShell curl alias
curl.exe -X POST http://localhost:8787/analyze `
-H "Content-Type: application/json" `
-d "{\"text\": \"password = secret123\"}"Response:
{
"overall_risk": "high",
"risk_rationale": "High severity issues detected",
"findings": [
{
"type": "password_assignment",
"severity": "high",
"confidence": "medium",
"reason": "secr...t123",
"line_number": 1
}
]
}Detects RSA, EC, DSA, and generic private keys in PEM format.
pasteguard --text "-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"Detects JSON Web Tokens (3-part base64 format).
pasteguard --text 'token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."'Detects common password/secret assignment patterns.
pasteguard --text 'password = "secret123"'
pasteguard --text 'api_key = "sk-1234567890"'
pasteguard --text 'secret: "my_secret_value"'Detects high-entropy token-like strings with conservative filtering (ignores UUIDs, hashes, commit hashes).
pasteguard --text 'api_key = "AbCdEfGhIjKlMnOpQrStUvWxYz1234567890"'All secrets are automatically redacted in the output. Full secrets never appear in JSON responses.
- Token heuristics: >50% of token masked
- Other rules: First 4 and last 4 characters shown
- Rate Limiting: 100 requests per minute per IP
- Size Limits: 1MB maximum request body
- No Input Logging: User input never logged to console
All responses follow this JSON structure:
{
"overall_risk": "high" | "medium" | "low",
"risk_rationale": "Description of risk level",
"findings": [
{
"type": "pem_private_key" | "jwt_token" | "password_assignment" | "token_heuristics",
"severity": "high" | "medium" | "low",
"confidence": "high" | "medium" | "low",
"reason": "redacted_secret",
"line_number": 1
}
]
}- high: Any finding with high severity detected
- medium: Findings detected but none are high severity
- low: No findings detected
PowerShell (Windows):
# Run comprehensive test suite with report
.\test-all.ps1Unix/Linux/Mac:
# Run all tests with coverage
go test ./... -cover
# Run backend tests
cd backend && go test ./... -cover && cd ..# Run all tests
go test ./...
# Run with coverage
go test ./... -cover
# Run specific test suites
go test -v ./... -run TestCLI
go test -v ./server
go test -v ./detector
# Test backend module
cd backend && go test ./... && cd ..Test Coverage:
- CLI Tests: 13 tests
- HTTP Server Tests: 15 tests
- Rule Tests: 50+ tests
- Engine Tests: 10+ tests
- Redaction Tests: 8 tests
- Merge/Sort Tests: 11 tests
- Backend Module: (no tests yet)
- Total: 95+ tests
- Complete Feature List - All working features and capabilities
- Architecture Documentation - System architecture and design
- Testing Guide - Comprehensive testing instructions
- PowerShell Examples - PowerShell-specific usage examples
- ASCII Architecture Diagram - Text-based architecture diagram
Pasteguard uses a modular rule-based architecture:
Entry Points (CLI/HTTP)
β
Detector Engine
β
Detection Rules (PEM, JWT, Password, Token Heuristics)
β
Processing Pipeline (Merge, Sort, Score, Redact)
β
JSON Output
See ARCHITECTURE.md for detailed architecture documentation.
- Go 1.21 or later
go build -o pasteguard .go test ./...pasteguard/
βββ main.go # CLI entry point
βββ detector/ # Detection engine and rules
β βββ engine.go # Core engine
β βββ rule.go # Rule interface
β βββ pem_rule.go # PEM detection
β βββ jwt_rule.go # JWT detection
β βββ password_rule.go # Password detection
β βββ token_heuristics_rule.go # Token detection
βββ server/ # HTTP server
β βββ server.go # HTTP handlers
βββ *_test.go # Test files
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Go standard library only
- Inspired by secret scanning tools like GitGuardian, TruffleHog, and Gitleaks
- Issues: GitHub Issues
- Discussions: GitHub Discussions
| Feature | Status | Details |
|---|---|---|
| PEM Key Detection | β Working | RSA, EC, DSA, generic |
| JWT Detection | β Working | 3-part base64 format |
| Password Detection | β Working | Multiple keywords, quoted/unquoted |
| Token Heuristics | β Working | High-entropy, conservative |
| CLI Mode | β Working | --text flag, stdin, file input |
| HTTP Server | β Working | /health, /analyze endpoints |
| Overlap Merging | β Working | Automatic duplicate detection |
| Secret Redaction | β Working | >50% masking for tokens |
| Rate Limiting | β Working | 100 req/min per IP |
| Size Limits | β Working | 1MB max request body |
| Tests | β Passing | 95+ tests, 95%+ coverage |
For complete details, see FEATURES.md.
Made with β€οΈ using Go