Skip to content

Commit

Permalink
fix(salesforce): fix potential SOQL injection breach (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
emile-bex authored Oct 23, 2023
1 parent 9f76bb8 commit 1526988
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/external-services/salesforce/salesforce.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
} from './salesforce.types';

import {
escapeQuery,
executeBulkAction,
formatBusinessLines,
formatCompanyName,
Expand Down Expand Up @@ -459,7 +460,7 @@ export class SalesforceService {
await this.salesforce.query(
`SELECT Id
FROM ${ObjectNames.CONTACT}
WHERE Email = '${email}' ${
WHERE Email = '${escapeQuery(email)}' ${
recordType ? `AND RecordTypeId = '${recordType}'` : ''
} LIMIT 1`
);
Expand All @@ -472,7 +473,7 @@ export class SalesforceService {
await this.salesforce.query(
`SELECT Id
FROM ${ObjectNames.LEAD}
WHERE Email = '${email}'
WHERE Email = '${escapeQuery(email)}'
AND RecordTypeId = '${recordType}' LIMIT 1
`
);
Expand Down Expand Up @@ -501,7 +502,7 @@ export class SalesforceService {
`SELECT Id
FROM ${ObjectNames.CAMPAIGN_MEMBER}
WHERE ${leadId ? `LeadId = '${leadId}'` : `ContactId = '${contactId}'`}
AND CampaignId = '${infoCoId}' Limit 1`
AND CampaignId = '${escapeQuery(infoCoId)}' Limit 1`
);
return records[0]?.Id;
}
Expand Down
5 changes: 4 additions & 1 deletion src/external-services/salesforce/salesforce.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ export function mapSalesforceLeadFields<T extends LeadRecordType>(
leadProps: LeadProp<T>,
recordType: AnyCantFix
): SalesforceLeads[T] {

const { firstName, lastName, email, phone, zone } = leadProps;

const commonFields = {
Expand Down Expand Up @@ -593,3 +592,7 @@ export function executeBulkAction<T extends ObjectName>(
});
});
}

export function escapeQuery(query: string) {
return query.replace(/'/g, "\\'");
}

0 comments on commit 1526988

Please sign in to comment.