{"id":"CVE-2023-47128","aliases":["CVE-2023-47128","GHSA-xq59-7jf3-rjc6","PYSEC-2023-241"],"related":[],"kind":"vulnerability","state":"published","title":"piccolo SQL Injection via named transaction savepoints","summary":"Piccolo is an object-relational mapping and query builder which supports asyncio. Prior to version 1.1.1, the handling of named transaction `savepoints` in all database implementations is vulnerable to SQL Injection via f-strings. While the likelihood of an end developer exposing a `savepoints` `name` parameter to a user is highly unlikely, it would not be unheard of. If a malicious user was able to abuse this functionality they would have essentially direct access to the database and the ability to modify data to the level of permissions associated with the database user. A non exhaustive list of actions possible based on database permissions is: Read all data stored in the database, including usernames and password hashes; insert arbitrary data into the database, including modifying existing records; and gain a shell on the underlying server. Version 1.1.1 fixes this issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Piccolo is an object-relational mapping and query builder which supports asyncio. Prior to version 1.1.1, the handling of named transaction `savepoints` in all database implementations is vulnerable to SQL Injection via f-strings. While the likelihood of an end developer exposing a `savepoints` `name` parameter to a user is highly unlikely, it would not be unheard of. If a malicious user was able to abuse this functionality they would have essentially direct access to the database and the ability to modify data to the level of permissions associated with the database user. A non exhaustive list of actions possible based on database permissions is: Read all data stored in the database, including usernames and password hashes; insert arbitrary data into the database, including modifying existing records; and gain a shell on the underlying server. Version 1.1.1 fixes this issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nThe handling of named transaction savepoints in all database implementations is vulnerable to [SQL Injection](https://owasp.org/www-community/attacks/SQL_Injection) as user provided input is passed directly to `connection.execute(...)` via f-strings.\n\n### Details\n\nAn excerpt of the Postgres savepoint handling:\n```python\n    async def savepoint(self, name: t.Optional[str] = None) -> Savepoint:\n        name = name or f\"savepoint_{self.get_savepoint_id()}\"\n        await self.connection.execute(f\"SAVEPOINT {name}\")\n        return Savepoint(name=name, transaction=self)\n```\n\nIn this example, we can see user input is directly passed to `connection.execute` without being properly escaped. \n\nAll implementations of savepoints and savepoint methods directly pass this `name` parameter to `connection.execute` and are vulnerable to this. A non-exhaustive list can be found below:\n- Postgres\n- - [One](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/postgres.py#L239)\n- - [Two](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/postgres.py#L133)\n- - [Three](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/postgres.py#L138)\n- Sqlite\n- - [One](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/sqlite.py#L416)\n- - [Two](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/sqlite.py#L313)\n- - [Three](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/sqlite.py#L318)\n\nCare should be given to ensuring all strings passed to `connection.execute` are properly escaped, regardless of how end user facing they may be.\n\nFurther to this, the [following method](https://github.com/piccolo-orm/piccolo/blob/master/piccolo/engine/postgres.py#L404) also passes user input directly to an execution context however I have been unable to abuse this functionality at the time of writing. This method also has a far lower chance of being exposed to an end user as it relates to database init functionality.\n\n### PoC\n\nThe following FastAPI route can be used in conjunction with [sqlmap](https://github.com/sqlmapproject/sqlmap) to easily demonstrate the SQL injection.\n\n```python\nDB = ...\n\n@app.get(\"/test\")\nasync def test(name):\n    async with DB.transaction() as transaction:\n        await transaction.savepoint(name)\n```\n\n##### Steps\n\n1. Create a standard Piccolo application with Postgres as a database backend\n2. Add the route shown previously\n3. Run your application, making a note of the URL it is served on\n4. Install [sqlmap](https://github.com/sqlmapproject/sqlmap)\n5. In a terminal, run the following command substituting URL with your applications URL: `sqlmap -u \"http://URL/test?name=a\" --batch`\n6. Observe sqlmap identifying the vulnerability\n\nFor sqlmap help, [this usage guide](https://github.com/sqlmapproject/sqlmap/wiki/Usage) may be useful. The following commands may also be helpful to see the impact.\n\n###### Dumping all tables\n\nThe `--tables` flag will enumerate all tables accessible from within the exposed database session.\n\n`sqlmap -u \"http://URL/test?name=a\" --batch --tables`\n\nAn example output of this can be seen in the following screenshot.\n![Screenshot from 2023-11-06 23-10-30](https://user-images.githubusercontent.com/47520067/280669236-5be9dc0f-4d2c-4bad-a1ba-fc1eb43fdb34.png)\n\n\n###### OS Shell\n\nThe `--os-shell` will drop the user into an OS shell on the underlying system if permissions permit. This can be seen in the attached screenshot which prints the databases current working directory. \n![Screenshot from 2023-11-06 22-43-50](https://user-images.githubusercontent.com/47520067/280668670-0a152589-5f4c-468d-99b9-045226934007.png)\n\n\n### Impact\n\nWhile the likelihood of an end developer exposing a savepoints `name` parameter to a user is highly unlikely, it would not be unheard of. If a malicious user was able to abuse this functionality they would have essentially direct access to the database and the ability to modify data to the level of permissions associated with the database user. \n\nA non exhaustive list of actions possible based on database permissions is:\n- Read all data stored in the database, including usernames and password hashes\n- Insert arbitrary data into the database, including modifying existing records \n- Gain a shell on the underlying server","format":"markdown","source":"ghsa"},{"lang":"es","text":"Piccolo es un generador de consultas y mapeo relacional de objetos que admite asyncio. Antes de la versión 1.1.1, el manejo de \"savepoints\" de transacciones con nombre en todas las implementaciones de bases de datos es vulnerable a la inyección SQL a través de cadenas f. Si bien la probabilidad de que un desarrollador final exponga un parámetro de \"name\" de \"savepoints\" a un usuario es muy poco probable, no sería algo inaudito. Si un usuario malintencionado pudiera abusar de esta funcionalidad, tendría esencialmente acceso directo a la base de datos y la capacidad de modificar los datos al nivel de permisos asociados con el usuario de la base de datos. Una lista no exhaustiva de acciones posibles según los permisos de la base de datos es: Leer todos los datos almacenados en la base de datos, incluidos los nombres de usuario y los hashes de contraseñas; insertar datos arbitrarios en la base de datos, incluida la modificación de registros existentes; y obtener un shell en el servidor subyacente. La versión 1.1.1 soluciona este problema.","source":"nvd"}],"published":"2023-11-10T18:11:07.863Z","modified":"2026-06-17T06:32:12.850Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N","rating":"CRITICAL"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"}],"cwes":["CWE-89"],"affected":[{"ranges":[{"version":"< 1.1.1","status":"affected"}],"vendor":"piccolo-orm","product":"piccolo","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.1.1"}],"ecosystem":"PyPI","package":"piccolo","purl":"pkg:pypi/piccolo","source":"ghsa"},{"ranges":[{"status":"affected","version":"1.1.0"}],"vendor":"piccolo-orm","product":"piccolo","cpe":"cpe:2.3:a:piccolo-orm:piccolo:1.1.0:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"82679eb8cd1449cf31d87c9914a072e70168b6eb"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.1.1"}],"ecosystem":"PyPI","package":"piccolo","purl":"pkg:pypi/piccolo","repo":"https://github.com/piccolo-orm/piccolo","source":"pysec"}],"references":[{"url":"https://github.com/piccolo-orm/piccolo/security/advisories/GHSA-xq59-7jf3-rjc6","tags":["advisory","evidence","exploit","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/piccolo-orm/piccolo/commit/82679eb8cd1449cf31d87c9914a072e70168b6eb","tags":["fix","patch","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2023-47128","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/piccolo-orm/piccolo","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/piccolo/PYSEC-2023-241.yaml","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2024-09-03T17:27:44.708Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2023-47128","url":"https://www.cve.org/CVERecord?id=CVE-2023-47128","licence":"CVE Terms of Use","modified":"2024-09-03T17:28:09.878Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-xq59-7jf3-rjc6","url":"https://github.com/advisories/GHSA-xq59-7jf3-rjc6","licence":"CC-BY-4.0","modified":"2026-06-09T13:04:23.000Z"},{"source":"nvd","name":"NVD","id":"CVE-2023-47128","url":"https://nvd.nist.gov/vuln/detail/CVE-2023-47128","licence":"Public domain","modified":"2026-06-17T06:32:12.850Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2023-241","url":"https://osv.dev/vulnerability/PYSEC-2023-241","licence":"CC-BY-4.0","modified":"2026-06-08T11:15:06.561Z"}],"updatedAt":"2026-11-25T22:58:30.309Z","epss":{"score":0.00955,"percentile":0.62412,"date":"2026-12-01T12:00:22.000Z"}}