Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Develop into Release #3185

Merged
merged 23 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c677d6e
add Infacost rule (#3164)
LewisArdern Oct 16, 2023
1618ef1
New Published Rules - returntocorp.reserved-aws-lambda-environment-va…
semgrep-dev-pr-bot[bot] Oct 16, 2023
a5e6b94
Update `server-dangerous-object-deserialization` rule
nmote Oct 10, 2023
f46408a
Merge pull request #3140 from returntocorp/nmote/inheritance
nmote Oct 16, 2023
60e6fc7
Add rule for missing depends_on in subscription filters shipping to l…
minusworld Oct 17, 2023
05f8c58
Add rule flagging redundant fields on AWS Lambda resource when using …
minusworld Oct 17, 2023
3019c76
Updated unverified-jwt-token according to new APIs. Added fixtest (#3…
0xDC0DE Oct 17, 2023
ef6ede9
Update test targets for tests relying on include:
Oct 17, 2023
b1d7c13
Add rule for missing asterisk at end of aws_lambda_permission cloudwa…
minusworld Oct 17, 2023
d611cf7
Merge branch 'develop' into update_with_new_ignore_paths
p4p3r Oct 17, 2023
c5ce6c9
Merge pull request #3174 from returntocorp/update_with_new_ignore_paths
p4p3r Oct 17, 2023
23f79a4
Skip Apex rules when running the OSS testsuite (#3177)
p4p3r Oct 18, 2023
f77ecc3
Skip Apex rules in testsuite - part 2 (#3178)
p4p3r Oct 18, 2023
075ee5c
Add Apex and VisualForce rules (#3085)
garretpatten-ncino Oct 19, 2023
b09bc5a
Bump urllib3 from 2.0.6 to 2.0.7 (#3175)
dependabot[bot] Oct 19, 2023
86c0be6
hashids-with-django-secret (#3161)
Sjord Oct 19, 2023
d8905b0
test-is-missing-assert (#3172)
Sjord Oct 19, 2023
9685cf5
Fix metadata for Apex rules (#3184)
p4p3r Oct 19, 2023
ca69adf
Update python dangerous subprocess rule to accurately reflect documen…
0xDC0DE Oct 19, 2023
d42f7e3
Fix twitter oauth rule triggering on minimized css files (#3165)
0xDC0DE Oct 19, 2023
79684d4
Update ReDoS message (#3166)
0xDC0DE Oct 19, 2023
760444c
add additional testcases (#3171)
0xDC0DE Oct 19, 2023
bebb7f1
delete testfile (#3186)
0xDC0DE Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/semgrep-rules-test-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
run: rm -rf semgrep-rules/stats
- name: delete fingerprints directory
run: rm -rf semgrep-rules/fingerprints
- name: delete rules requiring Semgrep Pro
run: rm -rf semgrep-rules/apex
- name: validate rules
run: |
export SEMGREP="docker run --rm -w /src -v ${GITHUB_WORKSPACE}/semgrep-rules:/src returntocorp/semgrep:develop semgrep"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/semgrep-rules-test-historical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
run: rm -rf semgrep-rules/stats
- name: delete fingerprints directory
run: rm -rf semgrep-rules/fingerprints
- name: delete rules requiring Semgrep Pro
run: rm -rf semgrep-rules/apex
- name: grab historical semgrep version
env:
GH_TOKEN: ${{ github.token }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/semgrep-rules-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
run: rm -rf stats
- name: remove fingerprints from testing
run: rm -rf fingerprints
- name: remove rules requiring Semgrep Pro
run: rm -rf apex
- name: validate rules
run: semgrep --validate --config .
- name: run semgrep
Expand Down
182 changes: 90 additions & 92 deletions Pipfile.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* global javadoc
* javadoc with global in it
* javadoc global
*/
// ruleid: global-access-modifiers
global without sharing class GlobalAccessModifiers {
// ruleid: global-access-modifiers
global String globalInstanceVariable = 'globalInstanceVariable';

// ok: global-access-modifiers
public String publicInstanceVariable = 'publicInstanceVariable';

// ok: global-access-modifiers
private String privateInstanceVariable = 'privateInstanceVariable';

// ok: global-access-modifiers
// This is a test comment that has the word global in it
// ruleid: global-access-modifiers
global static void myGlobalMethod() { }

// ok: global-access-modifiers
public static void myPublicMethod() { }

// ok: global-access-modifiers
private static void myPrivateMethod() { }

// ok: global-access-modifiers
// This is another test comment with global
// ruleid: global-access-modifiers
global with sharing class TestGlobalClass { }

// ok: global-access-modifiers
public with sharing class TestPublicClass { }

// ok: global-access-modifiers
private without sharing class SystemMode { }

// ok: global-access-modifiers
// Global test comment - last one
// ruleid: global-access-modifiers
global static String globalStaticVariable = 'globalStaticVariable';

// ok: global-access-modifiers
public static String publicStaticVariable = 'publicStaticVariable';

// ok: global-access-modifiers
private static String privateStaticVariable = 'privateStaticVariable';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rules:
- id: global-access-modifiers
min-version: 1.44.0
severity: WARNING
languages:
- apex
metadata:
cwe:
- 'CWE-284: Improper Access Control'
category: best-practice
technology:
- salesforce
references:
- https://cwe.mitre.org/data/definitions/284.html
message: >-
Global classes, methods, and variables should be avoided (especially in managed packages) as they can
never be deleted or changed in signature. Always check twice if something needs to be global.
patterns:
- pattern-regex: global [A-Za-z0-9_]{3,}
- pattern-not-regex: //(\s+([a-zA-Z]+\s+)+)[a-zA-Z]+
- pattern-not-regex: '[*](\s+([a-zA-Z]+\s+)+)[a-zA-Z]+'
paths:
exclude:
- "*Test*"
- "*test*"
13 changes: 13 additions & 0 deletions apex/lang/best-practice/ncino/tests/UseAssertClass.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class UseAssertClass {
// ruleid: use-assert-class
System.assert(true);

// ruleid: use-assert-class
System.assertEquals(1,1);

// ruleid: use-assert-class
System.assertNotEquals(1,1);

// ok: use-assert-class
Assert.areEqual(1,1);
}
20 changes: 20 additions & 0 deletions apex/lang/best-practice/ncino/tests/UseAssertClass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
rules:
- id: use-assert-class
min-version: 1.44.0
severity: WARNING
languages:
- generic
metadata:
category: best-practice
references:
- https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Assert.htm
technology:
- salesforce
message: >-
Assert methods in the System class have been replaced with the Assert class:
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Assert.htm
pattern-regex: System\.assert
paths:
include:
- "*.cls"
- "UseAssertClass.cls"
51 changes: 51 additions & 0 deletions apex/lang/best-practice/ncino/urls/AbsoluteUrls.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Test Controller with Absolute URLs
*/
public with sharing class AbsoluteUrls {

public PageReference absoluteSalesforceUrlExample() {
// ruleid: absolute-urls
String strUrl = 'https://na8.salesforce.com/TestVFPage?AccountId=999';
PageReference newUrl = new PageReference(strUrl);
newURL.setRedirect(true);

return newURL;
}

public PageReference absoluteNonSalesforceUrlExample() {
// ok: absolute-urls
String strUrl = 'https://www.website.com';
PageReference newUrl = new PageReference(strUrl);
newURL.setRedirect(true);

return newURL;
}

public PageReference nonAbsoluteSalesforceUrlExample() {
// ok: absolute-urls
String strUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/TestVFPage?AccountId=999';
PageReference newUrl = new PageReference(strUrl);
newURL.setRedirect(true);

return newURL;
}

// Absolute Salesforce URL comment example
// ruleid: absolute-urls
// https://na8.salesforce.com/TestVFPage?AccountId=999

// Absolute non-Salesforce URL comment example
// ok: absolute-urls
// https://www.website.com

// Non-absolute Salesforce URL comment example
// ok: absolute-urls
// URL.getSalesforceBaseUrl().toExternalForm() + '/TestVFPage?AccountId=999

// ruleid: absolute-urls
private static final String ABSOLUTE_SF_URL_CONSTANT = 'https://na8.salesforce.com/TestVFPage?AccountId=999';
// ok: absolute-urls
private static final String ABSOLUTE_NON_SF_URL_CONSTANT = 'https://www.website.com';
// ok: absolute-urls
private static final String NON_ASBOLUTE_SF_URL_CONSTANT = URL.getOrgDomainUrl().toExternalForm() + '/TestVFPage?AccountId=999';
}
23 changes: 23 additions & 0 deletions apex/lang/best-practice/ncino/urls/AbsoluteUrls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rules:
- id: absolute-urls
min-version: 1.44.0
severity: WARNING
languages:
- apex
metadata:
category: best-practice
references:
- ''
technology:
- salesforce
message: >-
Using absolute URLs to Salesforce Pages is bug prone. Different sandboxes and production
environments will have different instance names (like "na10", "na15" etc.). Code using
absolute URLs will only work when it runs in the corresponding salesforce instances. It
will break as soon as it is deployed in another one. Thus only relative URLs, i.e. without
the domain and subdomain names, should be used when pointing to a salesforce page.
pattern-regex: (http|https)://.*(salesforce|force|visualforce)\.com\.*
paths:
exclude:
- "*Test*"
- "*test*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
public class AvoidNativeDmlInLoops {
public void insertInsideLoop() {
for (Integer i = 0; i < 151; i++) {
// ruleid: avoid-native-dml-in-loops
insert account;
// ruleid: avoid-native-dml-in-loops
Database.insert(a);
}
}

public void insertInsideLoop2() {
for (Account a : accounts) {
// ruleid: avoid-native-dml-in-loops
insert account;
// ruleid: avoid-native-dml-in-loops
Database.insert(a);
}
}

public void insertInsideLoop3() {
while (someCondition) {
// ruleid: avoid-native-dml-in-loops
insert account;
// ruleid: avoid-native-dml-in-loops
Database.insert(a);
}
}

public void insertInsideLoop4() {
do {
// ruleid: avoid-native-dml-in-loops
insert account;
// ruleid: avoid-native-dml-in-loops
Database.insert(a);
} while (someCondition);
}

public void updateInsideLoop() {
for (Integer i = 0; i < 151; i++) {
// ruleid: avoid-native-dml-in-loops
update account;
// ruleid: avoid-native-dml-in-loops
Database.update(a);
}
}

public void updateInsideLoop2() {
for (Account a : accounts) {
// ruleid: avoid-native-dml-in-loops
update account;
// ruleid: avoid-native-dml-in-loops
Database.update(a);
}
}

public void updateInsideLoop3() {
while (someCondition) {
// ruleid: avoid-native-dml-in-loops
update account;
// ruleid: avoid-native-dml-in-loops
Database.update(a);
}
}

public void updateInsideLoop4() {
do {
// ruleid: avoid-native-dml-in-loops
update account;
// ruleid: avoid-native-dml-in-loops
Database.update(a);
} while (someCondition);
}

public void upsertInsideLoop() {
for (Integer i = 0; i < 151; i++) {
// ruleid: avoid-native-dml-in-loops
upsert account;
// ruleid: avoid-native-dml-in-loops
Database.upsert(a);
}
}

public void upsertInsideLoop2() {
for (Account a : accounts) {
// ruleid: avoid-native-dml-in-loops
upsert account;
// ruleid: avoid-native-dml-in-loops
Database.upsert(a);
}
}

public void upsertInsideLoop3() {
while (someCondition) {
// ruleid: avoid-native-dml-in-loops
upsert account;
// ruleid: avoid-native-dml-in-loops
Database.upsert(a);
}
}

public void upsertInsideLoop4() {
do {
// ruleid: avoid-native-dml-in-loops
upsert account;
// ruleid: avoid-native-dml-in-loops
Database.upsert(a);
} while (someCondition);
}

public void deleteInsideLoop() {
for (Integer i = 0; i < 151; i++) {
// ruleid: avoid-native-dml-in-loops
delete account;
// ruleid: avoid-native-dml-in-loops
Database.delete(a);
}
}

public void deleteInsideLoop2() {
for (Account a : accounts) {
// ruleid: avoid-native-dml-in-loops
delete account;
// ruleid: avoid-native-dml-in-loops
Database.delete(a);
}
}

public void deleteInsideLoop3() {
while (someCondition) {
// ruleid: avoid-native-dml-in-loops
delete account;
// ruleid: avoid-native-dml-in-loops
Database.delete(a);
}
}

public void deleteInsideLoop4() {
do {
// ruleid: avoid-native-dml-in-loops
delete account;
// ruleid: avoid-native-dml-in-loops
Database.delete(a);
} while (someCondition);
}

}
Loading
Loading