Skip to content

Commit b04e27a

Browse files
author
Scott Bommarito
authored
Deprecation - CVEs, CWEs, and CVSS should not be submitted with the form if unchecked (#6996)
1 parent 9cbe3cc commit b04e27a

2 files changed

Lines changed: 42 additions & 15 deletions

File tree

src/NuGetGallery/Scripts/gallery/page-manage-deprecation.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,22 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
300300
this.cvssRatingIsInvalid = ko.pureComputed(function () {
301301
return self.cvssRatingLabel() === invalidCvssRatingString;
302302
}, this);
303+
304+
this.chosenCvssRating = ko.pureComputed(function () {
305+
if (self.hasCvss()) {
306+
return self.selectedCvssRating();
307+
} else {
308+
// If the CVSS section is unchecked, there is no CVSS rating chosen.
309+
return null;
310+
}
311+
}, this);
303312

304313
// The CVSS rating to submit with the form.
305314
this.cvssRating = ko.pureComputed(function () {
306-
if (self.hasCvss()) {
307-
return self.selectedCvssRating();
315+
if (self.isVulnerable()) {
316+
return self.chosenCvssRating();
308317
} else {
309-
// If the CVSS section is unchecked, don't submit the CVSS rating with the form.
318+
// If the package is not vulnerable, don't submit the CVSS rating with the form.
310319
return null;
311320
}
312321
}, this);
@@ -328,7 +337,7 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
328337
};
329338

330339
// The model for the CVEs view.
331-
this.cves = new ManageDeprecationSecurityDetailListViewModel(
340+
this.chosenCves = new ManageDeprecationSecurityDetailListViewModel(
332341
"cve",
333342
"CVE ID(s)",
334343
"Add one or more CVEs applicable to the vulnerability.",
@@ -350,8 +359,17 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
350359
"We could not find this CVE. Is it correct?",
351360
"NuGet.org refreshes its CVE data often and if we find this ID, your deprecation will be updated with the latest data.");
352361

362+
this.cves = ko.pureComputed(function () {
363+
if (self.isVulnerable()) {
364+
return self.chosenCves.exportIds();
365+
} else {
366+
// If the package is not vulnerable, do not submit the CVEs with the form.
367+
return [];
368+
}
369+
}, this);
370+
353371
// The model for the CWEs view
354-
this.cwes = new ManageDeprecationSecurityDetailListViewModel(
372+
this.chosenCwes = new ManageDeprecationSecurityDetailListViewModel(
355373
"cwe",
356374
"CWE(s)",
357375
"Add one or more CWEs applicable to the vulnerability.",
@@ -373,6 +391,15 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
373391
null,
374392
null);
375393

394+
this.cwes = ko.pureComputed(function () {
395+
if (self.isVulnerable()) {
396+
return self.chosenCwes.exportIds();
397+
} else {
398+
// If the package is not vulnerable, do not submit the CWEs with the form.
399+
return [];
400+
}
401+
}, this);
402+
376403
// The ID entered into the alternate package ID textbox.
377404
this.chosenAlternatePackageId = ko.observable('');
378405

@@ -481,9 +508,9 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
481508
isVulnerable: self.isVulnerable(),
482509
isLegacy: self.isLegacy(),
483510
isOther: self.isOther(),
484-
cveIds: self.cves.exportIds(),
511+
cveIds: self.cves(),
485512
cvssRating: self.cvssRating(),
486-
cweIds: self.cwes.exportIds(),
513+
cweIds: self.cwes(),
487514
alternatePackageId: self.alternatePackageId(),
488515
alternatePackageVersion: self.alternatePackageVersion(),
489516
customMessage: self.customMessage()
@@ -512,9 +539,9 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
512539
versionData.IsVulnerable = self.isVulnerable();
513540
versionData.IsLegacy = self.isLegacy();
514541
versionData.IsOther = self.isOther();
515-
versionData.CveIds = self.cves.export();
516-
versionData.CvssRating = self.cvssRating();
517-
versionData.CweIds = self.cwes.export();
542+
versionData.CveIds = self.chosenCves.export();
543+
versionData.CvssRating = self.chosenCvssRating();
544+
versionData.CweIds = self.chosenCwes.export();
518545
versionData.AlternatePackageId = self.alternatePackageId();
519546
versionData.AlternatePackageVersion = self.alternatePackageVersion();
520547
versionData.CustomMessage = self.customMessage();
@@ -530,12 +557,12 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
530557
self.isLegacy(versionData.IsLegacy);
531558
self.isOther(versionData.IsOther);
532559

533-
self.cves.import(versionData.CveIds);
560+
self.chosenCves.import(versionData.CveIds);
534561

535-
self.hasCvss(versionData.CvssRating);
562+
self.hasCvss(!!versionData.CvssRating);
536563
self.selectedCvssRating(versionData.CvssRating);
537564

538-
self.cwes.import(versionData.CweIds);
565+
self.chosenCwes.import(versionData.CweIds);
539566

540567
self.chosenAlternatePackageId(versionData.AlternatePackageId);
541568
if (versionData.AlternatePackageVersion) {

src/NuGetGallery/Views/Packages/_ManageDeprecation.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<div class="deprecation-section-header">
4848
<b>Provide additional security details</b>
4949
</div>
50-
<div data-bind="template: { name: 'deprecation-security-detail-list-input-template', data: cves }"></div>
50+
<div data-bind="template: { name: 'deprecation-security-detail-list-input-template', data: chosenCves }"></div>
5151
<div class="security-detail panel panel-default">
5252
<div>
5353
<label>
@@ -61,7 +61,7 @@
6161
<span data-bind="text: cvssRatingLabel, css: { 'text-danger': cvssRatingIsInvalid, 'cvss-bold': !cvssRatingIsInvalid() }"></span>
6262
</div>
6363
</div>
64-
<div data-bind="template: { name: 'deprecation-security-detail-list-input-template', data: cwes }"></div>
64+
<div data-bind="template: { name: 'deprecation-security-detail-list-input-template', data: chosenCwes }"></div>
6565
</div>
6666
<div class="form-group unbolded-label">
6767
<label>

0 commit comments

Comments
 (0)