Skip to content

Commit c681e15

Browse files
Enhance CSRF protection in upload endpoints
1 parent ec7938a commit c681e15

7 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/Web/Grand.SharedUIResources/Views/Shared/EditorTemplates/MultiPicture.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
Reference: '@reference',
3333
ObjectId: '@objectId'
3434
},
35-
inputName: "files"
35+
inputName: "files",
36+
customHeaders: {
37+
'X-CSRF-TOKEN': $('input[name="__RequestVerificationToken"]').val()
38+
}
3639
},
3740
template: "@(clientId)-qq-template",
3841
multiple: true,

src/Web/Grand.SharedUIResources/Views/Shared/EditorTemplates/Picture.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ else
4444
Reference: '@ViewData["Reference"]',
4545
ObjectId: '@ViewData["ObjectId"]'
4646
},
47-
inputName: "file"
47+
inputName: "file",
48+
customHeaders: {
49+
'X-CSRF-TOKEN': $('input[name="__RequestVerificationToken"]').val()
50+
}
4851
},
4952
template: "@(clientId)-qq-template",
5053
multiple: false,

src/Web/Grand.Web.Admin/Controllers/PictureController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public PictureController(
3232
_mediaSettings = mediaSettings;
3333
}
3434

35-
[HttpPost]
36-
[IgnoreAntiforgeryToken]
35+
[HttpPost]
3736
public virtual async Task<IActionResult> AsyncUpload(IFormFile file, Reference reference = Reference.None, string objectId = "")
3837
{
3938
if (file == null)
@@ -73,8 +72,7 @@ await _pictureService.InsertPicture(fileBinary, contentType, null, reference: re
7372
});
7473
}
7574

76-
[HttpPost]
77-
[IgnoreAntiforgeryToken]
75+
[HttpPost]
7876
public virtual async Task<IActionResult> AsyncLogoUpload(IFormFile file)
7977
{
8078
if (!await _permissionService.Authorize(StandardPermission.ManageSettings))

src/Web/Grand.Web.Admin/Controllers/ProductController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ public async Task<IActionResult> AssociatedProductAddPopup(ProductModel.AddAssoc
10281028

10291029
#region Product pictures
10301030

1031-
[HttpPost]
1032-
[IgnoreAntiforgeryToken]
1031+
[HttpPost]
10331032
public async Task<IActionResult> ProductPictureAdd(
10341033
IFormFileCollection files,
10351034
Reference reference, string objectId,

src/Web/Grand.Web.Store/Controllers/PictureController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public PictureController(
3333
}
3434

3535
[HttpPost]
36-
[IgnoreAntiforgeryToken]
3736
public virtual async Task<IActionResult> AsyncUpload(IFormFile file, Reference reference = Reference.None, string objectId = "")
3837
{
3938
if (file == null)
@@ -74,7 +73,6 @@ await _pictureService.InsertPicture(fileBinary, contentType, null, reference: re
7473
}
7574

7675
[HttpPost]
77-
[IgnoreAntiforgeryToken]
7876
public virtual async Task<IActionResult> AsyncLogoUpload(IFormFile file)
7977
{
8078
if (!await _permissionService.Authorize(StandardPermission.ManageSettings))

src/Web/Grand.Web.Store/Controllers/ProductController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,6 @@ public async Task<IActionResult> AssociatedProductAddPopup(ProductModel.AddAssoc
10871087
#region Product pictures
10881088

10891089
[HttpPost]
1090-
[IgnoreAntiforgeryToken]
10911090
public async Task<IActionResult> ProductPictureAdd(
10921091
IFormFileCollection files,
10931092
Reference reference, string objectId,

src/Web/Grand.Web.Vendor/Controllers/ProductController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,7 @@ public async Task<IActionResult> AssociatedProductAddPopup(ProductModel.AddAssoc
10741074

10751075
#region Product pictures
10761076

1077-
[HttpPost]
1078-
[IgnoreAntiforgeryToken]
1077+
[HttpPost]
10791078
public async Task<IActionResult> ProductPictureAdd(
10801079
IFormFileCollection files,
10811080
Reference reference, string objectId,

0 commit comments

Comments
 (0)