Skip to content

Commit a7f51a2

Browse files
authored
Merge pull request #14 from datatheorem/wait-for-dynamic-results
By default, wait for DAST results when checking the scan status. Added a new input parameter WAIT_FOR_STATIC_SCAN_ONLY to action.yml, allowing users to specify if the action should wait for the static scan to complete instead of the top-level scan.
2 parents 32a53f9 + 8e1551c commit a7f51a2

3 files changed

Lines changed: 44 additions & 10 deletions

File tree

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ inputs:
6868
description: >
6969
Stop polling the scan result after the specified time in seconds, default is 5 minutes.
7070
required: false
71+
WAIT_FOR_STATIC_SCAN_ONLY:
72+
description: >
73+
When enabled, waits for the static_scan to be COMPLETED instead of the top-level scan. Default is false.
74+
required: false
7175
runs:
7276
using: 'node20'
7377
main: 'main.js'

main.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function run() {
107107
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
108108
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
109109
const polling_timeout = core.getInput("POLLING_TIMEOUT");
110+
const wait_for_static_scan_only = core.getInput("WAIT_FOR_STATIC_SCAN_ONLY");
110111
var parsed_polling_timeout;
111112
if (polling_timeout) {
112113
parsed_polling_timeout = parseInt(polling_timeout, 10);
@@ -269,6 +270,9 @@ function run() {
269270
if (warn_on_severity) {
270271
console.log(`Warning on vulnerabilities with minimum severity: ${warn_on_severity}`);
271272
}
273+
if (wait_for_static_scan_only === 'true') {
274+
console.log('WAIT_FOR_STATIC_SCAN_ONLY is enabled: will wait for static_scan completion');
275+
}
272276
for (const scan of scan_info) {
273277
const { mobile_app_id, scan_id } = scan;
274278
var maxWaitTime = 300000; // 5 minutes
@@ -292,15 +296,27 @@ function run() {
292296
continue;
293297
}
294298
const status_data = yield status_response.json();
295-
const scan_status = ((_a = status_data.static_scan) === null || _a === void 0 ? void 0 : _a.status) || status_data.status;
299+
// Check status based on WAIT_FOR_STATIC_SCAN_ONLY parameter
300+
let scan_status;
301+
if (wait_for_static_scan_only === 'true') {
302+
if ((_a = status_data.static_scan) === null || _a === void 0 ? void 0 : _a.status) {
303+
scan_status = status_data.static_scan.status;
304+
}
305+
else {
306+
console.log(`static_scan field not available for scan ${scan_id}, falling back to overall scan status`);
307+
scan_status = status_data.status;
308+
}
309+
}
310+
else {
311+
scan_status = status_data.status;
312+
}
296313
if (scan_status &&
297314
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)) {
298315
console.log(`Scan ${scan_id} failed, skipping vulnerability check`);
299316
break;
300317
}
301-
if (!status_data.static_scan ||
302-
status_data.static_scan.status !== "COMPLETED") {
303-
console.log(`Scan ${scan_id} still in progress, waiting...`);
318+
if (scan_status !== "COMPLETED") {
319+
console.log(`Scan ${scan_id} still in progress (current status: ${scan_status}), waiting...`);
304320
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
305321
continue;
306322
}

main.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async function run() {
126126
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
127127
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
128128
const polling_timeout = core.getInput("POLLING_TIMEOUT");
129+
const wait_for_static_scan_only = core.getInput("WAIT_FOR_STATIC_SCAN_ONLY");
129130
var parsed_polling_timeout;
130131
if (polling_timeout) {
131132
parsed_polling_timeout = parseInt(polling_timeout, 10);
@@ -325,6 +326,10 @@ async function run() {
325326
);
326327
}
327328

329+
if (wait_for_static_scan_only === 'true') {
330+
console.log('WAIT_FOR_STATIC_SCAN_ONLY is enabled: will wait for static_scan completion');
331+
}
332+
328333
for (const scan of scan_info) {
329334
const { mobile_app_id, scan_id } = scan;
330335

@@ -363,7 +368,19 @@ async function run() {
363368
}
364369

365370
const status_data = await status_response.json();
366-
const scan_status = status_data.static_scan?.status || status_data.status;
371+
// Check status based on WAIT_FOR_STATIC_SCAN_ONLY parameter
372+
let scan_status;
373+
if (wait_for_static_scan_only === 'true') {
374+
if (status_data.static_scan?.status) {
375+
scan_status = status_data.static_scan.status;
376+
} else {
377+
console.log(`static_scan field not available for scan ${scan_id}, falling back to overall scan status`);
378+
scan_status = status_data.status;
379+
}
380+
} else {
381+
scan_status = status_data.status;
382+
}
383+
367384
if (
368385
scan_status &&
369386
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)
@@ -372,11 +389,8 @@ async function run() {
372389
break;
373390
}
374391

375-
if (
376-
!status_data.static_scan ||
377-
status_data.static_scan.status !== "COMPLETED"
378-
) {
379-
console.log(`Scan ${scan_id} still in progress, waiting...`);
392+
if (scan_status !== "COMPLETED") {
393+
console.log(`Scan ${scan_id} still in progress (current status: ${scan_status}), waiting...`);
380394
await new Promise((resolve) => setTimeout(resolve, pollInterval));
381395
continue;
382396
}

0 commit comments

Comments
 (0)