How it works
When AppSec is enabled, dd-trace integrates a Web Application Firewall (WAF) engine into your Node.js process. Every incoming HTTP request is evaluated against Datadog’s managed rule set before your application code runs. If a request matches a known attack pattern, it can be blocked automatically and reported to Datadog.OWASP Top 10
Detects and blocks SQL injection, XSS, command injection, path traversal, SSRF, and other OWASP Top 10 attacks.
IP & user blocking
Block specific IP addresses or authenticated users via the Datadog UI with no redeployment needed.
RASP
Runtime Application Self-Protection detects exploitation of code-level vulnerabilities in real time.
API Security
Automatically discovers API endpoints and collects schema information to detect shadow or sensitive APIs.
Enabling AppSec
Or enable programmatically
Pass For fine-grained control, pass an options object:
appsec: true (or an options object) to tracer.init():AppSec requires a Datadog Agent running alongside your application. The tracer sends security data to the Agent, which forwards it to the Datadog backend.
Configuration options
| Option | Environment variable | Default | Description |
|---|---|---|---|
enabled | DD_APPSEC_ENABLED | false | Enable AppSec |
rules | DD_APPSEC_RULES | — | Path to a custom WAF rules file |
rateLimit | DD_APPSEC_TRACE_RATE_LIMIT | 100 | Max attack traces per second |
wafTimeout | DD_APPSEC_WAF_TIMEOUT | 5000 | WAF execution timeout (microseconds) |
rasp.enabled | DD_APPSEC_RASP_ENABLED | false | Enable RASP |
apiSecurity.enabled | DD_API_SECURITY_ENABLED | true | Enable API Security schema collection |
obfuscatorKeyRegex | DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP | — | Regex to redact sensitive parameter keys in reports |
obfuscatorValueRegex | DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP | — | Regex to redact sensitive parameter values in reports |
AppSec SDK
Thetracer.appsec object exposes methods for linking authenticated users to traces, checking blocks, and tracking security-relevant events.
setUser(user)
Links an authenticated user to the current trace. Call this after a user successfully authenticates so that AppSec can correlate requests with user identities for user-blocking rules.User object accepts the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique user identifier |
email | string | No | User email address |
name | string | No | Display name |
session_id | string | No | Session identifier |
role | string | No | User role |
scope | string | No | OAuth scopes or SAML assertions |
isUserBlocked(user)
Checks if the given user matches any active user-blocking rules in Datadog. Returnstrue if the user should be blocked. If no user is linked to the trace yet, setUser is called internally.
blockRequest(req?, res?)
Sends a blocking response to the client based on the request’sAccept header (JSON or HTML) and ends the response. Returns true if blocking was successful.
req and res are omitted, the method uses the request objects from the current async context.
trackUserLoginSuccessEvent(user, metadata?) — deprecated
Links a successful login event to the current trace.trackUserLoginFailureEvent(userId, exists, metadata?) — deprecated
eventTrackingV2
Thetracer.appsec.eventTrackingV2 object provides the current recommended API for tracking login events.
trackUserLoginSuccess(login, user?, metadata?)
trackCustomEvent(eventName, metadata?)
Links any custom business-logic event to the current trace. Useful for tracking suspicious activity such as password resets, account modifications, or high-value transactions.Supported frameworks
AppSec supports all major Node.js HTTP frameworks that dd-trace instruments, including:- Express
- Fastify
- Hapi
- Koa
- NestJS (via Express or Fastify adapter)
- Next.js
- Restify
- Connect
