burggraf@pg_headerkit

v1.0.0Created 2 years agoBy burggraf

pg_headerkit: PostgREST Header Kit

A set of functions for adding special features to your application that use PostgREST API calls to your PostgreSQL database. These functions can be used inside PostgreSQL functions that can give your application the following capabilities at the database level:

  • rate limiting
  • IP allowlisting
  • IP denylisting
  • request logging
  • request filtering
  • request routing
  • user allowlisting by uid or email (Supabase-specific)
  • user denylisting by uid or email (Supabase-specific)

Article

See: PostgREST Header Hacking

Function Reference

functiondescriptionparametersreturns
hdr.headers()get all header values as a json objectnonejson object
hdr.header(item text)get a header valueitem (text)text
hdr.ip()get the ip address of the current usernonetext
hdr.allow_list()get the allow list of ip addressesnoneinet[] (array of ip addresses)
hdr.deny_list()get the deny list of ip addressesnoneinet[] (array of ip addresses)
hdr.in_deny_list(ip inet)determine if the given ip is in the deny listip (inet)boolean
hdr.in_allow_list(ip inet)determine if the given ip is in the allow listip (inet)boolean
hdr.in_deny_list()determine if the current user's ip is in the deny listnoneboolean
hdr.in_allow_list()determine if the current user's ip is in the allow listnoneboolean
hdr.host()get host, i.e. "localhost:3000"nonetext
hdr.origin()get origin, i.e. "http://localhost:8100"nonetext
hdr.referer()get referer, i.e. "http://localhost:8100/"nonetext
hdr.agent()get user-agent stringnonetext
hdr.client()get x-client-info, i.e. "supabase-js/1.35.7"nonetext
hdr.role()<br>hdr.consumer()get role (consumer), i.e. "anon-key"nonetext
hdr.api_host()<br>hdr.domain()get api server, i.e. "xxxxxxxxxxxxxxxx.supabase.co"nonetext
hdr.projectref()<br>hdr.ref()get project ref #, i.e. "xxxxxxxxxxxxxxxx"nonetext
hdr.is_mobile()is mobile?noneboolean
hdr.is_iphone()is iphone?noneboolean
hdr.is_ipad()is ipad?noneboolean
hdr.is_android()is android?noneboolean

Install

  1. Install the dbdev package manager
  2. Install the package:
select dbdev.install('burggraf@pg_headerkit');
create extension "burggraf@pg_headerkit"
    version '1.0.0';

Downloads

  • 183 all time downloads
  • 3 downloads in the last 30 days
  • 59 downloads in the last 90 days
  • 99 downloads in the last 180 days