• Hi @nSubramanya728691 (Community Member)​ ,

     

    Please note that AngularJS support ended last year. There are commercial providers that will maintain AngularJS for you but you are strongly encouraged to migrate away from AngularJS to a different JavaScript framework, for example Angular v16.

     

    Fortunately, Angular and AngularJS use the same "X-XSRF-TOKEN" header protection:

    AngularJS: https://docs.angularjs.org/api/ng/service/$http#cross-site-request-forgery-xsrf-protection

    Angular: https://angular.io/guide/http-security-xsrf-protection

     

    You should be able to use this with [ValidateAntiForgeryToken] with the following recommendation from Microsoft:

     

    Assuming the script sends the token in a request header called X-XSRF-TOKEN, configure the antiforgery service to look for the X-XSRF-TOKEN header:

     

    builder.Services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");

     

    The following example adds a protected endpoint that will write the request token to a JavaScript-readable cookie:

     

    app.UseAuthorization();

    app.MapGet("antiforgery/token", (IAntiforgery forgeryService, HttpContext context) =>

    {

    var tokens = forgeryService.GetAndStoreTokens(context);

    context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken!,

    new CookieOptions { HttpOnly = false });

     

    return Results.Ok();

    }).RequireAuthorization();

     

    From: https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-6.0

     

    Please let me know if you have any remaining questions or concerns.

     

    Thank you,

    Boy Baukema

    Expand Post

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.