During a routine incident investigation, a security analyst reviews web application gateway logs for a custom automated reporting microservice. The logs contain consecutive HTTP POST requests targeting the endpoint `/api/v1/generate-report` with the body payload `template_header={{7*7}}`, which returned a `200 OK` status with `49` rendered in the response preview. Subsequent log entries show the payload modified to `template_header={{self.__init__.__globals__['__builtins__']['__import__']('os').popen('id').read()}}`, which returned operating system user identity context. Which of the following vulnerabilities is present in the application, and what is the primary mitigation strategy to prevent exploitation?
- Server-Side Template Injection (SSTI); enforce strict context-aware input sanitization, separate user data from template logic, and utilize sandboxed execution environments.Answer
- BSQL Injection (SQLi); replace dynamic inline database queries with parameterized prepared statements and stored procedures.
- CReflected Cross-Site Scripting (XSS); implement client-side HTML entity encoding and configure restrictive Content Security Policy (CSP) headers.
- DBroken Object Level Authorization (BOLA); implement role-based access control lists and enforce server-side session authentication checks on API endpoints.
Answer
The application is vulnerable to Server-Side Template Injection (SSTI). The primary mitigation is to enforce strict input sanitization, separate user input from template logic, and execute template processing within a sandboxed environment.
The option identifying Server-Side Template Injection (SSTI) correctly diagnoses the vulnerability. SSTI occurs when an application embeds unvalidated user input directly into a server-side template string prior to rendering. The initial probe (`{{7*7}}` evaluating to `49`) proves that template syntax is being evaluated on the server, while the follow-up payload uses object reflection to invoke system commands (`os.popen`), leading to remote code execution. Safe implementation requires separating user data from template layout, sanitizing inputs, and utilizing sandboxed rendering engines.
Step-by-Step Solution
Key Concept
Server-Side Template Injection (SSTI)