Server Side Include

ID

server_side_include

Severity

critical

Kind

Server-Side Include Injection

CWE

97

Description

Server-Side Include (SSI) Injection occurs when an attacker injects SSI directives into input fields, HTTP headers, or cookies that are embedded into web pages processed by the server. SSI directives are special instructions (such as <!--#exec cmd="…​" -→ or <!--#include virtual="…​" -→) that the web server parses and executes before serving the page to the user. When user-supplied data is incorporated into a response without proper validation, attackers can leverage these directives to read sensitive files, access server environment variables, or execute arbitrary system commands on the host.

Rationale

A successful SSI injection can lead to Remote Code Execution (RCE), allowing the attacker to run operating system commands under the privileges of the web server process, read arbitrary files such as /etc/passwd or application configuration files, and enumerate internal server details through CGI environment variables. Exploitation is straightforward because SSI directive syntax is simple and well-documented; any input vector reflected into an .shtml page or a server configured to parse all HTML for SSI directives becomes a viable attack surface, including form fields, query parameters, HTTP headers, and cookie values. This makes SSI injection particularly dangerous in environments where the exec directive has not been explicitly disabled, as a single unsanitized input can grant full control over the server.

Remediation

Do not trust client-side input. Validate and sanitize all user-supplied data on the server side, stripping or encoding SSI directive characters (<, >, !, #, -) before the input is embedded into any page that the web server may parse for includes.

Disable Server-Side Includes entirely if your application does not require them. For Apache HTTP Server, remove Includes from the Options directive and remove handlers that associate file extensions with SSI processing (for example, AddType text/x-server-parsed-html .html). Consult your web server documentation for the specific configuration needed.

If SSI functionality is required, restrict it to the minimum necessary. In Apache, use IncludesNOEXEC instead of Includes to allow file includes while disabling the dangerous exec directive that permits arbitrary command execution.

Run the web server process with least-privilege permissions so that, even if SSI injection is exploited, the impact of command execution and file access is limited to the minimal set of resources the server needs to operate.

References