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

guard against the possibility of no links being provided #69

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

alfredodeza
Copy link
Contributor

Closes #68

/cc @jonico

index.js Outdated
@@ -221,6 +221,12 @@ function grype_render_rules(vulnerabilities) {
let ruleID = "ANCHOREVULN_"+v.vulnerability.id+"_"+v.artifact.type+"_"+v.artifact.name+"_"+v.artifact.version;
if (!ruleIDs.includes(ruleID)) {
ruleIDs.push(ruleID);
// Entirely possible to not have any links whatsoever
var link = v.vulnerability.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but in general var should never be used, and it's safe to use let in its place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slipped on this one and have updated it to fix it. I ran tests locally against the reproducer, and it passed

@@ -221,6 +221,12 @@ function grype_render_rules(vulnerabilities) {
let ruleID = "ANCHOREVULN_"+v.vulnerability.id+"_"+v.artifact.type+"_"+v.artifact.name+"_"+v.artifact.version;
if (!ruleIDs.includes(ruleID)) {
ruleIDs.push(ruleID);
// Entirely possible to not have any links whatsoever
var link = v.vulnerability.id;
if ("links" in v.vulnerability) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this style of check before, but that doesn't mean it's wrong. I usually see checks for property's existence in the form of if (typeof v.vulnerability.links !== "undefined") ...

"markdown": "**Vulnerability "+v.vulnerability.id+"**\n"+
"| Severity | Package | Version | Fix Version | Type | Location | Data Namespace | Link |\n"+
"| --- | --- | --- | --- | --- | --- | --- | --- |\n"+
"|"+v.vulnerability.severity+"|"+v.artifact.name+"|"+v.artifact.version+"|"+"unknown"+"|"+v.artifact.type+"|"+v.artifact.locations[0].path+"|"+"unknown"+"|["+v.vulnerability.id+"]("+v.vulnerability.links[0]+")|\n"
"|"+v.vulnerability.severity+"|"+v.artifact.name+"|"+v.artifact.version+"|"+"unknown"+"|"+v.artifact.type+"|"+v.artifact.locations[0].path+"|"+"unknown"+"|"+link+"|\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole line might read easier as a template, and with values separated out. For example:

const { severity } = v.vulnerability;
const { name, version, type, locations } = v.artifact;
const { path } = locations[0];

// ...

`|${severity}|${name}|${version}|unknown|${type}|${path}|unknown|${link}|\n`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I've started using templates as I carve out changes. This whole file needs to use more templates. Do note that I have captured that feedback and created #51 to track it.

@alfredodeza alfredodeza merged commit 30be91c into main Nov 2, 2020
@alfredodeza alfredodeza deleted the undefined-links branch November 2, 2020 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing object attributes in JSON reporting from grype break the action
2 participants