Skip to content

bom.vulnerabilities model #163

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

Closed

Conversation

thepwagner
Copy link
Contributor

@thepwagner thepwagner commented Aug 6, 2022

Add Vulnerabilties to the Bom model, including enums as needed.

The implementation is styled after the existing Component implementation and tests.

this is part of #164

Signed-off-by: Peter Wagner <[email protected]>
@thepwagner thepwagner requested a review from a team as a code owner August 6, 2022 17:55
@jkowalleck jkowalleck added the enhancement New feature or request label Aug 7, 2022
@jkowalleck
Copy link
Member

jkowalleck commented Aug 7, 2022

Thank you for this feature, @thepwagner

Review will take a while, did a part of it already.

Are you planning on implementing the JSON- and XML normalizer, too?

@jkowalleck jkowalleck changed the title Bom.Vulnerabilities model bom.vulnerabilities model Aug 7, 2022
Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

partial review.

please find critical remarks with an ❌ .
other remarks are discussion items.

Copyright (c) OWASP Foundation. All Rights Reserved.
*/

export enum VulnerabilityAnalysisResponse {
Copy link
Member

Choose a reason for hiding this comment

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

rename to ImpactAnalysisResponsesType as the XML schema defines?

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 switched to ImpactAnalysisResponse as this was the most consistent with the JSON schema, even if the JSON schema doesn't give this enum a standalone definition.

Please advise if you'd prefer a different name.

@thepwagner
Copy link
Contributor Author

@jkowalleck thank you for the quick initial feedback!
I've addressed feedback and resolved the threads I think are resolved - please advise if you'd prefer to resolve after verifying the fixes.

  • I made all suggested renames, biased towards the naming of the JSON schema.
  • I've extended the compare() methods to consider all fields, including nested sets like Set<URL | string> or SortableSet<VulnerabilityReference>. This meant adding a generic SortableSet.compare()
  • Using the JSON schema for functional tests is cool! I extended the name-mapping helper to support snake_case since there was no feedback on the naming of enum values in the first review.

I was not intending to implement the normalizers.

@jkowalleck jkowalleck mentioned this pull request Aug 8, 2022
Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

please find critical chaneg requests marked with ❌ '
everything else is a discussion item.

everything is just my opinionated view, lets discuss :)

Copyright (c) OWASP Foundation. All Rights Reserved.
*/

export enum AffectedStatus {
Copy link
Member

Choose a reason for hiding this comment

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

re: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/163/files/542767bab211a12fa71d209e88978e2b4f49c3bf#r939618319

👍 lets keep it as enum AffectedStatus.

alternative enum ImpactAnalysisAffectedStatus might get in conflict with enum ImpactAnalysisState which already has a value NotAffected.

compare (other: SortableSet<T>): number {
const thisSorted = this.sorted()
const otherSorted = other.sorted()
const lenDiff = thisSorted.length - otherSorted.length
Copy link
Member

Choose a reason for hiding this comment

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

❌ why sort upfront?
Could you add an in-code comment to explain?

return lenDiff
}

for (let i = 0; i < thisSorted.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

❌ better: for ( const i=0 ; i < thisSorted.length ; ++i ) {}


/**
* Define the format for acceptable Common Weakness Enumeration (CWE) IDs.
* Refer to {@link https://cwe.mitre.org/index.html} for official specification.
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -27,11 +27,14 @@ module.exports = {
*/
capitaliseFirstLetter: s => s.charAt(0).toUpperCase() + s.slice(1),
/**
* UpperCamelCase a string
Copy link
Member

Choose a reason for hiding this comment

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

i liked the old description better.
I understand the need for more description.

❌ better go with:

UpperCamelCase a string ("white space example", "snake_case_example" or "kebab-case-example" )

❌ when on it, lets replace not only _ but also -(kebab-case)

}

export class VulnerabilityCredits implements Comparable {
organizations?: OrganizationalEntityRepository
Copy link
Member

Choose a reason for hiding this comment

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

❌ repositories must not be optiional, but they may be empty


export class VulnerabilityCredits implements Comparable {
organizations?: OrganizationalEntityRepository
individuals?: OrganizationalContactRepository
Copy link
Member

Choose a reason for hiding this comment

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

❌ repositories must not be optiional, but they may be empty

}

compare (other: VulnerabilityRating): number {
return (this.score ?? 0) - (other.score ?? 0)
Copy link
Member

Choose a reason for hiding this comment

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

this appears to be like an insufficient comparison.
if this is enough to properly compare, then please add a in-code comment that explains why.

}

compare (other: VulnerabilityReference): number {
return (this.id ?? '').localeCompare(other.id ?? '')
Copy link
Member

Choose a reason for hiding this comment

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

❌ unnecessary null-comparisson

import { Comparable, SortableSet } from '../helpers/sortableSet'

interface OptionalProperties {
url?: URL | string
Copy link
Member

Choose a reason for hiding this comment

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

❌ use type refenrences ala VulnerabilitySource['url']

@thepwagner
Copy link
Contributor Author

The changes remaining on this PR are far removed from my initial use case: as you can tell I'm not a strong TypeScript developer, and all I wanted was the Bom model object to have a []Vulnerability field that I could use.

I appreciate the value that your normalization brings, but the added complexity means contributing to this library is outside of my ability. If anyone else wants to pick this up for the basis of the implementation, please do!

@jkowalleck thank you for the reviews and sorry I couldn't see this through.

@jkowalleck
Copy link
Member

jkowalleck commented Aug 12, 2022

thank you for all your work, @thepwagner

could you open a pull request with your latest things and have it target the "feature/vulnerabilities" branch ?
Plan is to merge your models in there, fine tune them a bit and merge them into master for an early release.
I would love to keep you involved, @thepwagner , so when a beta-release of the feature is published, you could check if it suites your needs.

Then, in a later feature, the normalizers and serializers can be developed and be released separately.

This way you (and others) will have the models for use soon,
and will not be blocked by normalization details.

@jkowalleck
Copy link
Member

work continues in #419

@jkowalleck jkowalleck added this to the Bom.Vulnerabilities milestone Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants