Skip to content

Commit 0377c51

Browse files
authored
Merge branch 'fortify:dev/v3.x' into develop
2 parents f8f562e + 22a5498 commit 0377c51

File tree

8 files changed

+72
-44
lines changed

8 files changed

+72
-44
lines changed

fcli-core/fcli-action/src/main/resources/com/fortify/cli/generic_action/actions/build-time/ci-envvars.yaml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ formatters:
127127
`SETUP_EXTRA_OPTS`. To allow this action to create new applications, depending on FoD version,
128128
you may (also) need to provide the `--app-owner <user id or name>` option through `SETUP_EXTRA_OPTS`.
129129
scan:
130-
- names: DO_SAST_SCAN\nSAST_SCAN_EXTRA_OPTS\nDO_SAST_WAIT
130+
- names: DO_SAST_SCAN\nSAST_SCAN_EXTRA_OPTS
131131
desc: >-
132-
For now, this fcli action only supports running a SAST scan, which is enabled by default. The
133-
`SAST_SCAN_EXTRA_OPTS` environment variable can be used to pass extra options to the `fcli fod sast-scan start`
134-
command. By default, this action will wait until the scan has been completed, unless `DO_SAST_WAIT`
135-
is set to `false`; note that any post-scan tasks will be skipped in this case.
132+
The fcli `ci` action currently only supports running a SAST scan, which is enabled by default.
133+
The `SAST_SCAN_EXTRA_OPTS` environment variable can be used to provide additional options to the
134+
`fcli fod sast-scan start` command, for example to specify scan notes. Note that these environment
135+
variables only control the submission of the scan request; see the information below for details
136+
on waiting for the scan to complete.
137+
- names: DO_SAST_WAIT\nSAST_WAIT_EXTRA_OPTS
138+
desc: >-
139+
By default, the fcli `ci` action will wait for the SAST scan to complete. This behavior can be
140+
overridden by setting `DO_SAST_WAIT` to `false`, but note that doing so will skip any post-scan
141+
tasks. The `SAST_WAIT_EXTRA_OPTS` environment variable can be used to pass extra options to the
142+
`fcli fod sast-scan wait-for` command, for example to adjust the polling interval or timeout.
136143
postScan:
137144
- names: DO_RELEASE_SUMMARY\nRELEASE_SUMMARY_ACTION\nRELEASE_SUMMARY_EXTRA_OPTS
138145
desc: >-
@@ -201,12 +208,19 @@ formatters:
201208
application version representing your default branch by passing the `--copy-from` option through
202209
`SETUP_EXTRA_OPTS`.
203210
scan:
204-
- names: DO_SAST_SCAN\nSAST_SCAN_EXTRA_OPTS\nDO_SAST_WAIT
211+
- names: DO_SAST_SCAN\nSAST_SCAN_EXTRA_OPTS
212+
desc: >-
213+
The fcli `ci` action currently only supports running a SAST scan, which is enabled by default.
214+
The `SAST_SCAN_EXTRA_OPTS` environment variable can be used to provide additional options to
215+
the `fcli sc-sast scan start` command, for example to request a scan completion email notification.
216+
Note that these environment variables only control the submission of the scan request; see the
217+
information below for details on waiting for the scan to complete.
218+
- names: DO_SAST_WAIT\nSAST_WAIT_EXTRA_OPTS
205219
desc: >-
206-
For now, this fcli action only supports running a SAST scan, which is enabled by default. The
207-
`SAST_SCAN_EXTRA_OPTS` environment variable can be used to pass extra options to the `fcli sc-sast scan start`
208-
command. By default, this action will wait until the scan has been completed, unless `DO_SAST_WAIT`
209-
is set to `false`; note that any post-scan tasks will be skipped in this case.
220+
By default, the fcli `ci` action will wait for the SAST scan to complete. This behavior can be
221+
overridden by setting `DO_SAST_WAIT` to `false`, but note that doing so will skip any post-scan
222+
tasks. The `SAST_WAIT_EXTRA_OPTS` environment variable can be used to pass extra options to the
223+
`fcli sc-sast scan wait-for` command, for example to adjust the polling interval or timeout.
210224
postScan:
211225
- names: DO_APPVERSION_SUMMARY\nAPPVERSION_SUMMARY_ACTION\nAPPVERSION_SUMMARY_EXTRA_OPTS
212226
desc: >-

fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/runner/ActionRunner.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
package com.fortify.cli.common.action.runner;
1414

1515
import java.io.OutputStreamWriter;
16+
import java.util.Collections;
17+
import java.util.List;
1618
import java.util.Map;
1719

1820
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -50,7 +52,13 @@ public final Integer run(String[] args) {
5052
return _run(args);
5153
}
5254

