@@ -4,6 +4,7 @@ const errors = require('./error')
44const getConstants = require ( '../../constants' ) . getConstants
55const error = new errors . CveControllerError ( )
66const booleanIsTrue = require ( '../../utils/utils' ) . booleanIsTrue
7+ const convertDatesToISO = require ( '../../utils/utils' ) . convertDatesToISO
78const isEnrichedContainer = require ( '../../utils/utils' ) . isEnrichedContainer
89const url = process . env . NODE_ENV === 'staging' ? 'https://test.cve.org/' : 'https://cve.org/'
910
@@ -332,7 +333,7 @@ async function submitCve (req, res, next) {
332333 const CONSTANTS = getConstants ( )
333334
334335 try {
335- const newCve = new Cve ( { cve : req . ctx . body } )
336+ const newCve = new Cve ( { cve : convertDatesToISO ( req . ctx . body , CONSTANTS . DATE_FIELDS ) } )
336337 const id = req . ctx . params . id
337338 const cveId = newCve . cve . cveMetadata . cveId
338339 const state = newCve . cve . cveMetadata . state
@@ -392,7 +393,8 @@ async function updateCve (req, res, next) {
392393 const CONSTANTS = getConstants ( )
393394
394395 try {
395- const newCve = new Cve ( { cve : req . ctx . body } )
396+ // All CVE fields are stored in UTC format, we need to check and convert dates to ISO before storing in the database.
397+ const newCve = new Cve ( { cve : convertDatesToISO ( req . ctx . body , CONSTANTS . DATE_FIELDS ) } )
396398 const cveId = req . ctx . params . id
397399 const cveRepo = req . ctx . repositories . getCveRepository ( )
398400 const cveIdRepo = req . ctx . repositories . getCveIdRepository ( )
@@ -486,7 +488,7 @@ async function submitCna (req, res, next) {
486488 return res . status ( 403 ) . json ( error . cveRecordExists ( ) )
487489 }
488490
489- const cnaContainer = req . ctx . body . cnaContainer
491+ const cnaContainer = convertDatesToISO ( req . ctx . body . cnaContainer , CONSTANTS . DATE_FIELDS )
490492 if ( erlCheck && ! isEnrichedContainer ( cnaContainer ) ) {
491493 // Process the ERL check here
492494 return res . status ( 403 ) . json ( error . erlCheckFailed ( ) )
@@ -582,7 +584,7 @@ async function updateCna (req, res, next) {
582584 return res . status ( 403 ) . json ( error . cveRecordDne ( ) )
583585 }
584586
585- const cnaContainer = req . ctx . body . cnaContainer
587+ const cnaContainer = convertDatesToISO ( req . ctx . body . cnaContainer , CONSTANTS . DATE_FIELDS )
586588 if ( erlCheck && ! isEnrichedContainer ( cnaContainer ) ) {
587589 // Process the ERL check here
588590 return res . status ( 403 ) . json ( error . erlCheckFailed ( ) )
@@ -684,7 +686,7 @@ async function rejectCVE (req, res, next) {
684686
685687 const providerMetadata = createProviderMetadata ( providerOrgObj . UUID , req . ctx . org , ( new Date ( ) ) . toISOString ( ) )
686688 const rejectedCve = Cve . newRejectedCve ( cveIdObj , req . ctx . body , owningCnaShortName , providerMetadata )
687- const newCveObj = new Cve ( { cve : rejectedCve } )
689+ const newCveObj = new Cve ( { cve : convertDatesToISO ( rejectedCve , CONSTANTS . DATE_FIELDS ) } )
688690
689691 result = Cve . validateCveRecord ( newCveObj . cve )
690692 if ( ! result . isValid ) {
@@ -757,7 +759,7 @@ async function rejectExistingCve (req, res, next) {
757759
758760 // update CVE record to rejected
759761 const updatedRecord = Cve . updateCveToRejected ( id , providerMetadata , result . cve , req . ctx . body )
760- const updatedCve = new Cve ( { cve : updatedRecord } )
762+ const updatedCve = new Cve ( { cve : convertDatesToISO ( updatedRecord , CONSTANTS . DATE_FIELDS ) } )
761763
762764 result = Cve . validateCveRecord ( updatedCve . cve )
763765 if ( ! result . isValid ) {
@@ -867,7 +869,7 @@ async function insertAdp (req, res, next) {
867869 cveRecord . containers . adp . push ( adpContainer )
868870 }
869871
870- const cveModel = new Cve ( { cve : cveRecord } )
872+ const cveModel = new Cve ( { cve : convertDatesToISO ( cveRecord , CONSTANTS . DATE_FIELDS ) } )
871873 result = Cve . validateCveRecord ( cveModel . cve )
872874 if ( ! result . isValid ) {
873875 logger . error ( JSON . stringify ( { uuid : req . ctx . uuid , message : 'CVE JSON schema validation FAILED.' } ) )
0 commit comments