Skip to content
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
4 changes: 1 addition & 3 deletions src/findings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import {
capitalise,
mostSpecificRescoring,
orderRescoringsBySpecificity,
} from './util'
import { artefactMetadataFilter } from './ocm/util'

Expand Down Expand Up @@ -190,8 +189,7 @@ export const findingIsResolved = ({
}) => {
if (rescoring.applicable_rescorings.length === 0) return false

const rescoringsOrderedBySpecificity = orderRescoringsBySpecificity(rescoring.applicable_rescorings)
const id = rescoringsOrderedBySpecificity[0].data.severity
const id = mostSpecificRescoring(rescoring.applicable_rescorings).data.severity
const categorisation = findCategorisationById({id, findingCfg})

return categorisation.value === 0
Expand Down
12 changes: 9 additions & 3 deletions src/rescoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,21 @@ const scopedComponentArtefactId = ({
artefact,
artefactKind,
}) => {
const extraIdentity = {...artefact.extraIdentity}

if (scope === scopeOptions.ARTEFACT) {
delete extraIdentity.version
}

return {
component_name: [scopeOptions.COMPONENT, scopeOptions.ARTEFACT, scopeOptions.SINGLE].includes(scope) ? component.name : null,
component_version: scopeOptions.SINGLE === scope && component.version !== 'greatest' ? component.version : null,
artefact_kind: artefactKind,
artefact_kind: [scopeOptions.ARTEFACT, scopeOptions.SINGLE].includes(scope) ? artefactKind : null,
artefact: {
artefact_name: [scopeOptions.ARTEFACT, scopeOptions.SINGLE].includes(scope) ? artefact.name : null,
artefact_version: scopeOptions.SINGLE === scope ? artefact.version : null,
artefact_type: artefact.type,
artefact_extra_id: scopeOptions.SINGLE === scope ? artefact.extraIdentity : {},
artefact_type: [scopeOptions.ARTEFACT, scopeOptions.SINGLE].includes(scope) ? artefact.type : null,
artefact_extra_id: [scopeOptions.ARTEFACT, scopeOptions.SINGLE].includes(scope) ? extraIdentity : {},
},
}
}
Expand Down
42 changes: 18 additions & 24 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,37 +141,30 @@ export const pluralise = (word, count, verbSingular, verbPlural) => {
return `${word.replace(/y$/, 'ie')}${word.endsWith('s') ? '' : 's'}`
}

export const orderRescoringsBySpecificity = (rescorings) => {
return rescorings?.sort((a, b) => {
// if one rescoring has global scope, use the other one
if (a.artefact.component_name && !b.artefact.component_name) return -1
if (b.artefact.component_name && !a.artefact.component_name) return 1

// if one rescoring has component scope, use the other one
if (a.artefact.artefact.artefact_name && !b.artefact.artefact.artefact_name) return -1
if (b.artefact.artefact.artefact_name && !a.artefact.artefact.artefact_name) return 1

// if one rescoring has artefact scope, use the other one
if (a.artefact.artefact.artefact_version && !b.artefact.artefact.artefact_version) return -1
if (b.artefact.artefact.artefact_version && !a.artefact.artefact.artefact_version) return 1

// if both rescorings share the same scope, use the latest one
return new Date(b.meta.creation_date) - new Date(a.meta.creation_date)
})
}

export const mostSpecificRescoring = (rescorings) => {
if (!rescorings?.length > 0) return null

return orderRescoringsBySpecificity(rescorings)[0]
return rescorings.sort((a, b) => {
return new Date(b.meta.creation_date) - new Date(a.meta.creation_date)
})[0]
}
Comment thread
8R0WNI3 marked this conversation as resolved.


export const filterRescoringsForFinding = (finding, rescorings) => {
const findingExtraIdentity = {...finding.artefact.artefact.artefact_extra_id}
delete findingExtraIdentity.version

return rescorings.filter((rescoring) => {
if (rescoring.data.referenced_type !== finding.meta.type) return false
if (rescoring.artefact.artefact_kind !== finding.artefact.artefact_kind) return false
if (rescoring.artefact.artefact.artefact_type !== finding.artefact.artefact.artefact_type) return false
if (
rescoring.artefact.artefact_kind
&& rescoring.artefact.artefact_kind !== finding.artefact.artefact_kind
) return false
if (
rescoring.artefact.artefact.artefact_type
&& rescoring.artefact.artefact.artefact_type !== finding.artefact.artefact.artefact_type
) return false
if (
rescoring.artefact.component_name
&& rescoring.artefact.component_name !== finding.artefact.component_name
Expand All @@ -189,10 +182,11 @@ export const filterRescoringsForFinding = (finding, rescorings) => {
rescoring.artefact.artefact.artefact_version
&& rescoring.artefact.artefact.artefact_version !== finding.artefact.artefact.artefact_version
) return false
const rescoringExtraIdentity = {...rescoring.artefact.artefact.artefact_extra_id}
delete rescoringExtraIdentity.version
if (
Object.keys(rescoring.artefact.artefact.artefact_extra_id).length > 0
&& normaliseExtraIdentity(rescoring.artefact.artefact.artefact_extra_id)
!== normaliseExtraIdentity(finding.artefact.artefact.artefact_extra_id)
Object.keys(rescoringExtraIdentity).length > 0
&& normaliseExtraIdentity(rescoringExtraIdentity) !== normaliseExtraIdentity(findingExtraIdentity)
) return false

if (finding.meta.type === FINDING_TYPES.VULNERABILITY) {
Expand Down
Loading