Skip to content

Commit f2183b1

Browse files
Feature-221 : Gateway-Level Input Validation & Output Sanitization (#1536)
* added input security validation Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> * testcases fixed Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> * fixed config.py Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> * added env vars and fixed validation code Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> * remove input_validator.py file Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> * fix: remove duplicate SecurityValidator import Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Veeresh K <veeruveeresh1522@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent 9822650 commit f2183b1

File tree

13 files changed

+1519
-4
lines changed

13 files changed

+1519
-4
lines changed

.env.example

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,73 @@ JWT_AUDIENCE_VERIFICATION=true
155155
TOKEN_EXPIRY=10080
156156
REQUIRE_TOKEN_EXPIRATION=false
157157

158+
#####################################
159+
# Security Validation & Sanitization
160+
#####################################
161+
162+
# Enable experimental input validation and output sanitization
163+
# This implements gateway-level security controls to protect against:
164+
# - Path traversal attacks (../../../etc/passwd)
165+
# - Command injection (file.jpg; rm -rf /)
166+
# - SQL injection ('; DROP TABLE users; --)
167+
# - XSS attacks (<script>alert(1)</script>)
168+
# - Control character injection (\x1b[31m)
169+
#
170+
# Roll-out phases:
171+
# Phase 0: EXPERIMENTAL_VALIDATE_IO=false (disabled, default)
172+
# Phase 1: EXPERIMENTAL_VALIDATE_IO=true, VALIDATION_STRICT=false (log-only)
173+
# Phase 2: EXPERIMENTAL_VALIDATE_IO=true, VALIDATION_STRICT=true (enforce in staging)
174+
# Phase 3: Production deployment with all features enabled
175+
EXPERIMENTAL_VALIDATE_IO=true
176+
177+
# Enable validation middleware for all requests
178+
# When enabled, validates all incoming request parameters and paths
179+
# Options: true, false (default)
180+
VALIDATION_MIDDLEWARE_ENABLED=true
181+
182+
# Strict validation mode
183+
# Options:
184+
# - true: Reject requests with validation failures (422 status)
185+
# - false: Log warnings but allow requests (log-only mode)
186+
# Recommended: false for dev/staging, true for production
187+
VALIDATION_STRICT=true
188+
189+
# Sanitize output to remove control characters
190+
# Removes ANSI escape sequences and C0/C1 control characters from responses
191+
# Preserves newlines (\n) and tabs (\t)
192+
# Options: true (default), false
193+
SANITIZE_OUTPUT=true
194+
195+
# Allowed root paths for resource access
196+
# Restricts file system access to specific directories
197+
# Format: JSON array or comma-separated list
198+
# Examples:
199+
# - JSON: ["/srv/data", "/var/app/uploads"]
200+
# - CSV: /srv/data,/var/app/uploads
201+
# - Empty: [] (no restrictions, not recommended)
202+
# PRODUCTION: Always configure this to limit resource access
203+
ALLOWED_ROOTS=[]
204+
205+
# Maximum allowed path depth
206+
# Prevents deeply nested path attacks
207+
# Default: 10 levels
208+
MAX_PATH_DEPTH=10
209+
210+
# Maximum parameter length (characters)
211+
# Prevents buffer overflow and DoS attacks
212+
# Default: 10000 characters
213+
MAX_PARAM_LENGTH=10000
214+
215+
# Regex patterns for dangerous input (JSON array)
216+
# Used to detect and block malicious input patterns
217+
# Default patterns:
218+
# 1. Shell metacharacters: [;&|`$(){}\[\]<>]
219+
# 2. Path traversal: \.\.[/\\]
220+
# 3. Control characters: [\x00-\x1f\x7f-\x9f]
221+
# 4. SQL injection: (drop|delete|insert|update|select)\s+(table|from|into|where)
222+
# Format: JSON array of regex patterns
223+
DANGEROUS_PATTERNS=["[;&|`$(){}\\[\\]<>]", "\\.\\.[/\\\\]", "[\\x00-\\x1f\\x7f-\\x9f]", "(?i)(drop|delete|insert|update|select)\\s+(table|from|into|where)"]
224+
158225
#####################################
159226
# Email-Based Authentication
160227
#####################################

0 commit comments

Comments
 (0)