From 97c86ad353ce1bb559e5973607e2a729c4bf1800 Mon Sep 17 00:00:00 2001 From: gumbarros Date: Tue, 24 Nov 2026 11:10:44 -0300 Subject: [PATCH] Added AutoValidateAntiforgeryToken --- .../Controllers/DataDictionaryController.cs | 3 +- .../Controllers/ElementController.cs | 1 + .../Controllers/FieldController.cs | 1 + .../Controllers/PanelController.cs | 2 +- .../Controllers/RulesController.cs | 1 + .../Views/Element/_Scripts.cshtml | 3 +- .../DataDictionary/Views/Indexes/Index.cshtml | 2 +- .../Views/Relationships/_IndexLayout.cshtml | 3 +- .../Controllers/MasterDataController.cs | 3 +- .../Scripts/DataDictionaryUtils.ts | 2 + src/MasterData.Web/Scripts/PostFormValues.ts | 16 +++--- .../Web/AntiforgeryTests.cs | 54 +++++++++++++++++++ 12 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 test/MasterData.IntegrationTests/Web/AntiforgeryTests.cs diff --git a/src/MasterData.Web/Areas/DataDictionary/Controllers/DataDictionaryController.cs b/src/MasterData.Web/Areas/DataDictionary/Controllers/DataDictionaryController.cs index 43df41838..fcdb44abc 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Controllers/DataDictionaryController.cs +++ b/src/MasterData.Web/Areas/DataDictionary/Controllers/DataDictionaryController.cs @@ -3,4 +3,5 @@ namespace JJMasterData.Web.Areas.DataDictionary.Controllers; [Area("DataDictionary")] -public abstract class DataDictionaryController : Controller; \ No newline at end of file +[AutoValidateAntiforgeryToken] +public abstract class DataDictionaryController : Controller; diff --git a/src/MasterData.Web/Areas/DataDictionary/Controllers/ElementController.cs b/src/MasterData.Web/Areas/DataDictionary/Controllers/ElementController.cs index 51e0eea1b..bbbfa8733 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Controllers/ElementController.cs +++ b/src/MasterData.Web/Areas/DataDictionary/Controllers/ElementController.cs @@ -184,6 +184,7 @@ public async Task Scripts(string elementName, string scriptOption } } + [HttpPost] public async Task Delete() { var formView = elementService.GetFormView(); diff --git a/src/MasterData.Web/Areas/DataDictionary/Controllers/FieldController.cs b/src/MasterData.Web/Areas/DataDictionary/Controllers/FieldController.cs index 3b787a44f..cdd9709af 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Controllers/FieldController.cs +++ b/src/MasterData.Web/Areas/DataDictionary/Controllers/FieldController.cs @@ -53,6 +53,7 @@ public async Task Add(string elementName) return PartialView("_Detail", field); } + [HttpPost] public async Task Delete(string elementName, string fieldName) { await fieldService.DeleteField(elementName, fieldName); diff --git a/src/MasterData.Web/Areas/DataDictionary/Controllers/PanelController.cs b/src/MasterData.Web/Areas/DataDictionary/Controllers/PanelController.cs index 67f601f5d..4d9cec2ec 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Controllers/PanelController.cs +++ b/src/MasterData.Web/Areas/DataDictionary/Controllers/PanelController.cs @@ -50,6 +50,7 @@ public async Task Add(string elementName) return PartialView("_Detail", panel); } + [HttpPost] public async Task Delete(string elementName, int panelId) { await panelService.DeleteFieldAsync(elementName, panelId); @@ -89,7 +90,6 @@ public async Task Sort(string elementName, string fieldsOrder) } [HttpPost] - [ValidateAntiForgeryToken] public async Task Move(string elementName, int panelId, int? parentId, int? beforePanelId) { if (!ModelState.IsValid || !await panelService.MovePanelAsync(elementName, panelId, parentId, beforePanelId)) diff --git a/src/MasterData.Web/Areas/DataDictionary/Controllers/RulesController.cs b/src/MasterData.Web/Areas/DataDictionary/Controllers/RulesController.cs index 10900544a..7a53f04e2 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Controllers/RulesController.cs +++ b/src/MasterData.Web/Areas/DataDictionary/Controllers/RulesController.cs @@ -72,6 +72,7 @@ public async Task Save(string elementName, FormElementRule rule, return RedirectToIndex(elementName, rule, selectedTab); } + [HttpPost] public async Task Delete(string elementName, int ruleId) { await formElementRulesService.DeleteAsync(elementName, ruleId); diff --git a/src/MasterData.Web/Areas/DataDictionary/Views/Element/_Scripts.cshtml b/src/MasterData.Web/Areas/DataDictionary/Views/Element/_Scripts.cshtml index 81687a7a8..5ea9dbf86 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Views/Element/_Scripts.cshtml +++ b/src/MasterData.Web/Areas/DataDictionary/Views/Element/_Scripts.cshtml @@ -218,6 +218,7 @@ try { const response = await fetch('@Url.Action("Scripts", "Element", new { elementName = Model.ElementName })', { method: 'POST', + headers: getRequestHeaders(), body: formData }); @@ -262,4 +263,4 @@ } hljs.highlightAll(); - \ No newline at end of file + diff --git a/src/MasterData.Web/Areas/DataDictionary/Views/Indexes/Index.cshtml b/src/MasterData.Web/Areas/DataDictionary/Views/Indexes/Index.cshtml index e219a3e53..5cee0a834 100644 --- a/src/MasterData.Web/Areas/DataDictionary/Views/Indexes/Index.cshtml +++ b/src/MasterData.Web/Areas/DataDictionary/Views/Indexes/Index.cshtml @@ -19,7 +19,7 @@