Skip to content

Commit 4ee71ae

Browse files
committed
Python: Add support for pymssql package
I also forgot to mention `PyMySQL` in frameworks.rst
1 parent b1d33a4 commit 4ee71ae

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

docs/codeql/support/reusables/frameworks.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ and the CodeQL library pack ``codeql/python-all`` (`changelog <https://github.co
226226
MySQL-python, Database
227227
mysqlclient, Database
228228
psycopg2, Database
229+
pymssql, Database
230+
PyMySQL, Database
229231
sqlite3, Database
230232
Flask-SQLAlchemy, Database ORM
231233
peewee, Database ORM

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private import semmle.python.frameworks.Peewee
3737
private import semmle.python.frameworks.Psycopg2
3838
private import semmle.python.frameworks.Pycurl
3939
private import semmle.python.frameworks.Pydantic
40+
private import semmle.python.frameworks.Pymssql
4041
private import semmle.python.frameworks.PyMySQL
4142
private import semmle.python.frameworks.Requests
4243
private import semmle.python.frameworks.RestFramework
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `pymssql` PyPI package.
3+
* See https://pypi.org/project/pymssql/
4+
*/
5+
6+
private import python
7+
private import semmle.python.dataflow.new.DataFlow
8+
private import semmle.python.dataflow.new.RemoteFlowSources
9+
private import semmle.python.Concepts
10+
private import semmle.python.ApiGraphs
11+
private import semmle.python.frameworks.PEP249
12+
13+
/**
14+
* Provides models for the `pymssql` PyPI package.
15+
* See https://pypi.org/project/pymssql/
16+
*/
17+
private module Pymssql {
18+
/**
19+
* A model of `pymssql` as a module that implements PEP 249, providing ways to execute SQL statements
20+
* against a database.
21+
*/
22+
class PymssqlPEP249 extends PEP249::PEP249ModuleApiNode {
23+
PymssqlPEP249() { this = API::moduleImport("pymssql") }
24+
}
25+
}
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 model of `pymssql` PyPI package as a SQL interface following PEP249, resulting in additional sinks for `py/sql-injection`.

python/ql/test/library-tests/frameworks/pymssql/ConceptsTest.expected

Whitespace-only changes.
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pymssql
2+
connection = pymssql.connect(host="localhost", user="user", password="passwd")
3+
4+
cursor = connection.cursor()
5+
cursor.execute("some sql", (42,)) # $ getSql="some sql"
6+
cursor.executemany("some sql", [(42,)]) # $ MISSING: getSql="some sql"

0 commit comments

Comments
 (0)