pgspot


Namepgspot JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/timescale/pgspot
SummarySpot vulnerabilities in postgres extension scripts
upload_time2025-01-06 19:06:10
maintainerNone
docs_urlNone
authorTimescale, Inc.
requires_python>=3.10
licenseThe PostgreSQL License
keywords postgresql
VCS
bugtrack_url
requirements pglast
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## pgspot
<p align="center">
  <a href="https://github.com/timescale/pgspot/actions"><img alt="Actions Status" src="https://github.com/timescale/pgspot/workflows/Test/badge.svg"></a>
  <a href="https://github.com/timescale/pgspot/blob/main/LICENSE"><img alt="License: PostgreSQL" src="https://img.shields.io/github/license/timescale/pgspot"></a>
  <a href="https://pypi.org/project/pgspot/"><img alt="PyPI" src="https://img.shields.io/pypi/v/pgspot"></a>
  <a href="https://pepy.tech/project/pgspot"><img alt="Downloads" src="https://pepy.tech/badge/pgspot"></a>
  <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
  <a href="https://www.bestpractices.dev/projects/8009"><img src="https://www.bestpractices.dev/projects/8009/badge"></a>
</p>

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.

[reference]: https://github.com/timescale/pgspot/blob/main/REFERENCE.md

## Useful links
- [PostgreSQL security recommendations for extensions](https://www.postgresql.org/docs/current/extend-extensions.html#EXTEND-EXTENSIONS-SECURITY)
- [PostgreSQL security recommendations for SECURITY DEFINER functions](https://www.postgresql.org/docs/current/sql-createfunction.html#SQL-CREATEFUNCTION-SECURITY)

## Installation

pip install pgspot

## Requirements

- python >= 3.10
- [pglast](https://github.com/lelit/pglast)
- [libpg_query](https://github.com/pganalyze/libpg_query) (through pglast)

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/timescale/pgspot",
    "name": "pgspot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "postgresql",
    "author": "Timescale, Inc.",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b2/61/144d1b1c666b5dece51c20de14ce811bbed7c5e12a73581c9f5c409ccf84/pgspot-0.9.0.tar.gz",
    "platform": null,
    "description": "## pgspot\n<p align=\"center\">\n  <a href=\"https://github.com/timescale/pgspot/actions\"><img alt=\"Actions Status\" src=\"https://github.com/timescale/pgspot/workflows/Test/badge.svg\"></a>\n  <a href=\"https://github.com/timescale/pgspot/blob/main/LICENSE\"><img alt=\"License: PostgreSQL\" src=\"https://img.shields.io/github/license/timescale/pgspot\"></a>\n  <a href=\"https://pypi.org/project/pgspot/\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/pgspot\"></a>\n  <a href=\"https://pepy.tech/project/pgspot\"><img alt=\"Downloads\" src=\"https://pepy.tech/badge/pgspot\"></a>\n  <a href=\"https://github.com/psf/black\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>\n  <a href=\"https://www.bestpractices.dev/projects/8009\"><img src=\"https://www.bestpractices.dev/projects/8009/badge\"></a>\n</p>\n\nSpot vulnerabilities in PostgreSQL extension scripts.\n\npgspot checks extension scripts for following PostgreSQL security best\npractices. In addition to checking extension scripts it can also be\nused to check security definer functions or any other PostgreSQL SQL code.\n\npgspot checks for the following vulnerabilities:\n- search_path-based attacks\n- unsafe object creation\n\nConsult the [reference] for detailed documentation of the vulnerabilities which\npgspot detects, and their potential mitigations.\n\n[reference]: https://github.com/timescale/pgspot/blob/main/REFERENCE.md\n\n## Useful links\n- [PostgreSQL security recommendations for extensions](https://www.postgresql.org/docs/current/extend-extensions.html#EXTEND-EXTENSIONS-SECURITY)\n- [PostgreSQL security recommendations for SECURITY DEFINER functions](https://www.postgresql.org/docs/current/sql-createfunction.html#SQL-CREATEFUNCTION-SECURITY)\n\n## Installation\n\npip install pgspot\n\n## Requirements\n\n- python >= 3.10\n- [pglast](https://github.com/lelit/pglast)\n- [libpg_query](https://github.com/pganalyze/libpg_query) (through pglast)\n\nTo install the runtime requirements, use `pip install -r requirements.txt`.\n\n\n### Usage\n\n```\n> pgspot -h\nusage: pgspot [-h] [-a] [--proc-without-search-path PROC] [--summary-only] [--plpgsql | --no-plpgsql] [--explain EXPLAIN] [--ignore IGNORE] [--sql-accepting SQL_FN] [FILE ...]\n\nSpot vulnerabilities in PostgreSQL SQL scripts\n\npositional arguments:\n  FILE                  file to check for vulnerabilities\n\noptions:\n  -h, --help            show this help message and exit\n  -a, --append          append files before checking\n  --proc-without-search-path PROC\n                        whitelist functions without explicit search_path\n  --summary-only        only print number of errors, warnings and unknowns\n  --plpgsql, --no-plpgsql\n                        Analyze PLpgSQL code (default: True)\n  --explain EXPLAIN     Describe an error/warning code\n  --ignore IGNORE       Ignore error or warning code\n  --ignore-lang LANG    Ignore unknown procedural language\n  --sql-accepting SQL_FN\n                        Specify one or more sql-accepting functions\n```\n\n```\n> pgspot --ignore PS017 <<<\"CREATE TABLE IF NOT EXISTS foo();\"\nPS012: Unsafe table creation: foo\n\nErrors: 1 Warnings: 0 Unknown: 0\n```\n\n#### SQL-accepting functions\n\nIt is a common pattern that SQL-accepting functions exist, which take a\nstring-like argument which will be executed as SQL. This can \"hide\" some SQL\nfrom pgspot, as the string-like argument masks the SQL. With the\n`--sql-accepting` argument, pgspot can be told about such functions.\n\nAssuming a function named `execute_sql` which takes a SQL string as its first\nargument, and executes it. With `pgspot --sql-accepting=execute_sql` we can\ntell pgspot `execute_sql` may accept SQL. pgspot will attempt to unpack and\nevaluate all arguments to that function as SQL.\n",
    "bugtrack_url": null,
    "license": "The PostgreSQL License",
    "summary": "Spot vulnerabilities in postgres extension scripts",
    "version": "0.9.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/timescale/pgspot/issues",
        "Homepage": "https://github.com/timescale/pgspot"
    },
    "split_keywords": [
        "postgresql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "301bd28c2b1aceba788875b9ae4c427a6aba107ada9b8574007393ef37c76c92",
                "md5": "53cecc30375862037c037e9ec42088b1",
                "sha256": "3271c6157d0e52989d8034cd2bee17d1ac3828cc6abd3983ab0c2f47c829c95c"
            },
            "downloads": -1,
            "filename": "pgspot-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "53cecc30375862037c037e9ec42088b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 18525,
            "upload_time": "2025-01-06T19:06:09",
            "upload_time_iso_8601": "2025-01-06T19:06:09.018409Z",
            "url": "https://files.pythonhosted.org/packages/30/1b/d28c2b1aceba788875b9ae4c427a6aba107ada9b8574007393ef37c76c92/pgspot-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b261144d1b1c666b5dece51c20de14ce811bbed7c5e12a73581c9f5c409ccf84",
                "md5": "5835656bf9f5e549ab59f2df5f2d94be",
                "sha256": "419e5b6a88de47fd778ae7439d7f943ef1e1b0ad56c2625ce672abe1ad30b797"
            },
            "downloads": -1,
            "filename": "pgspot-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5835656bf9f5e549ab59f2df5f2d94be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 17602,
            "upload_time": "2025-01-06T19:06:10",
            "upload_time_iso_8601": "2025-01-06T19:06:10.398577Z",
            "url": "https://files.pythonhosted.org/packages/b2/61/144d1b1c666b5dece51c20de14ce811bbed7c5e12a73581c9f5c409ccf84/pgspot-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-06 19:06:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "timescale",
    "github_project": "pgspot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pglast",
            "specs": [
                [
                    "==",
                    "7.2"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "pgspot"
}
        
Elapsed time: 1.11968s