Skip to content

Commit 124d2c2

Browse files
🐛 Update bulkInsertCves for collectors
1 parent 85978cf commit 124d2c2

File tree

4 files changed

+127
-17
lines changed

4 files changed

+127
-17
lines changed

openaev-api/src/main/java/io/openaev/rest/cve/CveApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public CveSimple createCve(@Valid @RequestBody VulnerabilityCreateInput input) {
7777
@LogExecutionTime
7878
@PostMapping(CVE_API + "/bulk")
7979
@RBAC(actionPerformed = Action.CREATE, resourceType = ResourceType.VULNERABILITY)
80-
public void bulkInsertCVEsForCollector(
81-
@Valid @RequestBody @NotNull VulnerabilityBulkInsertInput input) {
82-
this.vulnerabilityService.bulkUpsertVulnerabilities(input);
80+
public void bulkInsertCVEsForCollector(@Valid @RequestBody @NotNull CVEBulkInsertInput input) {
81+
this.vulnerabilityService.bulkUpsertVulnerabilities(
82+
vulnerabilityMapper.fromCVEBulkInsertInput(input));
8383
}
8484

8585
@Operation(summary = "Update an existing CVE")

openaev-api/src/main/java/io/openaev/utils/mapper/VulnerabilityMapper.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import io.openaev.database.model.Cwe;
55
import io.openaev.database.model.Vulnerability;
66
import io.openaev.ee.Ee;
7-
import io.openaev.rest.vulnerability.form.CweOutput;
8-
import io.openaev.rest.vulnerability.form.VulnerabilityOutput;
9-
import io.openaev.rest.vulnerability.form.VulnerabilitySimple;
7+
import io.openaev.rest.cve.form.CVEBulkInsertInput;
8+
import io.openaev.rest.cve.form.CveCreateInput;
9+
import io.openaev.rest.vulnerability.form.*;
1010
import java.util.ArrayList;
1111
import java.util.Collections;
1212
import java.util.List;
@@ -57,6 +57,50 @@ public VulnerabilityOutput toVulnerabilityOutput(final Vulnerability vulnerabili
5757
.build();
5858
}
5959

60+
public VulnerabilityBulkInsertInput fromCVEBulkInsertInput(final CVEBulkInsertInput input) {
61+
if (input == null) {
62+
return null;
63+
}
64+
65+
VulnerabilityBulkInsertInput result = new VulnerabilityBulkInsertInput();
66+
result.setVulnerabilities(toVulnerabilityCreateInputs(input.getCves()));
67+
result.setLastModifiedDateFetched(input.getLastModifiedDateFetched());
68+
result.setLastIndex(input.getLastIndex());
69+
result.setInitialDatasetCompleted(input.getInitialDatasetCompleted());
70+
result.setSourceIdentifier(input.getSourceIdentifier());
71+
return result;
72+
}
73+
74+
private List<VulnerabilityCreateInput> toVulnerabilityCreateInputs(
75+
final List<CveCreateInput> cves) {
76+
if (cves == null) {
77+
return List.of();
78+
}
79+
return cves.stream().map(this::toVulnerabilityCreateInput).collect(Collectors.toList());
80+
}
81+
82+
private VulnerabilityCreateInput toVulnerabilityCreateInput(final CveCreateInput cve) {
83+
if (cve == null) {
84+
return null;
85+
}
86+
87+
VulnerabilityCreateInput input = new VulnerabilityCreateInput();
88+
input.setExternalId(cve.getExternalId());
89+
input.setSourceIdentifier(cve.getSourceIdentifier());
90+
input.setCvssV31(cve.getCvssV31());
91+
input.setPublished(cve.getPublished());
92+
input.setDescription(cve.getDescription());
93+
input.setVulnStatus(cve.getVulnStatus());
94+
input.setCisaExploitAdd(cve.getCisaExploitAdd());
95+
input.setCisaActionDue(cve.getCisaActionDue());
96+
input.setCisaRequiredAction(cve.getCisaRequiredAction());
97+
input.setCisaVulnerabilityName(cve.getCisaVulnerabilityName());
98+
input.setRemediation(cve.getRemediation());
99+
input.setReferenceUrls(cve.getReferenceUrls());
100+
input.setCwes(cve.getCwes());
101+
return input;
102+
}
103+
60104
private List<CweOutput> toCweOutputs(final List<Cwe> cwes) {
61105
if (cwes == null || cwes.isEmpty()) {
62106
return Collections.emptyList();

openaev-front/src/admin/components/settings/vulnerabilities/VulnerabilityForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const VulnerabilityForm = ({
3939
vulnerability_cisa_vulnerability_name: '',
4040
vulnerability_cwes: [],
4141
vulnerability_reference_urls: [],
42+
vulnerability_remediation: '',
4243
},
4344
}: Props) => {
4445
// Standard hooks
@@ -131,7 +132,7 @@ const VulnerabilityForm = ({
131132
return (
132133
<FormProvider {...methods}>
133134
<form
134-
id="cveForm"
135+
id="vulnerabilityForm"
135136
style={{
136137
display: 'flex',
137138
flexDirection: 'column',

openaev-front/src/utils/api-types.d.ts

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface AggregatedFindingOutput {
115115
finding_id: string;
116116
/**
117117
* Represents the data type being extracted.
118-
* @example "text, number, port, portscan, ipv4, ipv6, credentials, vulnerability"
118+
* @example "text, number, port, portscan, ipv4, ipv6, credentials, cve"
119119
*/
120120
finding_type:
121121
| "text"
@@ -125,7 +125,7 @@ export interface AggregatedFindingOutput {
125125
| "ipv4"
126126
| "ipv6"
127127
| "credentials"
128-
| "vulnerability";
128+
| "cve";
129129
/** Finding Value */
130130
finding_value: string;
131131
}
@@ -588,6 +588,16 @@ type BaseWidgetConfigurationWidgetConfigurationTypeMapping<Key, Type> = {
588588
widget_configuration_type: Key;
589589
} & Type;
590590

591+
export interface CVEBulkInsertInput {
592+
cves: CveCreateInput[];
593+
initial_dataset_completed?: boolean;
594+
/** @format int32 */
595+
last_index?: number;
596+
/** @format date-time */
597+
last_modified_date_fetched?: string;
598+
source_identifier: string;
599+
}
600+
591601
export interface Challenge {
592602
challenge_category?: string;
593603
challenge_content?: string;
@@ -902,7 +912,7 @@ export interface ContractOutputElement {
902912
| "ipv4"
903913
| "ipv6"
904914
| "credentials"
905-
| "vulnerability";
915+
| "cve";
906916
/** @format date-time */
907917
contract_output_element_updated_at: string;
908918
listened?: boolean;
@@ -935,7 +945,7 @@ export interface ContractOutputElementInput {
935945
| "ipv4"
936946
| "ipv6"
937947
| "credentials"
938-
| "vulnerability";
948+
| "cve";
939949
}
940950

941951
/** Represents the rules for parsing the output of an execution. */
@@ -962,7 +972,7 @@ export interface ContractOutputElementSimple {
962972
| "ipv4"
963973
| "ipv6"
964974
| "credentials"
965-
| "vulnerability";
975+
| "cve";
966976
}
967977

968978
export interface CreateExerciseInput {
@@ -1054,6 +1064,61 @@ export interface CustomDashboardParametersInput {
10541064
| "scenario";
10551065
}
10561066

1067+
/** Payload to create a CVE */
1068+
export interface CveCreateInput {
1069+
/**
1070+
* CVSS score
1071+
* @min 0
1072+
* @exclusiveMin false
1073+
* @max 10
1074+
* @exclusiveMax false
1075+
* @example 7.5
1076+
*/
1077+
cve_cvss_v31: number;
1078+
/**
1079+
* Date when action is due by CISA
1080+
* @format date-time
1081+
*/
1082+
cve_cisa_action_due?: string;
1083+
/**
1084+
* Date when CISA added the CVE to the exploited list
1085+
* @format date-time
1086+
*/
1087+
cve_cisa_exploit_add?: string;
1088+
/** Action required by CISA */
1089+
cve_cisa_required_action?: string;
1090+
/** Vulnerability name used by CISA */
1091+
cve_cisa_vulnerability_name?: string;
1092+
/** List of linked CWEs */
1093+
cve_cwes?: CweInput[];
1094+
/** Description of the CVE */
1095+
cve_description?: string;
1096+
/**
1097+
* External Unique CVE identifier
1098+
* @example "CVE-2024-0001"
1099+
*/
1100+
cve_external_id: string;
1101+
/**
1102+
* Publication date of the CVE
1103+
* @format date-time
1104+
*/
1105+
cve_published?: string;
1106+
/** List of reference URLs */
1107+
cve_reference_urls?: string[];
1108+
/** Suggested remediation */
1109+
cve_remediation?: string;
1110+
/**
1111+
* Identifier of the CVE source
1112+
* @example "MITRE"
1113+
*/
1114+
cve_source_identifier?: string;
1115+
/**
1116+
* Vulnerability status
1117+
* @example "ANALYZED"
1118+
*/
1119+
cve_vuln_status?: "ANALYZED" | "DEFERRED" | "MODIFIED";
1120+
}
1121+
10571122
/** Full CVE output including references and CWEs */
10581123
export interface CveOutput {
10591124
/**
@@ -2378,7 +2443,7 @@ export interface Finding {
23782443
| "ipv4"
23792444
| "ipv6"
23802445
| "credentials"
2381-
| "vulnerability";
2446+
| "cve";
23822447
/** @format date-time */
23832448
finding_updated_at: string;
23842449
finding_users?: string[];
@@ -2398,7 +2463,7 @@ export interface FindingInput {
23982463
| "ipv4"
23992464
| "ipv6"
24002465
| "credentials"
2401-
| "vulnerability";
2466+
| "cve";
24022467
finding_value: string;
24032468
}
24042469

@@ -5091,7 +5156,7 @@ export interface RelatedFindingOutput {
50915156
finding_simulation?: ExerciseSimple;
50925157
/**
50935158
* Represents the data type being extracted.
5094-
* @example "text, number, port, portscan, ipv4, ipv6, credentials, vulnerability"
5159+
* @example "text, number, port, portscan, ipv4, ipv6, credentials, cve"
50955160
*/
50965161
finding_type:
50975162
| "text"
@@ -5101,7 +5166,7 @@ export interface RelatedFindingOutput {
51015166
| "ipv4"
51025167
| "ipv6"
51035168
| "credentials"
5104-
| "vulnerability";
5169+
| "cve";
51055170
/** Finding Value */
51065171
finding_value: string;
51075172
}
@@ -6219,7 +6284,7 @@ export interface VulnerabilityCreateInput {
62196284
/** Description of the vulnerability */
62206285
vulnerability_description?: string;
62216286
/**
6222-
* External Unique VULNERABILITY IDentifier
6287+
* External Unique Vulnerabilty Identifier
62236288
* @example "CVE-2024-0001"
62246289
*/
62256290
vulnerability_external_id: string;

0 commit comments

Comments
 (0)