Skip to content

Commit ffa555f

Browse files
security: exempt [ApiController] classes from antiforgery validation
API controllers (Chat, McpToken, ListingSourceCode) are called from JS clients and bearer token auth - they don't use cookie-based auth so CSRF doesn't apply. Adding [IgnoreAntiforgeryToken] to each prevents the global AutoValidateAntiforgeryToken filter from rejecting their requests.
1 parent 6d06a66 commit ffa555f

3 files changed

Lines changed: 3 additions & 0 deletions

File tree

EssentialCSharp.Web/Controllers/ChatController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace EssentialCSharp.Web.Controllers;
1010
[Route("api/[controller]")]
1111
[Authorize]
1212
[EnableRateLimiting("ChatEndpoint")]
13+
[IgnoreAntiforgeryToken]
1314
public partial class ChatController : ControllerBase
1415
{
1516
private readonly AIChatService _AiChatService;

EssentialCSharp.Web/Controllers/ListingSourceCodeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace EssentialCSharp.Web.Controllers;
55

66
[ApiController]
77
[Route("api/[controller]")]
8+
[IgnoreAntiforgeryToken]
89
public class ListingSourceCodeController : ControllerBase
910
{
1011
private readonly IListingSourceCodeService _ListingSourceCodeService;

EssentialCSharp.Web/Controllers/McpTokenController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace EssentialCSharp.Web.Controllers;
99
[Route("api/[controller]")]
1010
[Authorize]
1111
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
12+
[IgnoreAntiforgeryToken]
1213
public class McpTokenController(McpApiTokenService tokenService) : ControllerBase
1314
{
1415
public record CreateTokenRequest(string? Name, DateOnly? ExpiresOn = null);

0 commit comments

Comments
 (0)