Skip to content

Commit 34fe473

Browse files
authored
Merge pull request #1625 from CVEProject/timeline-date-pr-test
Resolves #1623 Prevents invalid timeline.time values
2 parents 68b5743 + b304031 commit 34fe473

File tree

8 files changed

+172
-9
lines changed

8 files changed

+172
-9
lines changed

api-docs/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"openapi": "3.0.2",
33
"info": {
4-
"version": "2.6.0",
4+
"version": "2.6.1",
55
"title": "CVE Services API",
66
"description": "The CVE Services API supports automation tooling for the CVE Program. Credentials are required for most service endpoints. Representatives of <a href='https://www.cve.org/ProgramOrganization/CNAs'>CVE Numbering Authorities (CNAs)</a> should use one of the methods below to obtain credentials: <ul><li>If your organization already has an Organizational Administrator (OA) account for the CVE Services, ask your admin for credentials</li> <li>Contact your Root (<a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/Google'>Google</a>, <a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/INCIBE'>INCIBE</a>, <a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/jpcert'>JPCERT/CC</a>, or <a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/redhat'>Red Hat</a>) or Top-Level Root (<a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/icscert'>CISA ICS</a> or <a href='https://www.cve.org/PartnerInformation/ListofPartners/partner/mitre'>MITRE</a>) to request credentials </ul> <p>CVE data is to be in the JSON 5.2 CVE Record format. Details of the JSON 5.2 schema are located <a href='https://github.com/CVEProject/cve-schema/releases/tag/v5.2.0' target='_blank'>here</a>.</p> <a href='https://cveform.mitre.org/' class='link' target='_blank'>Contact the CVE Services team</a>",
77
"contact": {

package-lock.json

Lines changed: 40 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cve-services",
33
"author": "Automation Working Group",
4-
"version": "2.6.0",
4+
"version": "2.6.1",
55
"license": "(CC0)",
66
"devDependencies": {
77
"@faker-js/faker": "^7.6.0",

src/controller/cve.controller/cve.middleware.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,32 @@ function datePublicHelper (datePublic) {
178178
return currentDate > datePublicWithGracePeriod
179179
}
180180

181+
/**
182+
* Checks that timeline.time fields are valid datetime objects.
183+
* This accounts for invalid timezone offsets that aren't handled by the schema.
184+
*
185+
* @param {String} dateIndex
186+
* @returns true
187+
* @throws Error
188+
*/
189+
function validateTimelineDates (dateIndex) {
190+
// Check if datePublic is a future date
191+
return body(dateIndex).isArray().withMessage('Time must be a date string').optional({ nullable: true }).bail().custom((timelineArray) => {
192+
for (const timelineObj of timelineArray) {
193+
const value = new Date(timelineObj.time)
194+
if (!validateTimelineHelper(value)) {
195+
throw new Error(`Invalid date string: ${timelineObj.time} `)
196+
}
197+
}
198+
199+
return true
200+
})
201+
}
202+
203+
function validateTimelineHelper (value) {
204+
return value instanceof Date && !isNaN(value)
205+
}
206+
181207
// Organizations in the ADP pilot are generating JSON programatically, and thus
182208
// informing them about the result of the final validation (against the full
183209
// CVE Record schema) is currently sufficient.
@@ -290,6 +316,7 @@ module.exports = {
290316
validateDescription,
291317
validateRejectBody,
292318
validateDatePublic,
319+
validateTimelineDates,
293320
datePublicHelper,
294321
validatePURL,
295322
purlValidateHelper

0 commit comments

Comments
 (0)