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.

May 26, 2025 - 11:43
Updated: 
102k

Web & API Security in Cybersecurity & Ethical Hacking · Explainer

Ethical Hacking, Cybersecurity Careers & Certifications, Data Analytics & Data Science

What Is Server-Side Includes (SSI) Injection? How to Prevent It

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?

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 settingPossible impact
SSI with exec enabledOperating system command execution as the web server user
SSI with include onlyDisclosure of files inside the web root, configuration leaks
SSI echo of variablesLeak of server paths, software versions, environment data
SSI disabledNo 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 typeInterpreterMain fix
SSI injectionWeb server SSI moduleDisable SSI or exec; encode output
SQL injectionDatabase engineParameterised queries
Command injectionOperating system shellAvoid shell; use safe APIs
Cross-site scriptingUser's browserContext-aware output encoding
Template injectionServer template engineNever 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?

  1. Disable mod_include or the Nginx ssi directive if no page needs SSI.
  2. Where SSI is required, use Apache Options IncludesNOEXEC so exec is unavailable.
  3. Limit SSI to specific trusted directories, never upload or user-content folders.
  4. Encode user input for HTML before output, as the OWASP Injection Prevention Cheat Sheet advises.
  5. Validate input against allow lists of expected characters.
  6. Run the web server as a low-privilege account.

What Does Safe and Unsafe Design Look Like?

UnsafeSafe
Saving visitor comments directly into an .shtml pageStoring comments in a database and rendering them with an encoding template engine
Global Options +Includes on the whole siteIncludesNOEXEC on one static directory only
Raw error messages echoed into parsed pagesGeneric 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

It is a flaw where user input placed into a page parsed for SSI directives is executed by the web server as an instruction.

No. SSI injection targets the web server’s SSI module, while SQL injection targets the database. Both belong to the wider injection family.

Depending on configuration, they can read files in the web root, leak server variables or run operating system commands if exec is enabled.

MITRE CWE-97 covers improper neutralisation of server-side includes within a web page, and CAPEC-101 describes the attack pattern.

Use Options IncludesNOEXEC instead of Includes for directories that need SSI, which keeps file includes but blocks command execution.

Yes, mainly on legacy sites, intranet pages and embedded device web panels, which is why old SSI configurations still appear in assessments.

Look for .shtml, .stm and .shtm files and search Apache or Nginx configuration for Includes, INCLUDES filters or ssi on settings.

HTML encoding user input before writing it into parsed pages neutralises directive characters, and should be combined with disabling unused SSI.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.