Skip to main content

Spot vulnerabilities in postgres extension scripts

Project description

pgspot

Actions Status License: PostgreSQL PyPI Downloads Code style: black

Spot vulnerabilities in PostgreSQL extension scripts.

pgspot checks extension scripts for following PostgreSQL security best practices. In addition to checking extension scripts it can also be used to check security definer functions or any other PostgreSQL SQL code.

pgspot checks for the following vulnerabilities:

  • search_path-based attacks
  • unsafe object creation

Consult the reference for detailed documentation of the vulnerabilities which pgspot detects, and their potential mitigations.

Useful links

Installation

pip install pgspot

Requirements

To install the runtime requirements, use pip install -r requirements.txt.

Usage

> pgspot -h
usage: pgspot [-h] [-a] [--proc-without-search-path PROC] [--summary-only] [--plpgsql | --no-plpgsql] [--explain EXPLAIN] [--ignore IGNORE] [--sql-accepting SQL_FN] [FILE ...]

Spot vulnerabilities in PostgreSQL SQL scripts

positional arguments:
  FILE                  file to check for vulnerabilities

options:
  -h, --help            show this help message and exit
  -a, --append          append files before checking
  --proc-without-search-path PROC
                        whitelist functions without explicit search_path
  --summary-only        only print number of errors, warnings and unknowns
  --plpgsql, --no-plpgsql
                        Analyze PLpgSQL code (default: True)
  --explain EXPLAIN     Describe an error/warning code
  --ignore IGNORE       Ignore error or warning code
  --ignore-lang LANG    Ignore unknown procedural language
  --sql-accepting SQL_FN
                        Specify one or more sql-accepting functions
> pgspot --ignore PS017 <<<"CREATE TABLE IF NOT EXISTS foo();"
PS012: Unsafe table creation: foo

Errors: 1 Warnings: 0 Unknown: 0

SQL-accepting functions

It is a common pattern that SQL-accepting functions exist, which take a string-like argument which will be executed as SQL. This can "hide" some SQL from pgspot, as the string-like argument masks the SQL. With the --sql-accepting argument, pgspot can be told about such functions.

Assuming a function named execute_sql which takes a SQL string as its first argument, and executes it. With pgspot --sql-accepting=execute_sql we can tell pgspot execute_sql may accept SQL. pgspot will attempt to unpack and evaluate all arguments to that function as SQL.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgspot-0.9.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

pgspot-0.9.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file pgspot-0.9.1.tar.gz.

File metadata

  • Download URL: pgspot-0.9.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pgspot-0.9.1.tar.gz
Algorithm Hash digest
SHA256 bd6d34adee7fc7409e61b43c8cecb737d76f74629cd4d729a6e61b88d984c019
MD5 25de5ab1b0d30797b3768ed78607b84c
BLAKE2b-256 3a214acabdae0f61cb544020ead6338db29b01f9f4aa227f7ef242ba3b46f08a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgspot-0.9.1.tar.gz:

Publisher: publish.yml on timescale/pgspot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pgspot-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: pgspot-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pgspot-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45506837e9d6c3861ea59af9d3a79863925f780136c37d104de56d06f7c11812
MD5 11aadc665279c3d93c1a04c8a5af82f4
BLAKE2b-256 0b68e953904e2700ea6beb1fa3c059baf7c674add8526fea57461159079fa3bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgspot-0.9.1-py3-none-any.whl:

Publisher: publish.yml on timescale/pgspot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page