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

RELEASE: @W-13805530@: Merging dev to release for 3.15.0 #1136

Merged
merged 52 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b957690
@W-13569661@: Create DmlInLoopRule and add tests
MrEminent42 Jul 6, 2023
906b524
@W-13569661@: Updates for first review
MrEminent42 Jul 10, 2023
c55cc9a
@W-13569661@: Fix test typo
MrEminent42 Jul 10, 2023
2633e64
@W-13569661@: fix Database.<method> checks in DML rule
MrEminent42 Jul 10, 2023
7787a24
@W-13569661@: Fix tests for number of enabled rules to account for Dm…
MrEminent42 Jul 10, 2023
2965248
@W-13569661@: update DML tests to use NumberOfEmployees field in SOQL…
MrEminent42 Jul 10, 2023
27dd220
@W-13569661@: formatting, update JDoc in DmlLoopVisitor
MrEminent42 Jul 10, 2023
e289b50
@W-13569661@: update map of method name to database operation
MrEminent42 Jul 10, 2023
030ce51
@W-13569661@: fix jdoc typo in LoopDetectionVisitor
MrEminent42 Jul 10, 2023
0d4996b
@W-13569661@: update loopIncrementStatement test in DML to use ValueS…
MrEminent42 Jul 10, 2023
1252825
@W-13569661@: update loopFromStaticBlockOk test in DML to use ValueSo…
MrEminent42 Jul 10, 2023
f50531b
@W-13569661@: fix testNestedLoop loop structure typos
MrEminent42 Jul 10, 2023
151e232
@W-13569661@: fold testNestedLoop into testLoopWithinLoop
MrEminent42 Jul 10, 2023
7f504f9
@W-13569661@: test methods inside for each statement are correctly ov…
MrEminent42 Jul 10, 2023
9528b24
@W-13569661@: move OccurrenceInfo to rules.ops subpackage
MrEminent42 Jul 10, 2023
dde5bf4
@W-13569661@: move inputs for testDatabaseMethodWithinLoop to a Metho…
MrEminent42 Jul 10, 2023
306ae93
@W-13569661@: add vertex end scopes order test
MrEminent42 Jul 11, 2023
ed5035b
@W-13569661@: update DmlInLoopRule test names to be more descriptive
MrEminent42 Jul 11, 2023
e31c145
@W-13569661@: move string-to-DatabaseOperation mapping to DmlUtil
MrEminent42 Jul 11, 2023
cc059d1
@W-13569661@: add Override annotations to DmlInLoopVisitor
MrEminent42 Jul 11, 2023
63405e1
@W-13569661@: fix DML tests SOQL query typos
MrEminent42 Jul 11, 2023
dc5e5c4
Merge pull request #1110 from MrEminent42/d/W-13569661-b
jfeingold35 Jul 11, 2023
ecdb00e
CHANGE (CodeAnalyzer): @W-13644357@: Updated README.
jfeingold35 Jul 14, 2023
54860a9
Merge pull request #1114 from forcedotcom/d/W-13644357
jfeingold35 Jul 19, 2023
1e3a01d
@W-12943227@: Adds sample project for writing Java-based PMD custom r…
jfeingold35 Jul 14, 2023
3cf305a
@W-12943227@: Updated README to address feedback.
jfeingold35 Jul 18, 2023
6b22002
Merge pull request #1113 from forcedotcom/d/W-12943227
jfeingold35 Jul 19, 2023
6a5f236
@W-13569661@: Update JDoc, user facing messages for new UI text and f…
MrEminent42 Jul 12, 2023
e7d637a
@W-1353661@: rename DmlInLoopRule to AvoidDatabaseOperationInLoop
MrEminent42 Jul 20, 2023
2ff9fe8
@W-1353661@: update UI text for AvoidDatabaseOperationInLoop
MrEminent42 Jul 20, 2023
03d035e
@W-13569661@: update leftover classes to the new name for AvoidDataba…
MrEminent42 Jul 20, 2023
0f5330b
Merge pull request #1121 from MrEminent42/d/W-13569661-b
jfeingold35 Jul 20, 2023
7b91b70
@W-13720122@: MultipleMassSchemaLookupRule going GA as AvoidMultipleM…
jfeingold35 Jul 24, 2023
cee1a23
Merge pull request #1125 from forcedotcom/d/W-13720122
jfeingold35 Jul 24, 2023
d3e51f4
CHANGE (ESLint): @W-8458220@: Custom ESLint config discards noisy vio…
jfeingold35 Jul 20, 2023
dd9e52b
Merge pull request #1116 from forcedotcom/d/W-8458220
jfeingold35 Jul 24, 2023
4c930f7
@W-13569669@: add UseWithSharingOnDatabaseOperation rule, testing
MrEminent42 Jul 12, 2023
c12da01
@W-13569669@: final review changes
MrEminent42 Jul 26, 2023
9e0ac81
Merge pull request #1124 from MrEminent42/d/W-13569669
jfeingold35 Jul 26, 2023
0100811
@W-13790909@: Renamed UnusedMethodRule to RemoveUnusedMethod.
jfeingold35 Jul 24, 2023
1ee709b
Merge pull request #1123 from forcedotcom/d/W-13790909
jfeingold35 Jul 26, 2023
26e1638
CHANGE (GraphEngine): @W-13720122@: Adjusted MMS rule URL to new value.
jfeingold35 Jul 27, 2023
27a3843
Merge pull request #1127 from forcedotcom/d/W-13720122-supp
jfeingold35 Jul 27, 2023
f210644
CHANGE (GraphEngine): @W-13790909@: Adjusted url for RemoveUnusedMethod.
jfeingold35 Jul 27, 2023
dc391c4
@W-13790909@: Adjusted variable names.
jfeingold35 Jul 27, 2023
ecb5ac3
Merge pull request #1128 from forcedotcom/d/W-13790909-supp
jfeingold35 Jul 27, 2023
c850adc
@W-13569669@: fix references to subclasses in warnings
MrEminent42 Jul 27, 2023
e70460d
Merge pull request #1130 from MrEminent42/d/W-13569669
jfeingold35 Jul 27, 2023
2905b0c
FIX (GraphEngine): @W-13848149@: Adjusted violation URLs so they poin…
jfeingold35 Jul 28, 2023
be9e289
Merge pull request #1134 from forcedotcom/d/W-13848149
jfeingold35 Jul 29, 2023
25527fe
NEW (CodeAnalyzer): @W-13805530@: RetireJS and package updates for 3.…
jfeingold35 Jul 31, 2023
4b54053
Merge pull request #1135 from forcedotcom/d/W-13805530
jfeingold35 Jul 31, 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/build
/test-results
/test-coverage
/typescript-test-results
.DS_Store
*-debug.log
*-error.log
Expand All @@ -11,6 +12,10 @@
/tmp
node_modules
/out
# Build folders
/sample-code/pmd-example-rules/target


