Skip to main content

Security

The AI Gateway provides powerful security features to protect your data and prevent abuse. Block sensitive information from being sent to AI providers, and stop malicious users from exploiting your applications.

Sensitive Data Protection

The Risk

When using AI assistants or building AI-powered apps, sensitive data can accidentally be exposed:
Real scenarios we’ve seen:
  • AWS keys sent in code context to ChatGPT
  • Database passwords included in error messages
  • Customer PII processed by AI for “analysis”
  • API secrets in environment variable debugging

Automatic Detection

The gateway scans all requests for sensitive patterns:
Sensitive data detection
Detected patterns include:
  • AWS Access Keys and Secret Keys
  • GitHub Personal Access Tokens
  • Database connection strings
  • API keys (various providers)
  • Private keys (RSA, SSH, etc.)
  • Credit card numbers
  • Social Security Numbers
  • Email addresses
  • Phone numbers

Blocking Sensitive Data

Configure the gateway to block requests containing sensitive data:

Action Types

Remediation

When sensitive data is detected:
  1. Review the log - see exactly what was exposed
  2. Rotate credentials - change any exposed secrets immediately
  3. Update your code - ensure secrets aren’t in files that get sent to AI
  4. Enable blocking - prevent future exposure
Keep secrets in .env files and ensure .env is in your .gitignore. Most AI assistants respect gitignore patterns.

Blocking Malicious Users

When building AI-powered applications, you need to protect against abuse.

Common Abuse Patterns

Prompt Injection

Users trying to manipulate your AI to bypass restrictions

Cost Attacks

Users making excessive requests to run up your AI costs

Data Extraction

Attempts to extract training data or system prompts

Jailbreaking

Trying to make the AI produce harmful content

User Blocking

Block abusive users instantly:
Block user interface
When a blocked user makes a request:
  • Request is immediately rejected
  • No tokens are consumed
  • Event is logged for audit

Unblocking Users

Viewing Blocked Users

Access the block list at app.leanmcp.com/security:
  1. Open app.leanmcp.com/securityBlocked Users
  2. View all blocked users with reasons and timestamps
  3. Manage blocks (extend, reduce, remove)

Rate Limiting

Prevent abuse with intelligent rate limiting:

Rate Limit Strategies

Handling Rate Limits

When users hit limits:

Content Filtering

Block requests based on content:

Input Filtering

Output Filtering

Audit Logging

All security events are logged:
Audit log

Export Audit Logs

For compliance and review:

Security Alerts

Get notified of security events:

Alert Configuration

Alert Examples

Security alert example

Best Practices

Begin with ‘warn’ actions to understand what would be blocked, then switch to ‘block’ once tuned.
Check blocked requests weekly to ensure legitimate users aren’t being affected.
Configure security alerts before launch so you’re notified of issues immediately.
Set limits that allow normal use while preventing abuse. Adjust based on observed patterns.
Make sure users know your usage policies and what behavior will result in blocking.

Next Steps

Observability

Monitor all requests and detect issues

Token Optimization

Reduce costs while maintaining quality

Ready? Open your Observability Dashboard →

View your first logged AI request at app.leanmcp.com/observability