What Is Server-Side Includes (SSI) Injection? How to Prevent It
Server-Side Includes (SSI) are simple directives that a web server processes inside HTML pages, usually.shtml files, to insert a shared header, a date or a file. SSI injection happens when an application writes user input into a page that the server later parses for SSI directives.
Topic: Web & API Security in Cybersecurity & Ethical Hacking · Explainer
Also covers: Ethical Hacking, Cybersecurity Careers & Certifications, Data Analytics & Data Science
Quick answer: Server-Side Includes (SSI) are simple directives that a web server processes inside HTML pages, usually .shtml files, to insert a shared header, a date or a file. SSI injection happens when an application writes user input into a page that the server later parses for SSI directives. The server then treats that input as an instruction, which can leak files or, if the exec feature is enabled, run operating system commands. It is not a type of SQL injection, although both belong to the same injection family (CWE-97 for SSI). Prevent it by disabling SSI where unused, turning off exec, and never storing raw user input in SSI-parsed files.
Key takeaways
- SSI is processed by the web server, not by the database.
- Injection needs two things: SSI parsing enabled and user input written into parsed pages.
- The exec directive turns SSI injection into command execution.
- Apache IncludesNOEXEC and disabling SSI remove most of the risk.
- Encoding output and validating input apply to every injection type.
Table of Contents
- What Are Server-Side Includes?
- How Does SSI Injection Happen?
- What Is the Impact of SSI Injection?
- How Is SSI Injection Different From SQL Injection?
- How Can You Detect SSI Injection Risk?
- How Do You Prevent SSI Injection?
- What Does Safe and Unsafe Design Look Like?
- References
What Are Server-Side Includes?
SSI dates from the early web, before full server-side languages were common. A page contains special HTML-comment-style directives. When the server delivers the page, a module such as Apache mod_include replaces each directive with its output: the contents of another file, an environment variable, the last-modified date or, with exec, the output of a command. Nginx has its own ssi module. Many legacy intranet sites, routers and embedded web panels still use SSI.
How Does SSI Injection Happen?
The OWASP SSI injection page describes the flaw: an application takes input such as a comment, user name or log entry and places it, unencoded, into a file or response that the server later parses for directives. If the attacker supplies text shaped like a directive, the server executes it. A common pattern is a guestbook or error page saved as .shtml. MITRE tracks the weakness as CWE-97 and the attack pattern as CAPEC-101.
What Is the Impact of SSI Injection?
| Server setting | Possible impact |
|---|---|
| SSI with exec enabled | Operating system command execution as the web server user |
| SSI with include only | Disclosure of files inside the web root, configuration leaks |
| SSI echo of variables | Leak of server paths, software versions, environment data |
| SSI disabled | No SSI impact; input may still cause XSS if not encoded |
How Is SSI Injection Different From SQL Injection?
The original version of this article grouped SSI with SQL attacks. They are siblings, not the same thing.
| Injection type | Interpreter | Main fix |
|---|---|---|
| SSI injection | Web server SSI module | Disable SSI or exec; encode output |
| SQL injection | Database engine | Parameterised queries |
| Command injection | Operating system shell | Avoid shell; use safe APIs |
| Cross-site scripting | User's browser | Context-aware output encoding |
| Template injection | Server template engine | Never build templates from input |
The OWASP SQL Injection Prevention Cheat Sheet covers the database side; our SQL injection explainer walks through it for beginners.
How Can You Detect SSI Injection Risk?
- Find pages with .shtml, .stm or .shtm extensions and server configs that enable Includes.
- Review code for any path where user input is written into files the server parses.
- Follow OWASP WSTG-INPV-08 during authorised tests.
- Watch web logs for directive-like strings in parameters and alert on them.
On a Linux server you manage, check whether SSI is active:
apachectl -M | grep include
grep -RniE 'Includes|AddOutputFilter.*INCLUDES' /etc/apache2/ /etc/httpd/ 2>/dev/null
grep -Rni 'ssi on' /etc/nginx/ 2>/dev/null
How Do You Prevent SSI Injection?
- Disable mod_include or the Nginx ssi directive if no page needs SSI.
- Where SSI is required, use Apache
Options IncludesNOEXECso exec is unavailable. - Limit SSI to specific trusted directories, never upload or user-content folders.
- Encode user input for HTML before output, as the OWASP Injection Prevention Cheat Sheet advises.
- Validate input against allow lists of expected characters.
- Run the web server as a low-privilege account.
What Does Safe and Unsafe Design Look Like?
| Unsafe | Safe |
|---|---|
| Saving visitor comments directly into an .shtml page | Storing comments in a database and rendering them with an encoding template engine |
| Global Options +Includes on the whole site | IncludesNOEXEC on one static directory only |
| Raw error messages echoed into parsed pages | Generic error pages with no user input |
Testing for SSI injection on sites you do not own breaks Sections 43 and 66 of the IT Act 2000; get written authorisation first. See the OWASP Top 10 guide for the wider injection category, and join WebAsha web application security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0