|
| 1 | +# IAST Security Controls Configuration |
| 2 | + |
| 3 | +This document explains how to configure custom security controls for IAST using the `DD_IAST_SECURITY_CONTROLS_CONFIGURATION` environment variable. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `DD_IAST_SECURITY_CONTROLS_CONFIGURATION` environment variable allows you to specify custom sanitizers and validators that IAST should recognize when analyzing your application for security vulnerabilities. |
| 8 | + |
| 9 | +## Format |
| 10 | + |
| 11 | +The configuration uses the following format: |
| 12 | + |
| 13 | +``` |
| 14 | +CONTROL_TYPE:VULNERABILITY_TYPES:MODULE:METHOD[:PARAMETER_POSITIONS] |
| 15 | +``` |
| 16 | + |
| 17 | +Multiple security controls are separated by semicolons (`;`). |
| 18 | + |
| 19 | +### Fields |
| 20 | + |
| 21 | +1. **CONTROL_TYPE**: Either `INPUT_VALIDATOR` or `SANITIZER` |
| 22 | +2. **VULNERABILITY_TYPES**: Comma-separated list of vulnerability types or `*` for all types |
| 23 | +3. **MODULE**: Python module path (e.g., `shlex`, `django.utils.http`) |
| 24 | +4. **METHOD**: Method name to instrument |
| 25 | +5. **PARAMETER_POSITIONS** (Optional): Zero-based parameter positions to validate (INPUT_VALIDATOR only) |
| 26 | + |
| 27 | +### Vulnerability Types |
| 28 | + |
| 29 | +Supported vulnerability types: |
| 30 | +- `COMMAND_INJECTION` / `CMDI` |
| 31 | +- `CODE_INJECTION` |
| 32 | +- `SQL_INJECTION` / `SQLI` |
| 33 | +- `XSS` |
| 34 | +- `HEADER_INJECTION` |
| 35 | +- `PATH_TRAVERSAL` |
| 36 | +- `SSRF` |
| 37 | +- `UNVALIDATED_REDIRECT` |
| 38 | +- `INSECURE_COOKIE` |
| 39 | +- `NO_HTTPONLY_COOKIE` |
| 40 | +- `NO_SAMESITE_COOKIE` |
| 41 | +- `WEAK_CIPHER` |
| 42 | +- `WEAK_HASH` |
| 43 | +- `WEAK_RANDOMNESS` |
| 44 | +- `STACKTRACE_LEAK` |
| 45 | + |
| 46 | +Use `*` to apply to all vulnerability types. |
| 47 | + |
| 48 | +## Examples |
| 49 | + |
| 50 | +### Basic Examples |
| 51 | + |
| 52 | +#### Input Validator for Command Injection |
| 53 | +```bash |
| 54 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="INPUT_VALIDATOR:COMMAND_INJECTION:shlex:quote" |
| 55 | +``` |
| 56 | + |
| 57 | +#### Sanitizer for XSS |
| 58 | +```bash |
| 59 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="SANITIZER:XSS:html:escape" |
| 60 | +``` |
| 61 | + |
| 62 | +#### Multiple Vulnerability Types |
| 63 | +```bash |
| 64 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="INPUT_VALIDATOR:COMMAND_INJECTION,XSS:custom.validator:validate_input" |
| 65 | +``` |
| 66 | + |
| 67 | +#### All Vulnerability Types |
| 68 | +```bash |
| 69 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="SANITIZER:*:custom.sanitizer:sanitize_all" |
| 70 | +``` |
| 71 | + |
| 72 | +### Advanced Examples |
| 73 | + |
| 74 | +#### Multiple Security Controls |
| 75 | +```bash |
| 76 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="INPUT_VALIDATOR:COMMAND_INJECTION:shlex:quote;SANITIZER:XSS:html:escape;SANITIZER:SQLI:custom.db:escape_sql" |
| 77 | +``` |
| 78 | + |
| 79 | +#### Validator with Specific Parameter Positions |
| 80 | +```bash |
| 81 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="INPUT_VALIDATOR:COMMAND_INJECTION:custom.validator:validate:0,2" |
| 82 | +``` |
| 83 | +This validates only the 1st and 3rd parameters (0-based indexing). |
| 84 | + |
| 85 | +#### Complex Configuration |
| 86 | +```bash |
| 87 | +export DD_IAST_SECURITY_CONTROLS_CONFIGURATION="INPUT_VALIDATOR:COMMAND_INJECTION,XSS:security.validators:validate_user_input:0,1;SANITIZER:SQLI:database.utils:escape_sql_string;SANITIZER:*:security.sanitizers:clean_all_inputs" |
| 88 | +``` |
| 89 | + |
| 90 | +## How It Works |
| 91 | + |
| 92 | +### Input Validators |
| 93 | +- **Purpose**: Mark input parameters as safe after validation |
| 94 | +- **When to use**: When your function validates input and returns a boolean or throws an exception |
| 95 | +- **Effect**: Parameters are marked as secure for the specified vulnerability types |
| 96 | +- **Parameter positions**: Optionally specify which parameters to mark (0-based index) |
| 97 | + |
| 98 | +### Sanitizers |
| 99 | +- **Purpose**: Mark return values as safe after sanitization |
| 100 | +- **When to use**: When your function cleans/escapes input and returns the sanitized value |
| 101 | +- **Effect**: Return value is marked as secure for the specified vulnerability types |
| 102 | + |
| 103 | +## Integration with Existing Controls |
| 104 | + |
| 105 | +Your custom security controls work alongside the built-in IAST security controls: |
| 106 | + |
| 107 | +- `shlex.quote` (Command injection sanitizer) |
| 108 | +- `html.escape` (XSS sanitizer) |
| 109 | +- Database escape functions (SQL injection sanitizers) |
| 110 | +- Django validators (Various validators) |
| 111 | +- And more... |
| 112 | + |
| 113 | +## Error Handling |
| 114 | + |
| 115 | +If there are errors in the configuration: |
| 116 | +- Invalid configurations are logged and skipped |
| 117 | +- The application continues to run with built-in security controls |
| 118 | +- Check application logs for configuration warnings/errors |
0 commit comments