Skip to content

Commit 6a06126

Browse files
committed
cb
1 parent ee9d615 commit 6a06126

23 files changed

+276
-1262
lines changed

src/main/rules/APIVersion.ts

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
1-
import * as core from "../internals/internals";
2-
import { AdvancedRule } from "../models/AdvancedRule";
3-
4-
export class APIVersion extends AdvancedRule implements core.IRuleDefinition {
5-
constructor() {
6-
super({
7-
name: "APIVersion",
8-
label: "Outdated API Version",
9-
description:
10-
"Introducing newer API components may lead to unexpected issues with older versions of Flows, as they might not align with the underlying mechanics. Starting from API version 50.0, the 'Api Version' attribute has been readily available on the Flow Object. To ensure smooth operation and reduce discrepancies between API versions, it is strongly advised to regularly update and maintain them.",
11-
supportedTypes: core.FlowType.allTypes(),
12-
docRefs: [],
13-
isConfigurable: true,
14-
autoFixable: false,
15-
});
16-
}
17-
18-
public execute(flow: core.Flow, options?: { expression: string }): core.RuleResult {
19-
let flowAPIVersionNumber: number | null = null;
20-
if (flow.xmldata.apiVersion) {
21-
const flowAPIVersion = flow.xmldata.apiVersion;
22-
flowAPIVersionNumber = +flowAPIVersion;
23-
}
24-
const results: core.ResultDetails[] = [];
25-
if (!flowAPIVersionNumber) {
26-
results.push(
27-
new core.ResultDetails(new core.FlowAttribute("API Version <49", "apiVersion", "<49"))
28-
);
29-
30-
return new core.RuleResult(this, results);
31-
}
32-
if (options && options.expression) {
33-
// eslint-disable-next-line sonarjs/code-eval
34-
const isApiNumberMoreThanConfiguredExpression = new Function(
35-
`return ${flowAPIVersionNumber}${options.expression};`
36-
);
37-
if (!isApiNumberMoreThanConfiguredExpression()) {
38-
results.push(
39-
new core.ResultDetails(
40-
new core.FlowAttribute(`${flowAPIVersionNumber}`, "apiVersion", options.expression)
41-
)
42-
);
43-
}
44-
}
45-
46-
return new core.RuleResult(this, results);
47-
}
48-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
import { FlowType, IRuleDefinition } from "../internals/internals";
2-
import { LoopRuleCommon } from "../models/LoopRuleCommon";
3-
4-
export class ActionCallsInLoop extends LoopRuleCommon implements IRuleDefinition {
5-
constructor() {
6-
super(
7-
{
8-
autoFixable: false,
9-
description:
10-
"To prevent exceeding Apex governor limits, it is advisable to consolidate and bulkify your apex calls, utilize a single action call containing a collection variable at the end of the loop.",
11-
docRefs: [
12-
{
13-
label: "Invocable Method Considerations",
14-
path: "https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm",
15-
},
16-
],
17-
isConfigurable: false,
18-
label: "**Beta** Action Calls In Loop",
19-
name: "ActionCallsInLoop",
20-
supportedTypes: FlowType.backEndTypes,
21-
},
22-
{ severity: "warning" }
23-
);
24-
}
25-
26-
protected getStatementTypes(): string[] {
27-
return ["actionCalls", "apexPluginCalls"];
28-
}
29-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/

src/main/rules/AutoLayout.ts

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,12 @@
1-
import * as core from "../internals/internals";
2-
import { AdvancedRule } from "../models/AdvancedRule";
3-
4-
export class AutoLayout extends AdvancedRule implements core.IRuleDefinition {
5-
constructor() {
6-
super({
7-
name: "AutoLayout",
8-
label: "Auto-Layout Mode",
9-
description:
10-
"With Canvas Mode set to Auto-Layout, Elements are spaced, connected, and aligned automatically, keeping your Flow neatly organized thus saving you time.",
11-
supportedTypes: core.FlowType.allTypes(),
12-
docRefs: [],
13-
isConfigurable: true,
14-
autoFixable: false,
15-
});
16-
}
17-
18-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
19-
public execute(flow: core.Flow, options?: { expression: string }): core.RuleResult {
20-
if (flow.processMetadataValues) {
21-
const CanvasMode = flow.xmldata.processMetadataValues.find(
22-
(mdv) => mdv.name === "CanvasMode"
23-
);
24-
const autoLayout =
25-
CanvasMode.value &&
26-
typeof CanvasMode.value === "object" &&
27-
CanvasMode.value.stringValue &&
28-
CanvasMode.value.stringValue === "AUTO_LAYOUT_CANVAS";
29-
return !autoLayout
30-
? new core.RuleResult(this, [
31-
new core.ResultDetails(
32-
new core.FlowAttribute(
33-
CanvasMode.value?.stringValue,
34-
"CanvasMode",
35-
"!== AUTO_LAYOUT_CANVAS"
36-
)
37-
),
38-
])
39-
: new core.RuleResult(this, []);
40-
}
41-
return new core.RuleResult(this, []);
42-
}
43-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/

src/main/rules/CopyAPIName.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
1-
import * as core from "../internals/internals";
2-
import { AdvancedRule } from "../models/AdvancedRule";
3-
4-
export class CopyAPIName extends AdvancedRule implements core.IRuleDefinition {
5-
constructor() {
6-
super({
7-
name: "CopyAPIName",
8-
label: "Copy API Name",
9-
description:
10-
"Maintaining multiple elements with a similar name, like 'Copy_X_Of_Element,' can diminish the overall readability of your Flow. When copying and pasting these elements, it's crucial to remember to update the API name of the newly created copy.",
11-
supportedTypes: core.FlowType.allTypes(),
12-
docRefs: [],
13-
isConfigurable: false,
14-
autoFixable: false,
15-
});
16-
}
17-
18-
public execute(flow: core.Flow): core.RuleResult {
19-
const flowElements: core.FlowNode[] = flow.elements.filter(
20-
(node) => node instanceof core.FlowNode
21-
) as core.FlowNode[];
22-
const copyOfElements = [];
23-
for (const element of flowElements) {
24-
// eslint-disable-next-line sonarjs/concise-regex
25-
const copyOf = new RegExp("Copy_[0-9]+_of_[A-Za-z0-9]+").test(element.name);
26-
if (copyOf) {
27-
copyOfElements.push(element);
28-
}
29-
}
30-
const results = [];
31-
for (const det of copyOfElements) {
32-
results.push(new core.ResultDetails(det));
33-
}
34-
return new core.RuleResult(this, results);
35-
}
36-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/
Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,12 @@
1-
import { AdvancedRule } from "../models/AdvancedRule";
2-
import * as core from "../internals/internals";
3-
4-
export class CyclomaticComplexity extends AdvancedRule implements core.IRuleDefinition {
5-
constructor() {
6-
super(
7-
{
8-
name: "CyclomaticComplexity",
9-
label: "Cyclomatic Complexity",
10-
description: `The number of loops and decision rules, plus the number of decisions. Use a combination of 1) subflows and 2) breaking flows into multiple concise trigger ordered flows, to reduce the cyclomatic complexity within a single flow, ensuring maintainability and simplicity.`,
11-
supportedTypes: core.FlowType.backEndTypes,
12-
docRefs: [
13-
{
14-
label: `Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code.`,
15-
path: "https://en.wikipedia.org/wiki/Cyclomatic_complexity",
16-
},
17-
],
18-
isConfigurable: true,
19-
autoFixable: false,
20-
},
21-
{ severity: "note" }
22-
);
23-
}
24-
25-
private defaultThreshold: number = 25;
26-
27-
private cyclomaticComplexityUnit: number = 0;
28-
29-
public execute(flow: core.Flow, options?: { threshold: number }): core.RuleResult {
30-
// Set Threshold
31-
const threshold = options?.threshold || this.defaultThreshold;
32-
33-
// Calculate Cyclomatic Complexity based on the number of decision rules and loops, adding the number of decisions plus 1.
34-
let cyclomaticComplexity = 1;
35-
36-
const flowDecisions = flow?.elements?.filter(
37-
(node) => node.subtype === "decisions"
38-
) as core.FlowElement[];
39-
const flowLoops = flow?.elements?.filter((node) => node.subtype === "loops");
40-
41-
for (const decision of flowDecisions || []) {
42-
const rules = decision.element["rules"];
43-
if (Array.isArray(rules)) {
44-
cyclomaticComplexity += rules.length + 1;
45-
} else {
46-
cyclomaticComplexity += 1;
47-
}
48-
}
49-
cyclomaticComplexity += flowLoops?.length ?? 0;
50-
51-
this.cyclomaticComplexityUnit = cyclomaticComplexity; // for unit testing
52-
53-
const results: core.ResultDetails[] = [];
54-
if (cyclomaticComplexity > threshold) {
55-
results.push(
56-
new core.ResultDetails(
57-
new core.FlowAttribute(`${cyclomaticComplexity}`, "CyclomaticComplexity", `>${threshold}`)
58-
)
59-
);
60-
}
61-
return new core.RuleResult(this, results);
62-
}
63-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/
Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
import { FlowType, IRuleDefinition } from "../internals/internals";
2-
import { LoopRuleCommon } from "../models/LoopRuleCommon";
3-
4-
export class DMLStatementInLoop extends LoopRuleCommon implements IRuleDefinition {
5-
constructor() {
6-
super({
7-
autoFixable: false,
8-
description:
9-
"To prevent exceeding Apex governor limits, it is advisable to consolidate all your database operations, including record creation, updates, or deletions, at the conclusion of the flow.",
10-
docRefs: [
11-
{
12-
label: "Flow Best Practices",
13-
path: "https://help.salesforce.com/s/articleView?id=sf.flow_prep_bestpractices.htm&type=5",
14-
},
15-
],
16-
isConfigurable: false,
17-
label: "DML Statement In A Loop",
18-
name: "DMLStatementInLoop",
19-
supportedTypes: FlowType.backEndTypes,
20-
});
21-
}
22-
23-
protected getStatementTypes(): string[] {
24-
return ["recordDeletes", "recordUpdates", "recordCreates"];
25-
}
26-
}
1+
/**
2+
* ⚠️ WARNING!
3+
*
4+
* This is a version of Flow Scanner that contains known vulnerabilities.
5+
*
6+
* Please use a version >= 5.1.0 immidiately.
7+
* Failure to upgrade may expose your project to security risks.
8+
*
9+
* Follow 👉 https://github.com/Flow-Scanner/
10+
* Details 👉 https://github.com/orgs/Flow-Scanner/discussions/263
11+
*
12+
*/

0 commit comments

Comments
 (0)