Skip to content
SQL injection Disclosed report Intermediate

Second-order SOQL injection through email and campaign name parameter in Salesforce lead submission

jobert Follow

Originally disclosed on HackerOne

  • Disclosed after 7 months

The HackerOne directory contains profiles of bug bounty and vulnerability disclosure programs that aren't managed on HackerOne. These profiles can be claimed by the organization that manages it. As part of this flow, they will need to enter an email address to confirm that affiliation with the company. This email address will then be used to look up potential duplicate leads in SFDC. A lead can also be submitted through the https://hackerone.com/leads endpoint. The vulnerability will be demonstrated with the Leads endpoint with the campaign name, since the duplicate detection requires a duplicate to be matched in the SFDC backend before it can be exploited.

POST /leads HTTP/1.1
Host: hackerone.com
...

campaign_name='&name=A&company_name=B&title=C&phone=D&website=https://e.com

When submitting the request above, a lead will be created in HackerOne's SFDC account. The campaign name is matched against the SFDC backend first to obtain the ID that belongs to the campaign name. It does so using the following code:

Ruby
def find_campaign_id_by_name(campaign_name)
  campaign_record = Salesforce::SalesforceClient.new.soql_query(
    "SELECT Id FROM Campaign WHERE Name = '#{campaign_name}'",
  )&.first

  campaign_record['Id'] unless campaign_record.nil?
end

The campaign_name is passed directly into the SOQL query, resulting in the ability to inject arbitrary SOQL commands. The lead is created asynchronously, which makes this a second-order SOQL injection. In case the SOQL query syntax is invalid, an exception will be thrown as such:

Restforce::ErrorCode::MalformedQuery
MALFORMED_QUERY: 
Id FROM Campaign WHERE Name = '''
                                ^
ERROR at Row:1:Column:40
line 1:40 mismatched character '<EOF>' expecting '''

Impact

Due to the limited functionality of SOQL, this doesn't seem to lead to any immediate risks. However, string interpolation in any kind of query should be discouraged.

The original report as published on HackerOne, by jobert. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

HackerOne maintains a directory of bug bounty and vulnerability disclosure programs that are not managed on HackerOne itself. Each of these programs has a profile, and the organisation behind it can claim that profile. Claiming requires the organisation to enter an email address, which is used to confirm the affiliation with the company.

That email address is then used to look up potential duplicate leads in Salesforce (SFDC). Leads can also be submitted directly through the https://hackerone.com/leads endpoint. The report demonstrates the issue through that endpoint, using the campaign name, because the duplicate detection path needs a matching duplicate in the SFDC backend before the vulnerable code runs.

Setup

The report does not describe any accounts, roles, tools or versions. The only precondition it states is that duplicate detection requires a duplicate to be matched in the SFDC backend before the injection can be exploited, which is why the researcher chose the campaign name parameter for the demonstration.

Finding it

The email address entered during the profile claim flow is used to look up potential duplicate leads in SFDC. Following that path led to the code that resolves a campaign name to a campaign ID, where the campaign name is interpolated straight into a SOQL query. Because the lead is created asynchronously, the injected query runs later in the backend, making this a second-order injection.

Exploitation

Step 1: Submit a lead with an injected campaign name

The lead submission endpoint accepts a form-encoded body. The researcher sent the following request, with the campaign name closed off and the remaining fields appended:

HTTP
POST /leads HTTP/1.1
Host: hackerone.com
...

campaign_name='&name=A&company_name=B&title=C&phone=D&website=https://e.com

The single quote in campaign_name terminates the string literal in the query, and the rest of the body supplies the other lead fields. Submitting this request creates a lead in HackerOne's SFDC account.

Step 2: The backend resolves the campaign name

The campaign name is matched against the SFDC backend first to obtain the ID belonging to that campaign name. The report shows the code that does this:

Ruby
def find_campaign_id_by_name(campaign_name)
  campaign_record = Salesforce::SalesforceClient.new.soql_query(
    "SELECT Id FROM Campaign WHERE Name = '#{campaign_name}'",
  )&.first

  campaign_record['Id'] unless campaign_record.nil?
end

The campaign_name value is passed directly into the SOQL query string, so an attacker controls the query text that follows Name = '. This is what allows arbitrary SOQL commands to be injected.

Step 3: Observe the error on invalid syntax

When the injected query has invalid syntax, an exception is thrown. The report shows the resulting error:

Restforce::ErrorCode::MalformedQuery
MALFORMED_QUERY:
Id FROM Campaign WHERE Name = '''
                                ^
ERROR at Row:1:Column:40
line 1:40 mismatched character '<EOF>' expecting '''

The error shows the malformed query as the SOQL parser saw it.