# Logs
logs
*.log
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[![CircleCI](https://circleci.com/gh/forcedotcom/sfdx-scanner/tree/master.svg?style=shield)](https://circleci.com/gh/forcedotcom/sfdx-scanner/tree/master)
[![License](https://img.shields.io/npm/l/scanner.svg)](https://github.com/forcedotcom/sfdx-scanner/blob/master/package.json)

# Salesforce CLI Scanner Plug-in
The Salesforce CLI Scanner plug-in is a unified tool for static analysis of source code, in multiple languages (including Apex), with a consistent command-line interface and report output. We currently support the PMD rule engine and ESLint. We may add support for more rule engines in the future.
# Salesforce Code Analyzer
Salesforce Code Analyzer is a unified tool for static analysis of source code.
Code Analyzer analyzes multiple languages.
It relies on a consistent command-line interface and produces a results file of rule violations.
Use the results to review and improve your code.

The Salesforce CLI Scanner Plug-in creates "Rule Violations" when the scanner identifies issues. Developers use this information as feedback to fix their code.
If you're listing a managed package on AppExchange, it must pass security review.
You're also required to upload your Salesforce Code Analyzer scan reports.
Attach your Code Analyzer reports to your submission in the AppExchange Security Review Wizard.
For more info, read [Scan Your Code with Salesforce Code Analyzer](https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/security_review_code_analyzer_scan.htm) and [AppExchange Security Review](https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/security_review_overview.htm).

You can integrate this plug-in into your CI/CD solution to enforce the rules and expect high-quality code.
Code Analyzer current supports the PMD rule engine, PMD Copy Paste Detector, ESLint, RetireJS, and Salesforce Graph Engine.

# Official Documentation
All the official documentation on the Salesforce CLI Scanner plug-in is hosted on [GitHub Pages](https://forcedotcom.github.io/sfdx-scanner/). These documents include instructions on how to install the plug-in, the command reference, writing and managing custom rules and an overview of the architecture of the plug-in.
Integrate Code Analyzer into your Continuous Integration/Continuous Development (CI/CD) process to enforce rules that you define and to produce high-quality code.

### Document Link
https://forcedotcom.github.io/sfdx-scanner/
# Salesforce Code Analyzer Documentation
Read [Salesforce Code Analyzer](https://forcedotcom.github.io/sfdx-scanner/) documentation to learn:
* how to install Code Analyzer
* what is included in the Code Analyzer command reference
* the structure of Code Analyzer architecture
* how to write and manage custom rules

### Building/Contributing
Instructions [here](CONTRIBUTING.md).

=======

# Usage

Here is the information on [How to Install the plugin](https://forcedotcom.github.io/sfdx-scanner/en/v3.x/getting-started/install/)

Please check out the [Salesforce CLI Scanner Plug-In Command Reference](https://forcedotcom.github.io/sfdx-scanner/en/v3.x/scanner-commands/run/) for usage and demo of the plugin.
### Contribute to Salesforce Code Analyzer
Read these instructions to [contribute to Code Analyzer](https://github.com/forcedotcom/sfdx-scanner/blob/dev/CONTRIBUTING.md)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/sfdx-scanner",
"description": "Static code scanner that applies quality and security rules to Apex code, and provides feedback.",
"version": "3.14.0",
"version": "3.15.0",
"author": "ISV SWAT",
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
"dependencies": {
Expand Down
121 changes: 102 additions & 19 deletions retire-js/RetireJsVulns.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"summary": "Selector interpreted as HTML",
"githubID": "GHSA-2pqj-h3vj-pqgw"
},
"severity": "high",
"severity": "medium",
"info": [
"http://bugs.jquery.com/ticket/11290",
"https://nvd.nist.gov/vuln/detail/CVE-2012-6708",
Expand Down Expand Up @@ -269,7 +269,8 @@
],
"identifiers": {
"CVE": [
"CVE-2020-11023"
"CVE-2020-11023",
"CVE-2020-23064"
],
"issue": "4647",
"summary": "passing HTML containing <option> elements from untrusted sources - even after sanitizing it - to one of jQuery's DOM manipulation methods (i.e. .html(), .append(), and others) may execute untrusted code.",
Expand Down Expand Up @@ -388,7 +389,7 @@
},
{
"below": "1.19.4",
"severity": "low",
"severity": "medium",
"cwe": [
"CWE-1333"
],
Expand Down Expand Up @@ -834,6 +835,84 @@
"hashes": {}
}
},
"jquery.terminal": {
"vulnerabilities": [
{
"below": "1.21.0",
"severity": "medium",
"cwe": [
"CWE-79"
],
"identifiers": {
"summary": "Reflected Cross-Site Scripting in jquery.terminal",
"githubID": "GHSA-2hwp-g4g7-mwwj"
},
"info": [
"https://github.com/jcubic/jquery.terminal/commit/c8b7727d21960031b62a4ef1ed52f3c634046211",
"https://www.npmjs.com/advisories/769"
]
},
{
"below": "2.31.1",
"severity": "low",
"cwe": [
"CWE-79",
"CWE-80"
],
"identifiers": {
"summary": "jquery.terminal self XSS on user input",
"githubID": "GHSA-x9r5-jxvq-4387",
"CVE": [
"CVE-2021-43862"
]
},
"info": [
"https://github.com/jcubic/jquery.terminal/security/advisories/GHSA-x9r5-jxvq-4387",
"https://nvd.nist.gov/vuln/detail/CVE-2021-43862"
]
}
],
"extractors": {
"uri": [
"/jquery.terminal[@/](§§version§§)/"
],
"filecontent": [
"version (§§version§§)[\\s]+\\*[\\s]+\\* This file is part of jQuery Terminal.",
"\\$\\.terminal=\\{version:\"(§§version§§)\""
]
}
},
"jquery-deparam": {
"vulnerabilities": [
{
"below": "999",
"severity": "high",
"cwe": [
"CWE-1321"
],
"identifiers": {
"githubID": "GHSA-xg68-chx2-253g",
"CVE": [
"CVE-2021-20087"
]
},
"info": [
"https://nvd.nist.gov/vuln/detail/CVE-2021-20087"
]
}
],
"extractors": {
"hashes": {
"61c9d49ae64331402c3bde766c9dc504ed2ca509": "0.5.3",
"10a68e5048995351a01b0ad7f322bb755a576a02": "0.5.2",
"b8f063c860fa3aab266df06b290e7da648f9328d": "0.4.2",
"851bc74dc664aa55130ecc74dd6b1243becc3242": "0.4.1",
"2aae12841f4d00143ffc1effa59fbd058218c29f": "0.4.0",
"967942805137f9eb0ae26005d94e8285e2e288a0": "0.3.0",
"fbf2e115feae7ade26788e38ebf338af11a98bb2": "0.1.0"
}
}
},
"jPlayer": {
"bowername": [
"jPlayer"
Expand Down Expand Up @@ -1062,16 +1141,13 @@
},
{
"below": "4.9.7",
"severity": "medium",
"severity": "high",
"cwe": [
"CWE-79"
],
"identifiers": {
"summary": "TinyMCE before 4.9.7 and 5.x before 5.1.4 allows XSS in the core parser, the paste plugin, and the visualchars plugin by using the clipboard or APIs to insert content into the editor.",
"githubID": "GHSA-p7j5-4mwm-hv86",
"CVE": [
"CVE-2020-17480"
]
"githubID": "GHSA-p7j5-4mwm-hv86"
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-p7j5-4mwm-hv86"
Expand All @@ -1080,16 +1156,13 @@
{
"below": "5.1.4",
"atOrAbove": "5.0.0",
"severity": "medium",
"severity": "high",
"cwe": [
"CWE-79"
],
"identifiers": {
"summary": "TinyMCE before 4.9.7 and 5.x before 5.1.4 allows XSS in the core parser, the paste plugin, and the visualchars plugin by using the clipboard or APIs to insert content into the editor.",
"githubID": "GHSA-p7j5-4mwm-hv86",
"CVE": [
"CVE-2020-17480"
]
"githubID": "GHSA-p7j5-4mwm-hv86"
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-p7j5-4mwm-hv86"
Expand Down Expand Up @@ -1138,8 +1211,10 @@
],
"identifiers": {
"summary": "Cross-site scripting vulnerability in TinyMCE",
"retid": "63",
"githubID": "GHSA-vrv8-v4w8-f95h"
"githubID": "GHSA-vrv8-v4w8-f95h",
"CVE": [
"CVE-2020-12648"
]
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-vrv8-v4w8-f95h"
Expand All @@ -1154,8 +1229,10 @@
],
"identifiers": {
"summary": "Cross-site scripting vulnerability in TinyMCE",
"retid": "63",
"githubID": "GHSA-vrv8-v4w8-f95h"
"githubID": "GHSA-vrv8-v4w8-f95h",
"CVE": [
"CVE-2020-12648"
]
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-vrv8-v4w8-f95h"
Expand All @@ -1170,7 +1247,10 @@
],
"identifiers": {
"summary": "The vulnerability allowed arbitrary JavaScript execution when inserting a specially crafted piece of content into the editor via the clipboard or APIs",
"githubID": "GHSA-27gm-ghr9-4v95"
"githubID": "GHSA-27gm-ghr9-4v95",
"CVE": [
"CVE-2020-17480"
]
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-27gm-ghr9-4v95"
Expand All @@ -1184,7 +1264,10 @@
],
"identifiers": {
"summary": "The vulnerability allowed arbitrary JavaScript execution when inserting a specially crafted piece of content into the editor via the clipboard or APIs",
"githubID": "GHSA-27gm-ghr9-4v95"
"githubID": "GHSA-27gm-ghr9-4v95",
"CVE": [
"CVE-2020-17480"
]
},
"info": [
"https://github.com/tinymce/tinymce/security/advisories/GHSA-27gm-ghr9-4v95"
Expand Down
17 changes: 17 additions & 0 deletions sample-code/pmd-example-rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# PMD Example Rules
Salesforce Code Analyzer supports the use of custom PMD rules. If your custom PMD rules include Java code,
then you must compile your Java code into a JAR before you register it with Code Analyzer.

This project is an example of how to write Java-based PMD rules, and use Maven to compile them into a JAR.

## How do I build this project?
1. Install [Maven](https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html).
2. Clone the [Code Analyzer](https://github.com/forcedotcom/sfdx-scanner) project.
3. From the `sample-code/pmd-example-rules` directory, run `mvn clean package`.
4. Notice the new folder was created named `target`. It contains a file named `pmd-example-rules-1.0-SNAPSHOT.jar`.
5. From the `sample-code/pmd-example-rules` directory, run `sfdx scanner:rule:add --language apex --path ./target/pmd-example-rules-1.0-SNAPSHOT.jar`.
6. Run `scanner:rule:list --category CustomRules --engine pmd` to confirm the addition of the new rule.
7. Run `scanner:run --category CustomRules --engine pmd --target path/to/any/apexfile.cls` and view the new rule violation.

## What else can I do with this project?
Use this project as a template for how to define and build your own custom rules, categories, and rulesets.
78 changes: 78 additions & 0 deletions sample-code/pmd-example-rules/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is a sample POM file allowing this module to be compiled and bundled into a JAR via maven.
If you have Maven properly configured on your machine, you can run `mvn clean package` to build
a JAR containing everything needed to register and run a custom rule.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<!-- These two tags determine the name of the created JAR. -->
<artifactId>pmd-example-rules</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>6.55.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-apex</artifactId>
<version>6.55.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-apex-jorje</artifactId>
<version>6.55.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<includes>
<!-- Make sure to include all your custom Java. -->
<include>com/**/*.class</include>
<!-- Make sure to include all your custom category and ruleset XMLs. -->
<include>category/**/*.xml</include>
<include>rulesets/**/*.xml</include>
</includes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.pmd;

import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;

/**
* This class is an example for how one can write a custom PMD rule for Apex.
*/
public class ExampleCustomRule extends AbstractApexRule {

/**
* This is a sample implementation for a `visit()` method. It throws a violation
* for every Apex class it encounters. Your rule will probably be more interesting than this.
*/
@Override
public Object visit(ASTUserClass someClass, Object data) {
asCtx(data).addViolation(someClass);
return data;
}
}
Loading
Loading