Objective
The goal of this plugin is to detect improper or automated use of the AI Gateway by analyzing behavioral patterns in incoming HTTP requests. It leverages time series tracking, client fingerprinting, and semantic analysis to detect bots, abusive integrations, or non-human traffic in server-to-server (S2S) environments. This plugin helps you:- Detect timing-based attacks and suspicious request patterns
- Identify content similarity across multiple requests
- Detect artificially “clean” inputs lacking human-like imperfections
- Monitor suspicious header configurations
- Track token usage across different clients
- Take configurable actions against detected anomalies
How It Works
The Anomaly Detector plugin works by analyzing multiple aspects of incoming requests and comparing them to historical data:- Timing patterns - Detects suspiciously regular or frequent request patterns, identifying requests sent at exact, fixed intervals
- Content similarity - Identifies repeated identical content across requests using hash-based and semantic similarity analysis
- Artificially “clean” inputs - Detects inputs that lack human-like imperfections, suggesting programmatic generation
- Suspicious headers - Analyzes header configurations for bot-like patterns
- Token usage patterns - Monitors tokens used across multiple IPs or user agents to detect credential leakage or misuse
Configuration Options
Option | Type | Description | Default |
---|---|---|---|
threshold | float | Anomaly score threshold (0.0-1.0) that triggers action | Required |
action | string | Action to take when anomaly is detected | Required |
retention_period | integer | Period in seconds to retain request data | 300 (5 minutes) |
timing_pattern_weight | float | Weight for timing pattern detection | 0.2 |
content_similarity_weight | float | Weight for content similarity detection | 0.2 |
suspicious_headers_weight | float | Weight for suspicious headers detection | 0.2 |
token_usage_weight | float | Weight for token usage pattern detection | 0.2 |
min_time_between_requests | integer | Minimum time between requests in seconds | 1 |
max_requests_to_analyze | integer | Maximum number of past requests to analyze | 10 |
Available Actions
Action | Description |
---|---|
alert_only | Logs the detection but allows the request to proceed |
throttle | Adds a delay to suspicious requests to discourage automated activity |
block | Blocks requests identified as anomalous with a 403 Forbidden response |
Example Configuration
Note: Whenaction
is set toblock
, requests identified as anomalous will be rejected with a 403 Forbidden status code.
Anomaly Detection Factors
The plugin analyzes multiple factors to calculate an anomaly score, flagging specific types of anomalies:Timing Patterns
Analyzes the timing between requests to detect:- Suspiciously regular intervals between requests (e.g., exactly 1 request every 5 minutes)
- Requests that come too frequently (based on
min_time_between_requests
) - Very short or perfectly even request intervals indicating automated traffic
- Automated patterns that humans typically don’t exhibit
Content Similarity
Examines request content to identify:- Identical payloads sent repeatedly
- Unusual repetition patterns
- Content that appears machine-generated
Suspicious Headers
Analyzes request headers for suspicious patterns:- Missing or generic User-Agent strings
- Missing Accept headers
- Missing Accept-Language headers
- Missing Referer or Origin headers
- Other header anomalies typical of automated tools
Token Usage Patterns
Monitors authentication token usage across:- Multiple IP addresses
- Different User-Agent strings
- Unusual access patterns
token_fingerprint_mismatch
and helps identify potential security breaches.
Best Practices
- Start with alert_only mode: Monitor anomaly detection before blocking to avoid false positives
- Adjust threshold based on your traffic: Lower thresholds catch more anomalies but may increase false positives
- Tune weights for your use case: Adjust the weights of different factors based on your application’s specific threats
- Use with rate limiting: Combine with rate limiting for comprehensive protection
- Consider user experience: Use throttling instead of blocking for borderline cases
- Monitor logs: Watch for patterns in anomaly detection to refine your configuration
Integration with Contextual Security
The Anomaly Detector plugin is designed to work seamlessly with the Contextual Security plugin, creating a powerful layered defense system:- Data Sharing: When the Anomaly Detector identifies suspicious behavior, it feeds this data to the fingerprint tracking system.
- Enhanced Decision Making: The Contextual Security plugin can then use this data to make more informed decisions about whether to allow, block, or challenge requests.
- Persistent Protection: Even if an attacker changes their behavior slightly, the combined fingerprinting and contextual analysis can still identify them.
- Adaptive Security: As more anomalous behavior is detected, the security posture automatically strengthens against the specific threats targeting your application.
Client Fingerprint Strategy
The plugin generates a fingerprint for each client using:- IP address
- User-Agent
- Token (if present)
- Additional headers (e.g., Accept-Language)
Data Storage
The plugin uses a short-lived storage system (Redis with TTL) to track:- Timestamp history per fingerprint
- Last N request bodies for semantic analysis
- Last headers per fingerprint/token
retention_period
and is used to build a behavioral profile of each client.
Use Cases
Case | Description | Detection Trigger |
---|---|---|
Cron bot | Script sending 1 request every 5 min | fixed_interval_pattern |
Repetitive prompt | Body is 95% identical every time | semantic_repetition |
Low entropy input | No user variability | input_cleanliness_suspicious |
Missing headers | No User-Agent, Accept, etc. | header_anomaly |
Token reuse across agents | Same token, different fingerprints | token_fingerprint_mismatch |