Root cause

The mistake is string interpolation of user-controlled input into a SOQL query. The campaign_name value is concatenated into the WHERE Name = '...' clause without escaping or parameterisation, so a single quote breaks out of the literal and the remainder is interpreted as SOQL. The lookup runs asynchronously during lead creation, which is why the report classifies the issue as second-order: the payload is stored with the lead and executed later by the backend process. The report does not describe any escaping, allow-listing or parameterised query layer that would have prevented this.

Impact

The report rates the issue as low severity (CVSS 2.7). The researcher states that, due to the limited functionality of SOQL, this does not seem to lead to any immediate risks. The practical effect shown is the ability to inject arbitrary SOQL commands into the campaign lookup query, with malformed queries producing a Restforce::ErrorCode::MalformedQuery exception. The researcher's broader point is that string interpolation in any kind of query should be discouraged.

Fix

The recommendation it makes is to avoid string interpolation in queries; the natural fix for this code is to stop building the SOQL statement by concatenation and to pass the campaign name as a bound value or escape it correctly before it reaches the query.

Variants to test

  1. Other lead fields that are matched against SFDC before creation, such as the email address used in the profile claim flow. A positive result is an error or response that reflects injected SOQL syntax back from the backend.
  2. Any parameter that is used to look up a record by name in a backend CRM. A positive result is a MalformedQuery style error when a single quote is supplied.
  3. Asynchronous creation paths in general: submit a payload, then watch for backend errors or delayed effects rather than expecting an immediate response. A positive result is an error surfacing after the request has already returned.

Hunting notes

This kind of bug hides in integrations between a web application and a CRM or other backend that speaks its own query language. The signals are endpoints that accept a name or identifier and then perform a lookup in the backend, especially when the record is created asynchronously. Supplying a single quote in a name field and looking for a parser error, as the report does with campaign_name, is a quick way to confirm that input reaches the query. The researcher reached the vulnerable code through lead submission with duplicate detection and produced a concrete backend exception, while noting that SOQL's limited functionality kept the immediate risk low.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

HackerOne runs a website that lists bug bounty and vulnerability disclosure programs. Some of those programs are not managed on HackerOne itself, but they still get a profile page on the site. The organisation behind such a program can claim its profile. To claim it, someone at the organisation types in an email address, and that address is used to check that the person really belongs to the company.

Behind the scenes, HackerOne stores this kind of information in Salesforce, a customer relationship management (CRM) system. A CRM is software companies use to keep track of contacts, companies and sales opportunities. In Salesforce, one of the record types is called a lead: a possible customer or contact. HackerOne also lets people submit leads directly through a web address, https://hackerone.com/leads.

When a lead comes in, HackerOne checks whether it looks like a duplicate of a lead that already exists in Salesforce. To do that check, it takes the campaign name from the submitted lead and asks Salesforce for the matching campaign record. The bug is in how that question is built: the campaign name is pasted straight into the query text instead of being passed as a separate, safely handled value. A person who controls the campaign name can therefore slip extra instructions into the query. This kind of bug is called injection, and because the query is not run at the moment of the request but later, in the background, it is called second-order injection.

The researcher rated the issue low severity (CVSS 2.7). The query language involved, SOQL, is limited in what it can do, so the report says this does not seem to lead to any immediate risks. The lesson the researcher draws is broader: never build a query by pasting user input into it.

Background you need

A few ideas come up again and again below, so here they are from zero.

API and endpoint. An API is a way for one piece of software to talk to another, or for a browser to talk to a website's backend, without a human clicking through pages. An endpoint is one specific address on that API that accepts a particular kind of request, like a counter in a shop that only handles one type of transaction. https://hackerone.com/leads is an endpoint: it accepts lead submissions.

HTTP request. When your browser loads a page or submits a form, it sends an HTTP request. The request has a method (such as POST, meaning "here is some data, please store or process it"), a path (which endpoint), headers (extra information about the request) and sometimes a body (the data itself).

Form-encoded body. When you fill in a web form and press submit, the browser usually packs the fields into the body as field=value pairs joined by &. That is what the payload below looks like.

Query language and SOQL. A database is an organised store of records. To get records out, software sends it a query, a sentence in a special language. Salesforce's language is called SOQL, Salesforce Object Query Language. A simple SOQL query looks like SELECT Id FROM Campaign WHERE Name = 'something': give me the Id field from the Campaign records whose Name equals something. The part in single quotes is a string literal, text treated as plain data, not as instructions.

String interpolation. This means gluing a value into a piece of text. If a program has the template Name = '#{campaign_name}' and the campaign name is Summer, the result is Name = 'Summer'. It is convenient, and it is exactly where injection bugs are born: if the value contains a single quote, it can break out of the quoted text and the rest is read as part of the query.

