Skip to content

Commit cbb9a64

Browse files
authored
Merge pull request #15457 from RasmusWL/psycopg
Python: Model the `psycopg` package
2 parents 3d9f9af + 5867fb3 commit cbb9a64

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added modeling of the `psycopg` PyPI package as a SQL database library.

python/ql/lib/semmle/python/Frameworks.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private import semmle.python.frameworks.Oracledb
4848
private import semmle.python.frameworks.Pandas
4949
private import semmle.python.frameworks.Peewee
5050
private import semmle.python.frameworks.Phoenixdb
51+
private import semmle.python.frameworks.Psycopg
5152
private import semmle.python.frameworks.Psycopg2
5253
private import semmle.python.frameworks.Pycurl
5354
private import semmle.python.frameworks.Pydantic
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `psycopg` PyPI package.
3+
* See
4+
* - https://www.psycopg.org/psycopg3/docs/
5+
* - https://pypi.org/project/psycopg/
6+
*/
7+
8+
private import python
9+
private import semmle.python.dataflow.new.DataFlow
10+
private import semmle.python.dataflow.new.RemoteFlowSources
11+
private import semmle.python.Concepts
12+
private import semmle.python.ApiGraphs
13+
private import semmle.python.frameworks.PEP249
14+
15+
/**
16+
* Provides models for the `psycopg` PyPI package.
17+
* See
18+
* - https://www.psycopg.org/psycopg3/docs/
19+
* - https://pypi.org/project/psycopg/
20+
*/
21+
private module Psycopg {
22+
// ---------------------------------------------------------------------------
23+
// Psycopg
24+
// ---------------------------------------------------------------------------
25+
/**
26+
* A model of `psycopg` as a module that implements PEP 249, providing ways to execute SQL statements
27+
* against a database.
28+
*/
29+
class Psycopg extends PEP249::PEP249ModuleApiNode {
30+
Psycopg() { this = API::moduleImport("psycopg") }
31+
}
32+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import psycopg
2+
3+
conn = psycopg.connect(...)
4+
conn.execute("some sql", (42,)) # $ getSql="some sql"
5+
cursor = conn.cursor()
6+
cursor.execute("some sql", (42,)) # $ getSql="some sql"
7+
cursor.executemany("some sql", [(42,)]) # $ getSql="some sql"
8+
9+
# as in their examples:
10+
with psycopg.connect(...) as conn:
11+
conn.execute("some sql", (42,)) # $ getSql="some sql"
12+
with conn.cursor() as cursor:
13+
cursor.execute("some sql", (42,)) # $ getSql="some sql"
14+
cursor.executemany("some sql", [(42,)]) # $ getSql="some sql"

0 commit comments

Comments
 (0)