Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› COPY FROM PROGRAM
Cyber Security

COPY FROM PROGRAM

← Back to Glossary
By NHI Mgmt Group Updated September 25, 2026 Domain: Cyber Security

COPY FROM PROGRAM is a PostgreSQL capability that reads from a shell command and imports the command output into the database. In the wrong hands, it becomes a host command execution path, turning database access into operating system access. That makes it a high-value control boundary for detection and hardening.

What COPY FROM PROGRAM Does in PostgreSQL

COPY FROM PROGRAM is a PostgreSQL import path that executes a shell command and ingests its output. It is powerful because it bridges database operations and host-level execution, so a database action can become an operating-system action.

That bridge is useful for automation and data movement, but it also means the feature sits on a sharp trust boundary. If an attacker can influence the command, the surrounding environment, or the database role that can invoke it, the result can extend well beyond ordinary SQL access.

Why It Is a High-Risk Boundary

The core security concern is not the import itself, but the fact that the database server becomes the execution context for a host command. That makes the feature attractive wherever local command execution, filesystem access, or data staging can be turned into privilege expansion or lateral movement.

In practice, the risk grows when teams treat the capability like a normal bulk-load utility instead of a privileged operating-system interface. The more broadly it is available, the harder it becomes to reason about what code can run, what data can be read, and what the database host can reach.

Common Failure Conditions

Misuse usually appears in a few predictable ways: overly broad database privileges, hidden operational scripts, command strings assembled from untrusted input, and weak separation between administrative and application workflows. Any of these can turn a convenience feature into a command execution path.

Another failure mode is assuming that SQL review alone is sufficient. With COPY FROM PROGRAM, the security review also has to cover shell behavior, path resolution, environment inheritance, and the permissions of the database service account on the underlying host.

What Makes It Different From Ordinary COPY

Standard COPY moves data between PostgreSQL and files or client streams, while COPY FROM PROGRAM adds an execution step that changes the trust model. That extra step is what makes the feature materially more sensitive than a plain import command.

Because the command runs on the server side, defenders need to think in terms of host hardening, logging, and least privilege, not just database syntax. For background on the database-side control envelope, NIST Cybersecurity Framework 2.0 and NIST Privacy Framework both reinforce the need to govern sensitive processing paths and monitor high-impact operations.

Risk and Threat Considerations

When COPY FROM PROGRAM is exposed to an attacker or a careless administrator, it can become a command execution primitive on the PostgreSQL host. That creates a direct path from database compromise to host compromise, especially where the database service runs with meaningful local file or network reach.

Failure mechanism: The attacker abuses the server-side command execution path to run an unexpected shell command, read or stage data, or pivot into resources that the database host can access.

Impact: The result can include sensitive data exposure, unauthorized host activity, persistence opportunities, and a much larger blast radius than a SQL-only weakness would create.

Standards & Framework Alignment

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

MITRE ATT&CK addresses the attack surface, NIST SP 800-53 Rev 5, CIS Controls v8 and OWASP ASVS set the technical controls, and ISO/IEC 27001:2022 defines the regulatory obligations.

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5SI-4 — System MonitoringCOPY FROM PROGRAM needs monitoring for unexpected command execution and host-side abuse.
AC-6 — Least PrivilegeOnly tightly scoped roles should be able to invoke a database feature that executes host commands.
AU-12 — Audit Record GenerationServer-side command execution should generate audit evidence for review and forensics.
Recommendation — Monitor server-side command activity and alert on anomalous PostgreSQL execution paths. Restrict invocation to the smallest set of trusted roles and administrative workflows. Enable audit records for COPY FROM PROGRAM usage and review them for unexpected commands.
CIS Controls v8CIS-6 — Access Control ManagementThe feature's risk is driven by who can use it and how tightly that access is governed.
CIS-8 — Audit Log ManagementCOPY FROM PROGRAM abuse is detectable only if command activity is logged and retained.
CIS-4 — Secure Configuration of Enterprise Assets and SoftwareThe feature should be governed as a hardened configuration choice on the database host.
Recommendation — Limit and review access to database roles that can execute host commands. Collect and retain logs that reveal server-side command execution and review them regularly. Harden PostgreSQL deployments so server-side command execution is disabled or tightly controlled.
ISO/IEC 27001:2022A.8.9 — Configuration managementThis capability is a configuration-sensitive control boundary that must be governed deliberately.
Recommendation — Document and control database configurations that permit server-side command execution.
OWASP ASVSV15 — Secure Coding and ArchitectureThe feature changes the trust boundary between application logic, database access, and host execution.
V13 — ConfigurationA server-side execution feature requires secure deployment and configuration decisions.
Recommendation — Design applications so they do not depend on database features that execute host commands. Validate that database configurations do not expose unnecessary command-execution capability.
MITRE ATT&CKT1059 — Command and Scripting InterpreterCOPY FROM PROGRAM is a command execution path that adversaries may abuse to run host commands.
Recommendation — Map suspicious database command execution to T1059 and hunt for interpreter abuse on the host.

Practitioner Guidance

Why practitioners should care: Treat this feature as a privileged boundary, not a convenience import mechanism. If it is needed at all, its use should be rare, explicit, and tightly governed because the security consequence is host-level reach from a database session.

What to watch for: Audit where it is enabled, who can invoke it, and whether any operational job depends on it for routine data movement. If the feature is in active use, pair database controls with host hardening and command-level logging so misuse is visible rather than silent.

Deepen Your Knowledge

Sign up to our weekly newsletter — get 33% off our NHI Foundation Level Course

    NHIMG Editorial Note
    Reviewed and updated by the NHIMG editorial team on September 25, 2026.
    NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org