Injection. Injection is when untrusted input is interpreted as instructions rather than as data. Think of a form where you write your name, and the clerk reads your name out loud to a colleague as an order. If your name happens to be a sentence that sounds like an order, the colleague may follow it. The fix is always to keep data and instructions clearly separated.

Second-order. A first-order injection happens immediately, in the same request. A second-order injection is stored first and acted on later by another part of the system. Here the lead, including the malicious campaign name, is saved, and a background job later builds and runs the query.

Exception and stack-style error. When a program hits something it cannot handle, it raises an exception, an error signal. Often the error text includes a fragment of what went wrong, which is useful to developers and also useful to someone probing for a bug.

The setup

The report does not describe any accounts, roles, tools or versions. The one precondition it states is that the duplicate detection needs a duplicate to be matched in the Salesforce backend before the vulnerable code runs. That is why the researcher chose the campaign name parameter for the demonstration: it is the field that goes through the duplicate lookup.

Finding it

The email address entered during the profile claim flow is used to look up potential duplicate leads in Salesforce. Following that path led to the code that turns a campaign name into a campaign ID, and there the campaign name is pasted straight into a SOQL query. Because the lead is created asynchronously, the injected query runs later in the backend, which makes it a second-order injection.

Exploitation

Step 1: Submit a lead with an injected campaign name

The lead submission endpoint accepts a form-encoded body. The researcher sent the following request, with the campaign name closed off and the remaining fields appended:

HTTP
POST /leads HTTP/1.1
Host: hackerone.com
...

campaign_name='&name=A&company_name=B&title=C&phone=D&website=https://e.com

Line by line:

  • POST /leads HTTP/1.1 says: use the POST method on the /leads path, speaking version 1.1 of HTTP. POST is the method used when you are sending data to be processed.
  • Host: hackerone.com tells the server which site the request is for. One server can host many sites, so the request has to name the one it wants.
  • ... stands for the other headers a real request would carry, which the report leaves out.
  • The blank line separates the headers from the body.
  • The body is one line of field=value pairs joined by &. The first pair is campaign_name='. That single quote is the whole trick: it closes the quoted text in the query early. The pairs after it (name=A, company_name=B, title=C, phone=D, website=https://e.com) fill in the other lead fields so the submission looks like a normal lead.

Submitting this request creates a lead in HackerOne's Salesforce account. The lead is created asynchronously, so the query runs later in the background.

Step 2: The backend resolves the campaign name

The campaign name is matched against the Salesforce backend first to obtain the ID belonging to that campaign name. The report shows the code that does this:

Ruby
def find_campaign_id_by_name(campaign_name)
  campaign_record = Salesforce::SalesforceClient.new.soql_query(
    "SELECT Id FROM Campaign WHERE Name = '#{campaign_name}'",
  )&.first

  campaign_record['Id'] unless campaign_record.nil?
end

Line by line:

  • def find_campaign_id_by_name(campaign_name) defines a function, a named block of code, that takes one input called campaign_name. This is the value that came from the submitted lead.
  • Salesforce::SalesforceClient.new creates a connection object to Salesforce, the thing that knows how to talk to the CRM.
  • .soql_query(...) sends a SOQL query through that connection and returns the result.
  • "SELECT Id FROM Campaign WHERE Name = '#{campaign_name}'" is the query text. The #{campaign_name} part is string interpolation: whatever the user supplied is dropped into the sentence at that spot, inside single quotes. If the value contains a single quote, the quoted text ends early and anything after it is read as part of the query.
  • &.first takes the first record of the result, if there is one. The &. means "only continue if the thing before it is not empty".
  • campaign_record['Id'] unless campaign_record.nil? returns the campaign's Id field, unless no record was found.

The key point is that the campaign name is passed directly into the query string, so an attacker controls the query text that follows Name = '. That is what allows arbitrary SOQL commands to be injected.

Step 3: Observe the error on invalid syntax

When the injected query has invalid syntax, an exception is thrown. The report shows the resulting error:

Restforce::ErrorCode::MalformedQuery
MALFORMED_QUERY:
Id FROM Campaign WHERE Name = '''
                                ^
ERROR at Row:1:Column:40
line 1:40 mismatched character '<EOF>' expecting '''

Line by line:

  • Restforce::ErrorCode::MalformedQuery is the name of the error. Restforce is the library the code uses to talk to Salesforce, and this is its "your query was malformed" error code.
  • MALFORMED_QUERY: repeats that in plain text.
  • Id FROM Campaign WHERE Name = ''' is the query as the parser saw it. The extra quote shows where the injected text landed: the original opening quote, then the quote from the payload, then another quote, leaving the parser confused.
  • The ^ points at the position in the text where the parser gave up.
  • ERROR at Row:1:Column:40 and line 1:40 mismatched character '<EOF>' expecting ''' say the parser reached the end of the input (<EOF> means end of file) while it was still expecting a closing quote.

