Join our Newsletter — 33% off our NHI Course

Common Gateway Interface

Common Gateway Interface is an older mechanism for running server-side scripts, including PHP, through a web server. It remains relevant mainly in legacy environments. Because it was not designed for modern threat conditions, CGI can expose systems to code execution and other weaknesses when it is still in use on internet-facing hosts.

Expanded Definition

Common Gateway Interface, or CGI, is a web server interface for passing requests to external programs that generate dynamic content. In practice, it is an older execution model: the web server starts a separate process for each request, passes environment data and request input to that process, then returns the output to the browser. That behaviour made CGI simple and portable, but also costly and less defensive than modern application runtimes.

CGI is not a scripting language, and it is not the same thing as PHP itself. PHP could be deployed through CGI, but the term describes the integration pattern, not the language. In legacy environments, the main boundary to watch is that CGI often sits close to the web root and executes code with whatever operating-system permissions the hosting configuration allows. For that reason, CGI is usually discussed today as a legacy compatibility mechanism rather than a preferred design choice. For general control context, NIST’s NIST SP 800-53 Rev 5 Security and Privacy Controls remains a useful reference for access control, logging, and configuration discipline around exposed web services.

Examples and Use Cases

CGI still appears in older hosting stacks, embedded appliances, and long-lived intranet applications where rewriting the application would be more disruptive than maintaining the interface. It also shows up when administrators need compatibility with historical scripts that were written for a simple request-to-process model.

  • A legacy website invokes a Perl or shell script through CGI to render a form submission.
  • An older PHP deployment uses CGI or FastCGI-style execution rather than a modern application server model.
  • A network appliance exposes a web admin page implemented with CGI scripts for status and configuration functions.
  • An internal business tool keeps CGI because the application is stable and isolated from public traffic.
  • A migration project retains CGI temporarily while replacing request handlers one subsystem at a time.

The main tradeoff is compatibility versus efficiency. CGI is easy to reason about, but per-request process creation can become expensive under load and can magnify the impact of weak script hygiene. Where CGI remains in use, the operational question is usually not whether it works, but whether the legacy design still matches the exposure of the host environment.

Security Implications

CGI becomes risky when administrators treat it as a harmless legacy feature instead of executable code behind a web boundary. Any script reachable through the server can become a code execution path if input handling, command invocation, filesystem permissions, or environment exposure are mismanaged. That is especially important on internet-facing hosts, where an attacker only needs one weak endpoint to turn a small scripting convenience into a full compromise.

Common failure conditions include unsafe string handling, calls to system utilities, reliance on writable directories, and overbroad permissions for the service account running the scripts. CGI can also widen the blast radius of a mistake because a compromised script may expose local files, configuration data, or credentials stored on the same host. One practical symptom is that the application looks static from the outside, yet the server still executes multiple external programs for ordinary requests.

Legacy CGI is therefore a good example of how older web mechanics can remain functional while drifting out of step with modern threat assumptions.

Domain and Governance Relevance

CGI matters most in web application security and legacy platform governance. The central governance question is whether an organisation still needs a request-to-process model that predates modern application isolation, logging, and secure deployment patterns. If the answer is yes, then CGI should be treated as an exception requiring explicit ownership rather than an invisible default inherited from an old host build.

Its relevance to identity and access is indirect but real: CGI scripts often execute with server-side privileges that determine what the web application can read, write, or invoke. That makes permission scope, file ownership, and runtime segregation more important than the scripting language itself. In managed environments, the term often signals a broader lifecycle problem: the server may be maintained, but the execution model has not been modernised to match current exposure.

For NHIMG readers, the practical takeaway is that CGI is usually a legacy web runtime issue first, and an identity or credential issue only when the script’s execution rights, file access, or downstream command execution materially change the trust boundary.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK address the attack and risk surface, while CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
CIS Controls v8 16 — Application Software Security CGI is executable web app code that must be hardened and validated.
3 — Data Protection CGI scripts often handle request data and local files that need protection.
8 — Audit Log Management Legacy CGI deployments need visibility into script execution and abuse.
Recommendation — Apply secure development and validation controls to CGI scripts before exposing them publicly. Restrict read/write access so CGI handlers cannot expose sensitive files or data. Log CGI invocations and review abnormal process execution or error patterns.
NIST CSF 2.0 PR.AC-4 — Access Permissions and Authorizations CGI risk increases when script execution rights are broader than needed.
PR.DS-1 — Data-at-Rest Protection CGI often touches configuration and local data that should not be exposed.
DE.CM-7 — Monitoring for Unauthorized Code Execution Unexpected CGI process launches can indicate exploitation or misuse.
Recommendation — Limit CGI runtime permissions to the minimum required to execute each script safely. Protect files and secrets that CGI-accessible processes can reach on the host. Monitor for unusual CGI execution paths and investigate abnormal server-side process activity.
MITRE ATT&CK T1505.003 — Server Software Component: Web Shell Compromised CGI endpoints can be used to establish web-based command execution.
T1059 — Command and Scripting Interpreter CGI frequently executes scripts or commands that attackers can abuse if input is unsafe.
Recommendation — Hunt for server-side script abuse that turns CGI exposure into a web shell foothold. Detect and constrain script and command execution paths reachable through CGI.