Courses

PostgreSQL Large Objects
OSWE · Chapter 18

PostgreSQL Large Objects

PostgreSQL Large Objects provide a stream-oriented storage mechanism for data too large to handle as a normal column value. Because they are accessed via a distinct API (`lo_import`/`lo_export` and related functions), they have their own set of privilege and file-access considerations relevant to security testing.

Key concepts

  • Large objects are referenced by an OID and accessed through a streaming API rather than being embedded directly in a table row, unlike `bytea`.
  • `lo_export`/`lo_import` functions can read from or write to the server's local filesystem — if reachable by a low-privileged database role, this becomes a path to arbitrary file read/write.
  • Historically, misconfigured large object privileges have been used to write malicious files (e.g. web shells) to a location the web server executes from.
  • Hardening: restrict `lo_import`/`lo_export` execution to trusted roles, and ensure the database service account has no write access to web-servable directories.

Example

-- Reading server-local file content into a large object (requires appropriate privileges)
SELECT lo_import('/etc/passwd');

Try it yourself

Read the PostgreSQL Large Objects chapter and explain, in your own words, why `lo_export`/`lo_import` are more dangerous from a security perspective than a normal `bytea` column.

@ Daniel Burlacu