The error shows the malformed query as the SOQL parser saw it, with the injected text visible in the query.

Root cause

The mistake is string interpolation of user-controlled input into a SOQL query. The campaign_name value is concatenated into the WHERE Name = '...' clause without escaping or parameterisation, so a single quote breaks out of the literal and the remainder is interpreted as SOQL. Escaping means marking special characters so they are treated as plain text; parameterisation means sending the value separately from the query text so the database knows it is data, never instructions. The lookup runs asynchronously during lead creation, which is why the report calls the issue second-order: the payload is stored with the lead and executed later by the backend process. The report does not describe any escaping, allow-listing or parameterised query layer that would have prevented this.

Impact

The report rates the issue as low severity (CVSS 2.7). CVSS is a standard scoring system for vulnerabilities; 2.7 is on the low end. The researcher states that, due to the limited functionality of SOQL, this does not seem to lead to any immediate risks. The practical effect shown is the ability to inject arbitrary SOQL commands into the campaign lookup query, with malformed queries producing a Restforce::ErrorCode::MalformedQuery exception. The researcher's broader point is that string interpolation in any kind of query should be discouraged.

Fix

The recommendation it makes is to avoid string interpolation in queries. The natural fix for this code is to stop building the SOQL statement by concatenation and to pass the campaign name as a bound value or escape it correctly before it reaches the query.

Variants to test

  1. Other lead fields that are matched against Salesforce before creation, such as the email address used in the profile claim flow. A positive result is an error or response that reflects injected SOQL syntax back from the backend.
  2. Any parameter that is used to look up a record by name in a backend CRM. A positive result is a MalformedQuery style error when a single quote is supplied.
  3. Asynchronous creation paths in general: submit a payload, then watch for backend errors or delayed effects rather than expecting an immediate response. A positive result is an error surfacing after the request has already returned.

Hunting notes

This kind of bug hides in integrations between a web application and a CRM or other backend that speaks its own query language. The signals are endpoints that accept a name or identifier and then perform a lookup in the backend, especially when the record is created asynchronously. Supplying a single quote in a name field and looking for a parser error, as the report does with campaign_name, is a quick way to confirm that input reaches the query. The researcher reached the vulnerable code through lead submission with duplicate detection and produced a concrete backend exception, while noting that SOQL's limited functionality kept the immediate risk low.

Glossary

  • API: a defined way for software to talk to other software, usually over the web, without a human clicking through pages.
  • Endpoint: one specific address on an API that accepts a particular kind of request, such as https://hackerone.com/leads.
  • HTTP request: the message a browser or program sends to a server, made of a method, a path, headers and sometimes a body.
  • POST: an HTTP method meaning "here is data, please process or store it".
  • Header: extra information attached to an HTTP request, such as which site it is for.
  • Form-encoded body: request data packed as field=value pairs joined by &, the way a web form is usually submitted.
  • CRM: customer relationship management software, used to track contacts, companies and sales opportunities.
  • Salesforce (SFDC): the CRM system HackerOne uses to store leads and campaigns.
  • Lead: in Salesforce, a record of a possible customer or contact.
  • Campaign: in Salesforce, a record grouping related marketing or outreach activity, identified by an Id and a Name.
  • Query: a request for records written in a database's own language.
  • SOQL: Salesforce Object Query Language, the language used to ask Salesforce for records.
  • String literal: text inside quotes that is treated as plain data, not as instructions.
  • String interpolation: gluing a value into a piece of text, so the value becomes part of the text.
  • Injection: a bug where untrusted input is interpreted as instructions instead of data.
  • Second-order injection: an injection where the payload is stored first and acted on later by another part of the system.
  • Asynchronous: happening in the background, after the request has already returned, rather than immediately.
  • Exception: an error signal raised by a program when it cannot handle something.
  • Malformed query: a query with invalid syntax that the parser cannot understand.
  • Parser: the part of a system that reads query text and checks whether it follows the language's rules.
  • Escaping: marking special characters in a value so they are treated as plain text.
  • Parameterisation: sending a value separately from the query text so it is always treated as data.
  • Allow-listing: only accepting values from a known, approved set.
  • CVSS: a standard scoring system for the severity of vulnerabilities; 2.7 is a low score.
  • Restforce: the library the code uses to talk to Salesforce.

More by jobert

View all

67 more disclosed reports, best first.

More from HackerOne

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.