Skip to content

Commit f6bbd06

Browse files
Merge pull request #88 from project-codeguard/fix/differentiate-soql-from-sql-injection
Add SOQL/SOSL injection guidance to differentiate from SQL
2 parents e83b958 + a36456b commit f6bbd06

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

skills/software-security/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ When writing or reviewing code:
2929

3030
| Language | Rule Files to Apply |
3131
|----------|---------------------|
32+
| apex | codeguard-0-input-validation-injection.md |
3233
| c | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-data-storage.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-safe-c-functions.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
3334
| cpp | codeguard-0-safe-c-functions.md |
3435
| d | codeguard-0-iac-security.md |

skills/software-security/rules/codeguard-0-input-validation-injection.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
2-
description: Input validation and injection defense (SQL/LDAP/OS), parameterization, prototype pollution
2+
description: Input validation and injection defense (SQL/SOQL/LDAP/OS), parameterization, prototype pollution
33
languages:
4+
- apex
45
- c
56
- go
67
- html
@@ -49,6 +50,16 @@ pstmt.setString( 1, custname);
4950
ResultSet results = pstmt.executeQuery( );
5051
```
5152

53+
### SOQL/SOSL Injection (Salesforce)
54+
55+
SOQL and SOSL are query/search languages (no SQL-style DDL/DML). Data changes are performed via Apex DML or Database methods. Note: SOQL can lock rows via `FOR UPDATE`.
56+
57+
- Primary risk: data exfiltration by bypassing intended query filters/business logic; impact is amplified when Apex runs with elevated access (system mode) or when CRUD/FLS aren't enforced.
58+
- Second-order risk (conditional): if queried records are passed to DML, injection can broaden the record set and cause unintended mass updates/deletes.
59+
- Prefer static SOQL/SOSL with bind variables: `[SELECT Id FROM Account WHERE Name = :userInput]` or `FIND :term`.
60+
- For dynamic SOQL, use `Database.queryWithBinds()`; for dynamic SOSL, use `Search.query()`. Allow‑list any dynamic identifiers. If concatenation is unavoidable, escape string values with `String.escapeSingleQuotes()`.
61+
- Enforce CRUD/FLS with `WITH USER_MODE` or `WITH SECURITY_ENFORCED` (don't combine both). Enforce record sharing with `with sharing` or user-mode operations. Use `Security.stripInaccessible()` before DML.
62+
5263
### LDAP Injection Prevention
5364
- Always apply context‑appropriate escaping:
5465
- DN escaping for `\ # + < > , ; " =` and leading/trailing spaces

sources/core/codeguard-0-input-validation-injection.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: Input validation and injection defense (SQL/LDAP/OS), parameterization,
3-
prototype pollution
2+
description: Input validation and injection defense (SQL/SOQL/LDAP/OS), parameterization, prototype pollution
43
languages:
4+
- apex
55
- c
66
- go
77
- html
@@ -50,6 +50,16 @@ pstmt.setString( 1, custname);
5050
ResultSet results = pstmt.executeQuery( );
5151
```
5252

53+
### SOQL/SOSL Injection (Salesforce)
54+
55+
SOQL and SOSL are query/search languages (no SQL-style DDL/DML). Data changes are performed via Apex DML or Database methods. Note: SOQL can lock rows via `FOR UPDATE`.
56+
57+
- Primary risk: data exfiltration by bypassing intended query filters/business logic; impact is amplified when Apex runs with elevated access (system mode) or when CRUD/FLS aren't enforced.
58+
- Second-order risk (conditional): if queried records are passed to DML, injection can broaden the record set and cause unintended mass updates/deletes.
59+
- Prefer static SOQL/SOSL with bind variables: `[SELECT Id FROM Account WHERE Name = :userInput]` or `FIND :term`.
60+
- For dynamic SOQL, use `Database.queryWithBinds()`; for dynamic SOSL, use `Search.query()`. Allow‑list any dynamic identifiers. If concatenation is unavoidable, escape string values with `String.escapeSingleQuotes()`.
61+
- Enforce CRUD/FLS with `WITH USER_MODE` or `WITH SECURITY_ENFORCED` (don't combine both). Enforce record sharing with `with sharing` or user-mode operations. Use `Security.stripInaccessible()` before DML.
62+
5363
### LDAP Injection Prevention
5464
- Always apply context‑appropriate escaping:
5565
- DN escaping for `\ # + < > , ; " =` and leading/trailing spaces

src/language_mappings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Master mapping of languages to file extensions
1111
LANGUAGE_TO_EXTENSIONS = {
12+
"apex": [".cls", ".trigger"],
1213
"python": [".py", ".pyx", ".pyi"],
1314
"javascript": [".js", ".jsx", ".mjs"],
1415
"typescript": [".ts", ".tsx"],

0 commit comments

Comments
 (0)