Skip to content

[Authenticated] SQL Injection in Grapher Admin

High
marcelgerber published GHSA-28j4-g4cq-9r32 Apr 16, 2025

Package

owid/owid-grapher (Git commit)

Affected versions

>= a78ea12da40baa5ae843cc9d132afbf26ad47f93

Patched versions

>= a7165ab1ec449be749b0c97f3056fcede4c83eb8

Description

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:

const author = req.query.author || "Max Roser"

Sink 1:

trx,
`-- sql
SELECT id, publishedAt
FROM posts_gdocs
WHERE JSON_CONTAINS(content->'$.authors', '"${author}"')
AND type NOT IN ("data-insight", "fragment")
AND published = 1
`
)

Sink 2:

const wpModularTopicPages = await db.knexRaw<WordpressPageRecord>(
trx,
`-- sql
SELECT
wpApiSnapshot->>"$.slug" as slug,
wpApiSnapshot->>"$.title.rendered" as title,
wpApiSnapshot->>"$.excerpt.rendered" as subtitle,
TRUE as isWordpressPage,
wpApiSnapshot->>"$.authors_name" as authors,
wpApiSnapshot->>"$.featured_media_paths.medium_large" as thumbnail,
wpApiSnapshot->>"$.date" as publishedAt
FROM posts p
WHERE wpApiSnapshot->>"$.content" LIKE '%topic-page%'
AND JSON_CONTAINS(wpApiSnapshot->'$.authors_name', '"${author}"')
AND wpApiSnapshot->>"$.status" = 'publish'
AND NOT EXISTS (
SELECT 1 FROM posts_gdocs pg
WHERE pg.slug = p.slug
AND pg.content->>'$.type' LIKE '%topic-page'
)
`

PoC

Request:

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


Response:

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}}

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.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required High
User interaction None
Vulnerable System Impact Metrics
Confidentiality Low
Integrity High
Availability Low
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')

The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Learn more on MITRE.

Credits