URL Filter
Advanced URL detection and filtering guardrail that prevents access to unauthorized domains. Uses comprehensive regex patterns and robust URL parsing to detect various URL formats, validates them against security policies, and filters based on a configurable allow list.
Key Security Features:
- Prevents credential injection attacks (
user:pass@domain) - Blocks typosquatting and look-alike domains
- Restricts dangerous schemes (
javascript:,data:) - Supports IP addresses and CIDR ranges
- Configurable subdomain matching
Supported stages
| Stage | Supported | Notes |
|---|---|---|
pre_flight |
✅ | Block disallowed URLs in user messages before the LLM call |
input |
✅ | Runs concurrently with the LLM call |
output |
✅ | Recommended. Prevents the LLM from generating or echoing disallowed URLs in its response |
Configuration
{
"name": "URL Filter",
"config": {
"url_allow_list": ["example.com", "192.168.1.100", "https://api.service.com/v1"],
"allowed_schemes": ["https"],
"block_userinfo": true,
"allow_subdomains": false
}
}
Parameters
-
url_allow_list(optional): List of allowed domains, IP addresses, CIDR ranges, or full URLs.- Default:
[](blocks all URLs)
- Default:
-
allowed_schemes(optional): Set of allowed URL schemes/protocols.- Default:
["https"](HTTPS-only for security)
- Default:
-
block_userinfo(optional): Whether to block URLs containing userinfo (user:pass@domain) to prevent credential injection attacks.true(default): Blocks URLs containing userinfofalse: Allows URLs containing userinfo
-
allow_subdomains(optional): Whether to allow subdomains of allowed domains.false(default): Only exact domain matches (e.g.,example.comallowsexample.comandwww.example.com)true: Allows subdomains (e.g.,example.comallowsapi.example.com)
Mend Platform configuration
When a policy is loaded from the Mend Platform API the URL filter is identified by "id": "url". Its per-row config object uses camelCase keys that are mapped to the SDK's snake_case URLConfig fields as follows:
API field (config.*) |
URLConfig field |
Default |
|---|---|---|
allowList |
url_allow_list |
[] |
allowedSchemes |
allowed_schemes |
["https"] |
customSchemes |
merged into allowed_schemes |
[] |
blockUserinfo |
block_userinfo |
true |
allowSubdomains |
allow_subdomains |
false |
customSchemes lists non-standard schemes the operator wants to permit (e.g. myapp://). They are merged with allowedSchemes into a single deduplicated allowed_schemes set.
Example API response row:
{
"id": "url",
"action": "Alert",
"status": true,
"direction": "Output",
"guardrail": "URL Filter",
"config": {
"allowList": ["company.com"],
"allowedSchemes": ["https"],
"customSchemes": [],
"blockUserinfo": true,
"allowSubdomains": false
}
}
If config is absent the guardrail is loaded with all defaults (equivalent to URLConfig()).
Implementation Notes
- Detects URLs, domains, and IP addresses using regex patterns
- Validates URL schemes and security policies
- Supports exact domain matching or subdomain inclusion
- Handles IP addresses and CIDR ranges
What It Returns
Returns a GuardrailResult with the following info dictionary:
{
"guardrail_name": "URL Filter",
"config": {
"allowed_schemes": ["https"],
"block_userinfo": true,
"allow_subdomains": false,
"url_allow_list": ["example.com"]
},
"detected": ["https://example.com", "https://user:pass@malicious.com"],
"allowed": ["https://example.com"],
"blocked": ["https://user:pass@malicious.com"],
"blocked_reasons": ["https://user:pass@malicious.com: Contains userinfo (potential credential injection)"]
}
Response Fields
guardrail_name: Name of the guardrail that was executedconfig: Applied configuration including allow list, schemes, userinfo blocking, and subdomain settingsdetected: All URLs detected in the text using regex patternsallowed: URLs that passed all security checks and allow list validationblocked: URLs that were blocked due to security policies or allow list restrictionsblocked_reasons: Detailed explanations for why each URL was blocked