Server-Side Includes (SSI) Injection

User input is written into a page that the web server parses for Server-Side Include directives, so an attacker can inject directives that read files or run commands.

SeverityHigh
CVSS 3.18.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.09.2 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-97: Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
OWASP Top 10A05:2025 Injection
MITRE ATT&CKT1190 Exploit Public-Facing Application, T1059 Command and Scripting Interpreter
CategoryInjection

Description

Server-Side Includes (SSI) are directives written as HTML comments, such as <!--#include virtual="..." -->, that a web server processes before it sends a page. SSI injection occurs when the application places user input into content that the server then parses for these directives: a file written from user input into a directory where SSI processing is enabled, or dynamic output passed through the server's SSI filter. Because the input is not HTML-encoded, a directive within it is carried out by the server.

Whether the #exec directive, which runs operating system commands, is available depends on the server: Apache permits it under Options Includes but not under IncludesNOEXEC, and the nginx SSI module does not support it at all. Where it is available, an attacker can run operating system commands with the privileges of the web server, which amounts to a full compromise of the application host. Otherwise they can typically disclose server environment variables and the content of files and scripts reachable through include directives, and alter pages served to other users. No user interaction is needed.

The weakness typically shows itself on a test when a directive such as <!--#echo var="DATE_LOCAL" --> submitted in a parameter is replaced in the response by the server's date, or when an include directive returns the content of another file. Burp Suite and OWASP ZAP both test for SSI injection.

Remediation

Stop user input from reaching content that is parsed for directives, and remove the ability to run commands:

  • Disable SSI processing wherever it is not needed, by removing the Includes option and any SSI handlers or filters in Apache, or by leaving ssi off in nginx.
  • Where SSI is required, use IncludesNOEXEC in Apache so that commands cannot be run, and limit SSI processing to static files that contain no user input.
  • HTML-encode user input before it is written into any page, so that it cannot form a directive, and never write user input into files stored where SSI is processed.
  • Do not pass dynamic application output through the server's SSI filter.
# Apache: no SSI by default <Directory "/var/www/html"> Options -Includes </Directory> # only where SSI is required, without exec <Directory "/var/www/html/ssi"> Options IncludesNOEXEC </Directory>

As an interim measure, a web application firewall rule can block <!--# in request parameters. Confirm the fix by repeating the original directives and checking that they are returned as encoded text and are not processed.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding