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

Add sarif file existence to outputs #87

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- uses: actions/checkout@v4

- name: Nuclei - Vulnerability Scan
id: nuclei_scan
uses: projectdiscovery/nuclei-action@main
with:
target: https://example.com
Expand All @@ -38,8 +39,11 @@ jobs:

- name: GitHub Security Dashboard Alerts update
uses: github/codeql-action/upload-sarif@v3
if: steps.nuclei_scan.outputs.sarif_exists == 'true'
with:
sarif_file: nuclei.sarif
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

**GitHub Action running Nuclei on single URL**
Expand Down Expand Up @@ -172,14 +176,18 @@ github:

```yaml
- name: Nuclei - Vulnerability Scan
id: nuclei_scan
uses: projectdiscovery/nuclei-action@main
with:
target: https://example.com

- name: GitHub Security Dashboard Alerts
- name: GitHub Security Dashboard Alerts update
uses: github/codeql-action/upload-sarif@v3
if: steps.nuclei_scan.outputs.sarif_exists == 'true'
with:
sarif_file: nuclei.sarif
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

Available Inputs
Expand Down
11 changes: 9 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10788,6 +10788,7 @@ function parseFlagsToArray(rawFlags) {



const fs = __nccwpck_require__(7147);

const target = core.getInput('target', { required: false });
const urls = core.getInput('urls', { required: false });
Expand Down Expand Up @@ -10847,7 +10848,8 @@ async function run() {
}
}
if (workflows) params.push(`-w=${workflows}`);
params.push(`-se=${sarifExport ? sarifExport : 'nuclei.sarif'}`);
const sarifFileName = sarifExport ? sarifExport : 'nuclei.sarif';
params.push(`-se=${sarifFileName}`);
if (markdownExport) params.push(`-me=${markdownExport}`);
if (config) params.push(`-config=${config}`);
if (userAgent) params.push(`-H=${userAgent}`);
Expand All @@ -10870,7 +10872,12 @@ async function run() {

// run tool
delete process.env.GITHUB_TOKEN
exec.exec(binPath, params, options);
await exec.exec(binPath, params, options);
if (fs.existsSync(sarifFileName)) {
core.setOutput('sarif_exists', 'true');
} else {
core.setOutput('sarif_exists', 'false');
}
} catch (error) {
core.setFailed(error.message);
}
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as exec from '@actions/exec';
import * as installer from './installer';
import { generateGithubReportFile } from './yaml';
import { parseFlagsToArray } from './utils';
const fs = require('fs');

const target = core.getInput('target', { required: false });
const urls = core.getInput('urls', { required: false });
Expand Down Expand Up @@ -62,7 +63,8 @@ async function run() {
}
}
if (workflows) params.push(`-w=${workflows}`);
params.push(`-se=${sarifExport ? sarifExport : 'nuclei.sarif'}`);
const sarifFileName = sarifExport ? sarifExport : 'nuclei.sarif';
params.push(`-se=${sarifFileName}`);
if (markdownExport) params.push(`-me=${markdownExport}`);
if (config) params.push(`-config=${config}`);
if (userAgent) params.push(`-H=${userAgent}`);
Expand All @@ -85,7 +87,12 @@ async function run() {

// run tool
delete process.env.GITHUB_TOKEN
exec.exec(binPath, params, options);
await exec.exec(binPath, params, options);
if (fs.existsSync(sarifFileName)) {
core.setOutput('sarif_exists', 'true');
} else {
core.setOutput('sarif_exists', 'false');
}
} catch (error) {
core.setFailed(error.message);
}
Expand Down