Skip to content

Commit 79db3b4

Browse files
authored
release v2.3.1 (#813)
Prepare mysqlclient 2.3.1 with a fix for SQL injection through Python `set` query parameters when `NO_BACKSLASH_ESCAPES` is enabled: [GHSA-m9c3-99x3-77g6](GHSA-m9c3-99x3-77g6).
1 parent cdf32b5 commit 79db3b4

7 files changed

Lines changed: 190 additions & 9 deletions

File tree

‎.github/workflows/actions.lock‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ workflows:
1212
'.github/workflows/windows.yaml':
1313
- 'actions/cache@v6.1.0'
1414
- 'actions/checkout@v7.0.1'
15+
- 'actions/download-artifact@v8.0.2'
1516
- 'actions/setup-python@v7.0.0'
1617
- 'actions/upload-artifact@v7.0.2'
18+
- 'pypa/gh-action-pypi-publish@v1.14.3'
1719
dependencies:
1820
'actions/cache@v6.1.0':
1921
ref: 'v6.1.0'
@@ -25,11 +27,21 @@ dependencies:
2527
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
2628
owner_id: 44036562
2729
repo_id: 197814629
30+
'actions/download-artifact@v8.0.2':
31+
ref: 'v8.0.2'
32+
commit: 'sha1-9000827ccba6bdab643e8b6fd33ac0654aef8333'
33+
owner_id: 44036562
34+
repo_id: 192626254
2835
'actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd':
2936
ref: 'v8.0.0'
3037
commit: 'sha1-ed597411d8f924073f98dfc5c65a23a2325f34cd'
3138
owner_id: 44036562
3239
repo_id: 205262760
40+
'actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405':
41+
ref: 'v6.2.0'
42+
commit: 'sha1-a309ff8b426b58ec0e2a45f0f869d46889d02405'
43+
owner_id: 44036562
44+
repo_id: 192625525
3345
'actions/setup-python@v7.0.0':
3446
ref: 'v7.0.0'
3547
commit: 'sha1-5fda3b95a4ea91299a34e894583c3862153e4b97'
@@ -47,3 +59,10 @@ dependencies:
4759
repo_id: 200299178
4860
uses:
4961
- 'actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd'
62+
'pypa/gh-action-pypi-publish@v1.14.3':
63+
ref: 'v1.14.3'
64+
commit: 'sha1-7245906fb61fa33a13554f9d5fb856fe61758086'
65+
owner_id: 647025
66+
repo_id: 178055147
67+
uses:
68+
- 'actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405'

‎.github/workflows/windows.yaml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Build windows wheels
33
on:
44
push:
55
branches: ["main", "ci"]
6+
tags: ["v*"]
67
pull_request:
78
workflow_dispatch:
89

10+
permissions:
11+
contents: read
12+
913
jobs:
1014
build:
1115
strategy:
@@ -107,3 +111,26 @@ jobs:
107111
with:
108112
name: win-wheels-${{ matrix.cibw_arch }}
109113
path: mysqlclient/dist/*.*
114+
if-no-files-found: error
115+
116+
publish:
117+
name: Publish to PyPI
118+
needs: build
119+
if: >-
120+
github.event_name == 'push' && github.event.created &&
121+
startsWith(github.ref, 'refs/tags/v')
122+
runs-on: ubuntu-latest
123+
permissions:
124+
id-token: write
125+
steps:
126+
- name: Download distributions
127+
uses: actions/download-artifact@v8.0.2
128+
with:
129+
pattern: win-wheels-*
130+
path: dist
131+
merge-multiple: true
132+
133+
- name: Publish distributions to PyPI
134+
uses: pypa/gh-action-pypi-publish@v1.14.3
135+
with:
136+
attestations: true

‎HISTORY.rst‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
======================
2+
What's new in 2.3.1
3+
======================
4+
5+
Release: 2026-11-10
6+
7+
* **Security fix:** Escape Python ``set`` query parameters using the connection's
8+
character set and SQL mode. This fixes SQL injection when
9+
``NO_BACKSLASH_ESCAPES`` is enabled and an attacker controls a set member.
10+
``frozenset`` parameters now use the same escaping.
11+
See `GHSA-m9c3-99x3-77g6 <https://github.com/PyMySQL/mysqlclient/security/advisories/GHSA-m9c3-99x3-77g6>`_.
12+
13+
* Deprecate ``MySQLdb.converters.Set2Str``.
14+
15+
* ``Connection.literal()`` now applies built-in handling only to exact built-in
16+
types. Subclasses use the connection's converter mapping.
17+
18+
* Fix crashes when looking up connection attributes with a non-string name or
19+
a string containing lone surrogates. (#810)
20+
21+
122
======================
223
What's new in 2.3.0
324
======================

‎notes/release.md‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Release procedure
2+
3+
The examples below release **2.3.1** after **2.3.0**. Replace the version
4+
numbers and release date as needed. Run commands from the repository root.
5+
6+
Ensure the PyPI Trusted Publisher for `mysqlclient` is configured with
7+
repository `PyMySQL/mysqlclient`, workflow `windows.yaml`, and no required
8+
environment name.
9+
10+
## 1. Update the release notes
11+
12+
Review the changes since the previous release:
13+
14+
```sh
15+
git log v2.3.0..HEAD --oneline
16+
git diff v2.3.0..HEAD --stat
17+
```
18+
19+
Add a `What's new in 2.3.1` section at the top of
20+
[HISTORY.rst](../HISTORY.rst), with `Release: YYYY-MM-DD` set to the release
21+
date. Document changes, fixes, and deprecations that affect users.
22+
23+
## 2. Update the version and create a release PR
24+
25+
Update both version fields in
26+
[src/MySQLdb/release.py](../src/MySQLdb/release.py):
27+
28+
```python
29+
__version__ = "2.3.1"
30+
version_info = (2, 3, 1, "final", 0)
31+
```
32+
33+
Format the source and run the checks:
34+
35+
```sh
36+
ruff format src/
37+
ruff check src/
38+
git diff --check
39+
```
40+
41+
Review the diff, commit it as `release v2.3.1`, and open a PR targeting
42+
`main` in `PyMySQL/mysqlclient`.
43+
44+
## 3. Verify CI for the release commit
45+
46+
Once the PR checks pass, merge it into `main`. Verify that all of the
47+
following workflows pass for the merged commit:
48+
49+
- `Lint`
50+
- `Test`, including MySQL, MariaDB, and Django tests
51+
- `Build windows wheels`
52+
53+
To run the tests locally, install the package and the dependencies in
54+
`requirements.txt`, prepare the database, and run the command used by the
55+
[test workflow](../.github/workflows/tests.yaml). Adjust `TESTDB` to use
56+
the configuration for your database:
57+
58+
```sh
59+
TESTDB=actions.cnf pytest --cov=MySQLdb tests
60+
```
61+
62+
Verify that the [Windows workflow](../.github/workflows/windows.yaml)
63+
produces both `win-wheels-AMD64` and `win-wheels-ARM64` artifacts. The AMD64
64+
artifact also contains the source distribution (sdist).
65+
66+
Record the release commit SHA.
67+
68+
## 4. Create and push the release tag
69+
70+
Replace `RELEASE_SHA` with the commit SHA verified in step 3. Fetch the
71+
commit, create a lightweight tag, and push it:
72+
73+
```sh
74+
git fetch upstream main --tags
75+
git tag v2.3.1 RELEASE_SHA
76+
git push upstream refs/tags/v2.3.1
77+
```
78+
79+
Pushing the new `v*` tag starts a build of the tagged commit. Once both
80+
Windows builds succeed, the `Publish to PyPI` job combines their artifacts
81+
and publishes the wheels and sdist using Trusted Publishing.
82+
Publishing is restricted to push events that create a new `v*` tag.
83+
84+
## 5. Verify publication and create the GitHub Release
85+
86+
Check the tag-triggered `Build windows wheels` workflow and confirm that
87+
both builds and the `Publish to PyPI` job succeed. Then create the GitHub
88+
Release:
89+
90+
```sh
91+
gh release create v2.3.1 -R PyMySQL/mysqlclient \
92+
--verify-tag --title v2.3.1 \
93+
--generate-notes --notes-start-tag v2.3.0
94+
```
95+
96+
## 6. Verify the published release
97+
98+
Check that PyPI lists the sdist and wheels for both architectures. Install
99+
`mysqlclient==2.3.1` in a fresh environment and verify the import and version:
100+
101+
```sh
102+
python -c 'import MySQLdb; print(MySQLdb.version_info)'
103+
```
104+
105+
The expected output is `(2, 3, 1, 'final', 0)`.

‎src/MySQLdb/connections.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ class object, used to create cursors (keyword only)
200200
"executemany_fallback", self.executemany_fallback
201201
)
202202
if executemany_fallback not in ("loop", "multi"):
203-
raise ValueError(
204-
"executemany_fallback must be either 'loop' or 'multi'"
205-
)
203+
raise ValueError("executemany_fallback must be either 'loop' or 'multi'")
206204

207205
client_flag = kwargs.get("client_flag", 0)
208206
client_flag |= CLIENT.MULTI_RESULTS
@@ -311,6 +309,12 @@ def _bytes_literal(self, bs):
311309
def _tuple_literal(self, t):
312310
return b"(%s)" % (b",".join(map(self.literal, t)))
313311

312+
def _set_literal(self, s):
313+
for c in s:
314+
if not isinstance(c, str):
315+
raise TypeError("set elements must be strings")
316+
return self.string_literal(",".join(s))
317+
314318
def literal(self, o):
315319
"""If o is a single object, returns an SQL literal as a string.
316320
If o is a non-string sequence, the items of the sequence are
@@ -319,12 +323,15 @@ def literal(self, o):
319323
Non-standard. For internal use; do not use this in your
320324
applications.
321325
"""
322-
if isinstance(o, str):
326+
t = type(o)
327+
if t is str:
323328
s = self.string_literal(o.encode(self.encoding))
324-
elif isinstance(o, (bytes, bytearray)):
329+
elif t in (bytes, bytearray):
325330
s = self._bytes_literal(o)
326-
elif isinstance(o, (tuple, list)):
331+
elif t in (tuple, list):
327332
s = self._tuple_literal(o)
333+
elif t in (set, frozenset):
334+
s = self._set_literal(o)
328335
else:
329336
s = self.escape(o, self.encoders)
330337
if isinstance(s, str):

‎src/MySQLdb/converters.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def Bool2Str(s, d):
6262

6363
def Set2Str(s, d):
6464
# Only support ascii string. Not tested.
65+
import warnings
66+
67+
warnings.warn("Set2Str is deprecated", DeprecationWarning, stacklevel=2)
6568
return string_literal(",".join(s))
6669

6770

@@ -112,7 +115,6 @@ def array2Str(o, d):
112115
Date: Thing2Literal,
113116
DateTimeType: DateTime2literal,
114117
DateTimeDeltaType: DateTimeDelta2literal,
115-
set: Set2Str,
116118
Decimal: Decimal2Literal,
117119
FIELD_TYPE.TINY: int,
118120
FIELD_TYPE.SHORT: int,

‎src/MySQLdb/release.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = "Inada Naoki <songofacandy@gmail.com>"
2-
__version__ = "2.3.0"
3-
version_info = (2, 3, 0, "final", 0)
2+
__version__ = "2.3.1"
3+
version_info = (2, 3, 1, "final", 0)

0 commit comments

Comments
 (0)