55+
// TODO Review try/close/finally blocks and handling of output in delayed console writers
56+
// to see whether anything can be simplified, and whether there are any bugs.
5357
public final Integer _run(String[] args) {
58+
List<Runnable> delayedConsoleWriterRunnables = Collections.emptyList();
59+
Map<ActionStepCheckEntry, CheckStatus> checkStatuses = Collections.emptyMap();
60+
CheckStatus overallCheckstatus = CheckStatus.SKIP;
61+
int exitCode = 0;
5462
try ( var progressWriter = createProgressWriter() ) {
5563
var parameterValues = getParameterValues(args);
5664
try ( var ctx = createContext(progressWriter, parameterValues) ) {
@@ -59,14 +67,20 @@ public final Integer _run(String[] args) {
5967
try {
6068
new ActionStepProcessorSteps(ctx, vars, config.getAction().getSteps()).process();
6169
} finally {
62-
ctx.getDelayedConsoleWriterRunnables().forEach(Runnable::run);
63-
if ( !ctx.getCheckStatuses().isEmpty() ) {
64-
printCheckStatuses(ctx);
65-
}
70+
// Collect outputs from context; we can't write any of these outputs
71+
// until after the progress writer has been closed.
72+
delayedConsoleWriterRunnables = ctx.getDelayedConsoleWriterRunnables();
73+
checkStatuses = ctx.getCheckStatuses();
74+
exitCode = ctx.getExitCode();
6675
}
67-
return ctx.getExitCode();
6876
}
77+
} finally {
78+
// Write delayed console output and check statuses, now that progress writer has been closed
79+
delayedConsoleWriterRunnables.forEach(Runnable::run);
80+
overallCheckstatus = processAndPrintCheckStatuses(checkStatuses);
6981
}
82+
// Determine final exit code
83+
return exitCode==0 && overallCheckstatus==CheckStatus.FAIL ? 100 : exitCode;
7084
}
7185

7286
private IProgressWriterI18n createProgressWriter() {
@@ -105,17 +119,16 @@ private static final void initializeCheckStatuses(ActionRunnerContext ctx) {
105119
}
106120
}
107121

108-
private final void printCheckStatuses(ActionRunnerContext ctx) {
122+
private final CheckStatus processAndPrintCheckStatuses(Map<ActionStepCheckEntry, CheckStatus> checkStatuses) {
123+
if ( checkStatuses.isEmpty() ) { return CheckStatus.SKIP; }
109124
try ( var recordWriter = createCheckStatusWriter(); ) {
110-
ctx.getCheckStatuses().entrySet().stream()
125+
checkStatuses.entrySet().stream()
111126
.filter(e->e.getValue()!=CheckStatus.HIDE)
112127
.map(this::checkStatusAsObjectNode)
113128
.forEach(recordWriter::append);
114-
var overallStatus = CheckStatus.combine(ctx.getCheckStatuses().values());
129+
var overallStatus = CheckStatus.combine(checkStatuses.values());
115130
recordWriter.append(checkStatusAsObjectNode("Overall Status", overallStatus));
116-
if ( ctx.getExitCode()==0 && overallStatus==CheckStatus.FAIL ) {
117-
ctx.setExitCode(100);
118-
}
131+
return overallStatus;
119132
}
120133
}
121134

fcli-core/fcli-fod/src/main/resources/com/fortify/cli/fod/actions/zip/gitlab-dast-report.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ steps:
3232
uri: /api/v3/scans/${rel.currentDynamicScanId}/site-tree
3333
if: ${rel.currentDynamicScanId!=null}
3434
on.fail:
35-
- log.debug: "Site tree unavailable: ${exception.getMessage()}"
35+
- log.debug: "Site tree unavailable: ${siteTree_exception.getMessage()}"
3636
- log.progress: Processing issue data
3737
- rest.call:
3838
issues:
@@ -98,7 +98,7 @@ formatters:
9898
category: dast
9999
name: ${issue.category}
100100
message: ${issue.category}
101-
description: ${#abbreviate(#htmlToText(issue.details?.summary), 15000)}
101+
description: ${#abbreviate(#htmlToText(issue.details?.summary?:""), 15000)}
102102
cve: 'N/A'
103103
severity: ${{'Critical':'Critical','High':'High','Medium':'Medium','Low':'Low','Best Practice':'Info','Info':'Info'}.get(issue.severityString)?:'Unknown'}
104104
confidence: ${(issue.severityString matches "(Critical|Medium)") ? "High":"Low" }

fcli-core/fcli-fod/src/main/resources/com/fortify/cli/fod/actions/zip/gitlab-sast-report.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ steps:
6060

6161
formatters:
6262
gitlab-sast-report:
63-
schema: https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/raw/v15.0.0/dist/sast-report-format.json
64-
version: 15.0.0
63+
schema: https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/raw/v15.2.1/dist/sast-report-format.json
64+
version: 15.2.1
6565
scan:
6666
start_time: ${#formatDateTime("yyyy-MM-dd'T'HH:mm:ss", staticScanSummary?.startedDateTime?:'1970-01-01T00:00:00')}
6767
end_time: ${#formatDateTime("yyyy-MM-dd'T'HH:mm:ss", staticScanSummary?.completedDateTime?:'1970-01-01T00:00:00')}
@@ -84,11 +84,18 @@ formatters:
8484
vulnerabilities: ${vulnerabilities?:{}}
8585

8686
vulnerabilities:
87+
id: ${issue.vulnId}
8788
category: sast
88-
confidence: ${(issue.severityString matches "(Critical|Medium)") ? "High":"Low" }
89+
name: ${issue.category}
90+
message: ${issue.category}
8991
description: ${#abbreviate(#htmlToText(issue.details?.summary?:""), 15000)}
90-
id: ${issue.vulnId}
9192
cve: 'N/A'
93+
severity: ${issue.severityString}
94+
confidence: ${(issue.severityString matches "(Critical|Medium)") ? "High":"Low" }
95+
solution: ${#abbreviate(#htmlToText(issue.details?.explanation)+'\n\n'+#htmlToText(issue.recommendations?.recommendations), 7000)}
96+
scanner:
97+
id: FoD-SAST
98+
name: Fortify on Demand
9299
identifiers: |-
93100
${{
94101
{
@@ -98,16 +105,9 @@ formatters:
98105
value: issue.instanceId
99106
}
100107
}}
101-
location:
102-
file: ${issueSourceFileResolver.resolve(issue.primaryLocationFull)}
103-
start_line: ${issue.lineNumber}
104108
links:
105109
- name: Additional issue details, including analysis trace, in Fortify on Demand
106110
url: ${#fod.issueBrowserUrl(issue)}
107-
message: ${issue.category}
108-
name: ${issue.category}
109-
scanner:
110-
id: FoD-SAST
111-
name: Fortify on Demand
112-
severity: ${issue.severityString}
113-
solution: ${#abbreviate(#htmlToText(issue.details?.explanation)+'\n\n'+#htmlToText(issue.recommendations?.recommendations), 7000)}
111+
location:
112+
file: ${issueSourceFileResolver.resolve(issue.primaryLocationFull)}
113+
start_line: ${issue.lineNumber==0?1:issue.lineNumber}

fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/actions/zip/gitlab-dast-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ formatters:
110110
category: sast
111111
name: ${issue.issueName}
112112
message: ${issue.issueName}
113-
description: ${#abbreviate(#htmlToText(issue.details?.brief), 15000)}
113+
description: ${#abbreviate(#htmlToText(issue.details?.brief?:""), 15000)}
114114
cve: 'N/A'
115115
severity: ${issue.friority}
116116
confidence: ${(issue.friority matches "(Critical|Medium)") ? "High":"Low" }

fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/actions/zip/gitlab-debricked-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ formatters:
100100
category: dependency_scanning
101101
name: ${issue.issueName}
102102
message: ${issue.issueName}
103-
description: ${#abbreviate(#htmlToText(issue.details?.brief), 15000)}
103+
description: ${#abbreviate(#htmlToText(issue.details?.brief?:""), 15000)}
104104
cve: ${issue.details?.customAttributes?.externalId}
105105
severity: ${issue.friority}
106106
confidence: ${(issue.friority matches "(Critical|Medium)") ? "High":"Low" }

fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/actions/zip/gitlab-sast-report.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ steps:
7777

7878
formatters:
7979
gitlab-sast-report:
80-
schema: https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/raw/v15.0.0/dist/sast-report-format.json
81-
version: 15.0.0
80+
schema: https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/raw/v15.2.1/dist/sast-report-format.json
81+
version: 15.2.1
8282
scan:
8383
start_time: ${#formatDateTime("yyyy-MM-dd'T'HH:mm:ss", lastStaticScan?.uploadDate?:'1970-01-01T00:00:00')}
8484
end_time: ${#formatDateTime("yyyy-MM-dd'T'HH:mm:ss", lastStaticScan?.uploadDate?:'1970-01-01T00:00:00')}
@@ -104,7 +104,7 @@ formatters:
104104
category: sast
105105
name: ${issue.issueName}
106106
message: ${issue.issueName}
107-
description: ${#abbreviate(#htmlToText(issue.details?.brief), 15000)}
107+
description: ${#abbreviate(#htmlToText(issue.details?.brief?:""), 15000)}
108108
cve: 'N/A'
109109
severity: ${issue.friority}
110110
confidence: ${(issue.friority matches "(Critical|Medium)") ? "High":"Low"}
@@ -124,4 +124,5 @@ formatters:
124124
url: ${issue.details?.appSecTrainingUrl}
125125
location:
126126
file: ${issueSourceFileResolver.resolve(issue.fullFileName)}
127-
start_line: ${issue.lineNumber}
127+
start_line: ${issue.lineNumber==0?1:issue.lineNumber}
128+

fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/actions/zip/gitlab-sonatype-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ formatters:
9999
category: dependency_scanning
100100
name: ${issue.issueName}
101101
message: ${issue.issueName}
102-
description: ${#abbreviate(#htmlToText(issue.details?.brief), 15000)}
102+
description: ${#abbreviate(#htmlToText(issue.details?.brief?:""), 15000)}
103103
cve: 'N/A'
104104
severity: ${issue.friority}
105105
confidence: ${(issue.friority matches "(Critical|Medium)") ? "High":"Low" }

0 commit comments

Comments
 (0)