Python: Model the psycopg package

This commit is contained in:
Rasmus Wriedt Larsen
2024-01-29 12:10:46 +01:00
parent 49d6d3fa0c
commit 3f0dc2b022
5 changed files with 51 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ private import semmle.python.frameworks.Oracledb
private import semmle.python.frameworks.Pandas
private import semmle.python.frameworks.Peewee
private import semmle.python.frameworks.Phoenixdb
private import semmle.python.frameworks.Psycopg
private import semmle.python.frameworks.Psycopg2
private import semmle.python.frameworks.Pycurl
private import semmle.python.frameworks.Pydantic

View File

@@ -0,0 +1,32 @@
/**
* Provides classes modeling security-relevant aspects of the `psycopg` PyPI package.
* See
* - https://www.psycopg.org/psycopg3/docs/
* - https://pypi.org/project/psycopg/
*/
private import python
private import semmle.python.dataflow.new.DataFlow
private import semmle.python.dataflow.new.RemoteFlowSources
private import semmle.python.Concepts
private import semmle.python.ApiGraphs
private import semmle.python.frameworks.PEP249
/**
* Provides models for the `psycopg` PyPI package.
* See
* - https://www.psycopg.org/psycopg3/docs/
* - https://pypi.org/project/psycopg/
*/
private module Psycopg {
// ---------------------------------------------------------------------------
// Psycopg
// ---------------------------------------------------------------------------
/**
* A model of `psycopg` as a module that implements PEP 249, providing ways to execute SQL statements
* against a database.
*/
class Psycopg extends PEP249::PEP249ModuleApiNode {
Psycopg() { this = API::moduleImport("psycopg") }
}
}

View File

@@ -0,0 +1,2 @@
testFailures
failures

View File

@@ -0,0 +1,2 @@
import python
import experimental.meta.ConceptsTest

View File

@@ -0,0 +1,14 @@
import psycopg
conn = psycopg.connect(...)
conn.execute("some sql", (42,)) # $ getSql="some sql"
cursor = conn.cursor()
cursor.execute("some sql", (42,)) # $ getSql="some sql"
cursor.executemany("some sql", [(42,)]) # $ getSql="some sql"
# as in their examples:
with psycopg.connect(...) as conn:
conn.execute("some sql", (42,)) # $ getSql="some sql"
with conn.cursor() as cursor:
cursor.execute("some sql", (42,)) # $ getSql="some sql"
cursor.executemany("some sql", [(42,)]) # $ getSql="some sql"