Skip to content

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

CheckDescriptionDefault
prototypePollutionDetects __proto__, constructor.prototype✅ Enabled
pathTraversalDetects ../, ..\\ in paths✅ Enabled
ssrfInternalDetects internal IPs/URLsConfigurable
commandInjectionDetects shell metacharactersConfigurable
nosqlInjectionDetects MongoDB operatorsConfigurable

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: true

Per-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.prototype
  • prototype

Example Attack

{
"__proto__": {
"isAdmin": true
}
}

Configuration

vulnerabilityChecks:
prototypePollution: true # or false to disable

How 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 disable

SSRF (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_url

Command 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
- filename

NoSQL 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 fields

Handling 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:

CheckSeverityRisk Points
Prototype PollutionCritical+90
Path TraversalHigh+70
SSRF InternalHigh+70
Command InjectionCritical+90
NoSQL InjectionHigh+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 CategoryContractShield Coverage
A01: Broken Access Control✅ SSRF detection
A03: Injection✅ NoSQL, Command injection
A05: Security Misconfiguration✅ Strict defaults

Next Steps