SQL Injection in GraphQL Endpointgggg
SQL Injection in GraphQL Endpointgggg
Endpoint
Bug 🐞 SQL Injection
Asset ☑️ GraphQL
Vulnerability Description:
The embedded_submission_form_uuid parameter in the /graphql endpoint is
vulnerable to SQL injection. By manipulating this parameter, an attacker can
inject arbitrary SQL queries, potentially leading to unauthorized access or data
leakage.
Proof of Concept:
To reproduce the vulnerability:
Locally:
HackerOne.com:
Impact:
The SQL injection appears to execute within the context of the secure schema.
While the full impact is currently unknown, given the ability for an attacker to
potentially switch schemas, it should be considered as having a high impact on
confidentiality.
Impacted Data:
No exploitation of the vulnerability has been detected. Further details can be
found in the report below.
Root Cause:
The vulnerability stems from the decision to use GraphQL parameters, which
were not properly sanitized, instead of input fields when introducing the
embedded submission form feature. Below is a snippet of the vulnerable code:
unless database_parameters_up_to_date
safe_query = ''
😮
safe_query += "SET SESSION #{key} TO #{value};" # <--
begin
connection.query(safe_query)
rescue ActiveRecord::StatementInvalid => e
# NOTE: when the transaction is aborted, we cannot set
or reset any parameters.
# Changes of previous SET statements are undone as wel
l, so we can safely do
# nothing here
raise e unless e.cause.is_a? PG::InFailedSqlTransaction
end
end
Recommendations:
Immediately patch the vulnerability by implementing proper parameter
sanitation in GraphQL queries.
Reference:
https://hackerone.com/reports/435066