Skip to content

Commit

Permalink
Add by-cve option (#229)
Browse files Browse the repository at this point in the history
* Add by-cve option to action options

Signed-off-by: too-gee <116376+too-gee@users.noreply.github.com>

* chore: update audit to use npm-better-audit
* chore: modify workflow to use new audit script

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>

---------

Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: too-gee <116376+too-gee@users.noreply.github.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Co-authored-by: Keith Zantow <kzantow@gmail.com>
Co-authored-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
3 people authored Jul 6, 2023
1 parent 487706f commit 355bbe9
Show file tree
Hide file tree
Showing 10 changed files with 1,285 additions and 1,017 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm audit --production
- run: npm run audit
- run: npm run build
- run: git status --porcelain
- run: git diff
Expand Down Expand Up @@ -36,5 +36,5 @@ jobs:
docker buildx imagetools inspect localhost:5000/match-coverage/$distro:latest
done
- run: npm ci
- run: npm audit --production
- run: npm run audit
- run: npm test
6 changes: 6 additions & 0 deletions .nsprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"1092310": {
"active": true,
"notes": "Ignored since we don't use the vulnerable regex method"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ The inputs `image`, `path`, and `sbom` are mutually exclusive to specify the sou
| `severity-cutoff` | Optionally specify the minimum vulnerability severity to trigger a failure. Valid choices are "negligible", "low", "medium", "high" and "critical". Any vulnerability with a severity less than this value will lead to a "warning" result. Default is "medium". | `medium` |
| `only-fixed` | Specify whether to only report vulnerabilities that have a fix available. | `false` |
| `add-cpes-if-none` | Specify whether to autogenerate missing CPEs. | `false` |
| `by-cve` | Specify whether to orient results by CVE rather than GHSA. | `false` |

### Action Outputs

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inputs:
description: "Specify whether to autogenerate missing CPEs. Default is false."
required: false
default: "false"
by-cve:
description: "Specify whether to orient results by CVE rather than GHSA. Default is false."
required: false
default: "false"
outputs:
sarif:
description: "Path to a SARIF report file for the image"
Expand Down
17 changes: 16 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ async function run() {
const severityCutoff = core.getInput("severity-cutoff") || "medium";
const onlyFixed = core.getInput("only-fixed") || "false";
const addCpesIfNone = core.getInput("add-cpes-if-none") || "false";
const byCve = core.getInput("by-cve") || "false";
const out = await runScan({
source,
failBuild,
severityCutoff,
onlyFixed,
outputFormat,
addCpesIfNone,
byCve,
});
Object.keys(out).map((key) => {
core.setOutput(key, out[key]);
Expand All @@ -121,7 +123,15 @@ async function run() {
}
}

async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFormat, addCpesIfNone }) {
async function runScan({
source,
failBuild,
severityCutoff,
onlyFixed,
outputFormat,
addCpesIfNone,
byCve,
}) {
const out = {};

const env = {
Expand Down Expand Up @@ -153,6 +163,7 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
failBuild = failBuild.toLowerCase() === "true";
onlyFixed = onlyFixed.toLowerCase() === "true";
addCpesIfNone = addCpesIfNone.toLowerCase() === "true";
byCve = byCve.toLowerCase() === "true";

cmdArgs.push("-o", outputFormat);

Expand Down Expand Up @@ -187,6 +198,7 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
core.debug("Severity Cutoff: " + severityCutoff);
core.debug("Only Fixed: " + onlyFixed);
core.debug("Add Missing CPEs: " + addCpesIfNone);
core.debug("Orient by CVE: " + byCve);
core.debug("Output Format: " + outputFormat);

core.debug("Creating options for GRYPE analyzer");
Expand All @@ -204,6 +216,9 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
if (addCpesIfNone === true) {
cmdArgs.push("--add-cpes-if-none");
}
if (byCve === true) {
cmdArgs.push("--by-cve");
}
cmdArgs.push(source);

// This /dev/null writable stream is required so the entire Grype output
Expand Down
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ async function run() {
const severityCutoff = core.getInput("severity-cutoff") || "medium";
const onlyFixed = core.getInput("only-fixed") || "false";
const addCpesIfNone = core.getInput("add-cpes-if-none") || "false";
const byCve = core.getInput("by-cve") || "false";
const out = await runScan({
source,
failBuild,
severityCutoff,
onlyFixed,
outputFormat,
addCpesIfNone,
byCve,
});
Object.keys(out).map((key) => {
core.setOutput(key, out[key]);
Expand All @@ -107,7 +109,15 @@ async function run() {
}
}

async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFormat, addCpesIfNone }) {
async function runScan({
source,
failBuild,
severityCutoff,
onlyFixed,
outputFormat,
addCpesIfNone,
byCve,
}) {
const out = {};

const env = {
Expand Down Expand Up @@ -139,6 +149,7 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
failBuild = failBuild.toLowerCase() === "true";
onlyFixed = onlyFixed.toLowerCase() === "true";
addCpesIfNone = addCpesIfNone.toLowerCase() === "true";
byCve = byCve.toLowerCase() === "true";

cmdArgs.push("-o", outputFormat);

Expand Down Expand Up @@ -173,6 +184,7 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
core.debug("Severity Cutoff: " + severityCutoff);
core.debug("Only Fixed: " + onlyFixed);
core.debug("Add Missing CPEs: " + addCpesIfNone);
core.debug("Orient by CVE: " + byCve);
core.debug("Output Format: " + outputFormat);

core.debug("Creating options for GRYPE analyzer");
Expand All @@ -190,6 +202,9 @@ async function runScan({ source, failBuild, severityCutoff, onlyFixed, outputFor
if (addCpesIfNone === true) {
cmdArgs.push("--add-cpes-if-none");
}
if (byCve === true) {
cmdArgs.push("--by-cve");
}
cmdArgs.push(source);

// This /dev/null writable stream is required so the entire Grype output
Expand Down
Loading

0 comments on commit 355bbe9

Please sign in to comment.