Complete Guide to Password and Credential Sanitization for AI Tools
Learn how to detect and redact passwords, credentials, and secrets before using AI tools. Complete credential protection guide.
Complete Guide to Password and Credential Sanitization for AI Tools
You're debugging an authentication issue. You paste the error log to ChatGPT, including the database connection string with the password. The AI helps you fix the issueābut now it has your production credentials.
This happens constantly. Developers paste code with credentials, error logs with passwords, config files with API keys. Every paste is a potential security breach.
This guide covers password and credential sanitization for AIādetecting and redacting secrets before AI exposure.
What Counts as Credentials
More than just passwords. Anything that authenticates access:
- Passwords: User passwords, admin passwords, service accounts
- API Keys: AWS, Google, Stripe, OpenAI keys
- Database Credentials: Usernames, passwords, connection strings
- Tokens: JWT, OAuth, session tokens
- SSH Keys: Private keys, certificates
- Secrets: Environment variables, encryption keys
- Access Keys: AWS access key IDs and secret keys
Common Credential Patterns
1. Database Connections
// Before:
postgresql://admin:password123@localhost:5432/mydb
mysql://root:MySecretPass@db.server.com:3306/prod
// After:
postgresql://[REDACTED_USER]:[REDACTED_PASS]@localhost:5432/mydb
mysql://[REDACTED_USER]:[REDACTED_PASS]@db.server.com:3306/prod
2. API Keys
// Before:
const apiKey = 'sk_live_abc123xyz789';
const awsKey = 'AKIAIOSFODNN7EXAMPLE';
// After:
const apiKey = '[REDACTED_STRIPE_KEY]';
const awsKey = '[REDACTED_AWS_KEY]';
3. Environment Variables
// Before:
DATABASE_URL=postgresql://user:pass@localhost
AWS_SECRET_KEY=xyz123secret
STRIPE_API_KEY=sk_live_abc
// After:
DATABASE_URL=[REDACTED_DATABASE_URL]
AWS_SECRET_KEY=[REDACTED_AWS_SECRET]
STRIPE_API_KEY=[REDACTED_STRIPE_KEY]
4. JWT Tokens
// Before:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
// After:
Authorization: Bearer [REDACTED_JWT]
Credential Detection
Modern sanitization tools detect these patterns automatically:
- AWS keys: Start with AKIA, ASIA followed by 20 alphanumeric chars
- Stripe keys: Start with sk_live_, sk_test_, pk_live_
- Google keys: Start with AIza, GOOG
- GitHub tokens: Start with gho_, github_pat_
- Generic passwords: Patterns like "password", "pass", "pwd" near values
- Database URLs: Connection strings with credential syntax
The Sanitization Workflow
Step 1: Before Pasting Code
Review the text for any credentials. Look for:
- Passwords in strings
- API keys in comments
- Connection strings
- Environment variable names with secrets
Step 2: Use Auto-Detection
Use PasteShield to auto-detect credentials. Paste your text and the tool will identify:
- Known API key patterns
- Database credentials
- Password-like strings
- JWT and token formats
Step 3: Manual Review
Auto-detection catches most, but not all. Manually check for:
- Custom secrets in your codebase
- Company-specific API keys
- Internal service credentials
Step 4: After AI Use
Critical: rotate any credentials that touched AI. If you pasted it, assume it's compromised.
Before and After Examples
Example 1: Database Error
Before:
Error: Connection failed
postgresql://admin:P@ssw0rd!@prod-db-01.internal:5432/users
SQLSTATE: 28000
SQLERRM: password authentication failed
After:
Error: Connection failed
postgresql://[REDACTED_USER]:[REDACTED_PASS]@[REDACTED_HOST]:5432/users
SQLSTATE: [ERROR_CODE]
SQLERRM: password authentication failed
Example 2: Environment Config
Before:
// Production config
export AWS_ACCESS_KEY_ID='AKIAIOSFODNN7EXAMPLE'
export AWS_SECRET_ACCESS_KEY='wJalrXUtnFEMI/K7MDENG/bPxRfiCY'
export STRIPE_KEY='sk_live_abc123xyz789'
export DATABASE_URL='postgresql://user:pass@localhost'
After:
// Production config (credentials redacted)
export AWS_ACCESS_KEY_ID='[REDACTED_AWS_KEY]'
export AWS_SECRET_ACCESS_KEY='[REDACTED_AWS_SECRET]'
export STRIPE_KEY='[REDACTED_STRIPE_KEY]'
export DATABASE_URL='[REDACTED_DATABASE_URL]'
Example 3: Code with Password
Before:
const config = {
// Admin credentials
username: 'admin',
password: 'S3cur3P@ss2024!',
host: 'internal-server.company.com'
};
After:
const config = {
// Admin credentials (use env variables in production)
username: process.env.ADMIN_USER,
password: process.env.ADMIN_PASS, // Reference only
host: process.env.HOST
};
Best Practices
- Use environment variables: Never hardcode credentials
- Use secrets managers: AWS Secrets Manager, HashiCorp Vault
- Rotate after exposure: Any credential that touched AI should be rotated
- Don't paste secrets: At allāever
Credential Storage
Proper credential storage prevents accidental exposure:
- Environment variables: .env files, never committed
- Secrets managers: AWS Secrets Manager, GCP Secret Manager
- Password managers: 1Password, Bitwarden for team sharing
- Configuration services: Consul, etcd for internal config
Common Mistakes
Mistake 1: "It's Just Test Credentials"
Test credentials often lead to production systems. Never paste any credentials.
Mistake 2: "I'll Just Remove the Password"
The username, host, and connection pattern still reveal infrastructure.
Mistake 3: "It's Internal Anyway"
AI systems are external. "Internal" has no meaning after pasting.
Mistake 4: Forgetting API Keys
API keys are credentials. AWS keys, Stripe keys, all should be redacted.
The "Don't Paste" Rule
The safest credential rule: never paste credentials to AI.
If you absolutely must (for debugging), these rules:
- Redact completelyāusername and password
- Replace hosts with generic names
- Rotate credentials immediately after
- Document the exposure
Conclusion: Credentials Are the Keys
Credentials grant access to your systems, data, and infrastructure. Once exposed to AI, they're compromisedāno exceptions.
The solution is behavioral: never paste credentials to AI. Use environment variables, secrets managers, and proper credential hygiene.
If you must paste for debugging, sanitize everythingācredentials, hosts, connection stringsāand rotate immediately after.
Credentials: don't paste. Ever.
If you must: sanitize and rotate.
Found this guide helpful?
Share it with your team to spread AI privacy awareness.