Vulnerability Checks
import { Aside } from ‘@astrojs/starlight/components’;
Vulnerability Checks
ContractShield includes built-in detection for common application-layer vulnerabilities that traditional WAFs often miss.
Available Checks
| Check | Description | Default |
|---|---|---|
prototypePollution | Detects __proto__, constructor.prototype | ✅ Enabled |
pathTraversal | Detects ../, ..\\ in paths | ✅ Enabled |
ssrfInternal | Detects internal IPs/URLs | Configurable |
commandInjection | Detects shell metacharacters | Configurable |
nosqlInjection | Detects MongoDB operators | Configurable |
Configuration
Global Defaults
Enable checks for all routes:
defaults: vulnerabilityChecks: prototypePollution: true pathTraversal: true ssrfInternal: fields: [url, webhook_url, callback_url] commandInjection: fields: [command, script] nosqlInjection: truePer-Route Override
Disable or customize checks for specific routes:
routes: - id: admin.execute match: method: POST path: /admin/execute vulnerabilityChecks: commandInjection: false # Admin route allows commands rules: - id: admin.only type: cel action: block config: expr: "identity.scopes.exists(s, s == 'admin')"Prototype Pollution
What It Detects
Prototype pollution allows attackers to inject properties into JavaScript object prototypes, potentially leading to RCE.
Blocked patterns:
__proto__constructor.prototypeprototype
Example Attack
{ "__proto__": { "isAdmin": true }}Configuration
vulnerabilityChecks: prototypePollution: true # or false to disableHow It Works
ContractShield recursively scans all object keys in the request body and query parameters for prototype pollution patterns.
Path Traversal
What It Detects
Path traversal (directory traversal) attacks allow reading files outside the intended directory.
Blocked patterns:
../..\\- URL-encoded variants (
%2e%2e%2f, etc.)
Example Attack
{ "filename": "../../../etc/passwd"}Configuration
vulnerabilityChecks: pathTraversal: true # or false to disableSSRF (Server-Side Request Forgery)
What It Detects
SSRF attacks trick your server into making requests to internal services.
Blocked patterns:
localhost,127.0.0.1,::1- Private IP ranges (
10.x.x.x,192.168.x.x,172.16-31.x.x) - AWS metadata endpoint (
169.254.169.254) - Internal hostnames
Example Attack
{ "webhook_url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/"}Configuration
vulnerabilityChecks: ssrfInternal: fields: - url - webhook_url - callback_url - redirect_uri - image_urlCommand Injection
What It Detects
Command injection allows attackers to execute arbitrary system commands.
Blocked patterns:
- Shell metacharacters:
;,|,&,$(),` - Common commands:
rm,cat,wget,curl
Example Attack
{ "filename": "report.pdf; rm -rf /"}Configuration
vulnerabilityChecks: commandInjection: fields: - command - script - filenameNoSQL Injection
What It Detects
NoSQL injection attacks target MongoDB and similar databases using query operators.
Blocked patterns:
$where,$gt,$lt,$ne,$regex$or,$and,$not,$nor$exists,$type,$mod
Example Attack
{ "username": "admin", "password": { "$ne": "" }}This query would match any user with username “admin” regardless of password.
Configuration
vulnerabilityChecks: nosqlInjection: true # Scans all fieldsHandling Blocked Requests
When a vulnerability check triggers, ContractShield returns:
{ "error": "Request blocked", "reason": "Vulnerability detected: prototype pollution", "ruleHits": [ { "ruleId": "vuln:prototypePollution", "severity": "critical", "message": "Prototype pollution attempt detected in request body" } ]}Custom Response
app.use(contractshield({ policy: './policy.yaml', blockResponse: { message: "Security violation detected", includeRuleHits: process.env.NODE_ENV !== 'production' }}));Risk Scoring
Vulnerability checks contribute to the risk score:
| Check | Severity | Risk Points |
|---|---|---|
| Prototype Pollution | Critical | +90 |
| Path Traversal | High | +70 |
| SSRF Internal | High | +70 |
| Command Injection | Critical | +90 |
| NoSQL Injection | High | +70 |
Access the risk score in your code:
app.use((req, res, next) => { const { decision } = req.contractshield;
if (decision.risk.level === 'high' || decision.risk.level === 'critical') { // Log to security monitoring securityLogger.warn('High-risk request', { path: req.path, riskScore: decision.risk.score, ruleHits: decision.ruleHits }); }
next();});OWASP Coverage
ContractShield vulnerability checks address several OWASP Top 10 2025 categories:
| OWASP Category | ContractShield Coverage |
|---|---|
| A01: Broken Access Control | ✅ SSRF detection |
| A03: Injection | ✅ NoSQL, Command injection |
| A05: Security Misconfiguration | ✅ Strict defaults |
Next Steps
- Deployment Overview - Production patterns
- Pro: Sink-aware RASP - Advanced runtime protection