pg_headerkit
pg_headerkit · PostgreSQL SQL functions for reading PostgREST request headers inside database code
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101062 | pg_headerkit | pg_headerkit | 1.0 | UTIL | ISC | SQL |
Usage
Sources:
pg_headerkit version 1.0 is a pure-SQL PostgREST header helper. It creates the fixed hdr schema, allow-list and deny-list tables, and functions for reading the request.headers setting, extracting proxy and client fields, testing IP lists, and recognizing simple mobile user-agent patterns.
Intended use after correction
The following illustrates the intended API, but the pinned 1.0 installation script must be corrected before this sequence can run successfully:
The functions only expose request context supplied by PostgREST or another trusted gateway. They do not themselves enforce rate limits, routing, request filtering, or authorization; applications must call them from policies or functions that implement those decisions.
Current defects and security
At the reviewed commit, each of the hdr.projectref and hdr.ref function bodies contains two adjacent SELECT statements without a separator. Consequently, the distributed version 1.0 SQL has a syntax error and CREATE EXTENSION pg_headerkit fails atomically. Patch and review the installation SQL or wait for an upstream correction before packaging it.
Several functions that read request settings or allow/deny tables are incorrectly declared immutable. PostgreSQL may pre-evaluate or cache such results, so they must use appropriate volatility before they are trusted for security decisions. The IP helper trusts the first x-forwarded-for value; accept it only when a controlled reverse proxy overwrites that header. Design explicit schema, table, and function privileges, because the upstream SQL supplies no complete role model and its functions run with invoker rights.
The README lists rate limiting and access-control capabilities as uses that can be built with the helpers, not installed enforcement. Audit corrected SQL, revoke unneeded public execution, and test every policy through the actual PostgREST role and connection-pooling mode.