Skip to main content

Spot vulnerabilities in postgres extension scripts

Project description

pgspot

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 -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
  --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.3.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgspot-0.3.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pgspot-0.3.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pgspot-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7146637faa7f138247eb20c1b50be020497c299a3c20f7a7c13b9a55d70c128d
MD5 8ba5b4141b5f2f0fc79c9e63e514c6d3
BLAKE2b-256 5e4c9ae4594d73638e9c8fe3e761eb0431bffec9e749b65fc6b18236e6470db5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pgspot-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pgspot-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6382cc10e415b3690a571c5acb3fc80d45a77587cb2592ea964dbabefc570c72
MD5 3780ae8bc18a51a33e71928da8a1820d
BLAKE2b-256 b90d3c611e8c8d65abee3dc4513132bc7ae87e2f580c6099c2c081b73109d749

See more details on using hashes here.

Supported by

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