Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a TagHelperInitializer to set the Antiforgery attribute #840

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>
<form action="@LinkGenerator.AcceptCase(Model.TicketNumber)" method="post" asp-antiforgery="true">
<form action="@LinkGenerator.AcceptCase(Model.TicketNumber)" method="post">
<govuk-summary-list>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Current</govuk-summary-list-row-key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>
<form action="@LinkGenerator.RejectCase(Model.TicketNumber)" method="post" asp-antiforgery="true">
<form action="@LinkGenerator.RejectCase(Model.TicketNumber)" method="post">
<govuk-radios asp-for="RejectionReasonChoice">
<govuk-radios-fieldset>
<govuk-radios-fieldset-legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<div class="govuk-!-margin-bottom-6">
<form trs-action="l => l.Persons()" method="get" data-testid="search-form">
<form action="@LinkGenerator.Persons()" method="get" data-testid="search-form">
<div class="moj-search trs-search govuk-!-margin-bottom-4">
<govuk-input asp-for="Search"
input-class="moj-search__input"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/sign-out"
@page "/sign-out"
@addTagHelper *, Joonasw.AspNetCore.SecurityHeaders
@model TeachingRecordSystem.SupportUi.Pages.SignOutModel
@{
Expand All @@ -7,7 +7,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form action="@LinkGenerator.SignOut()" method="post" asp-antiforgery="true">
<form action="@LinkGenerator.SignOut()" method="post">
<govuk-button type="submit">Sign out</govuk-button>
</form>
<script asp-add-nonce="true">document.forms[0].submit();</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/users/add/confirm"
@page "/users/add/confirm"
@using TeachingRecordSystem.Core;
@model TeachingRecordSystem.SupportUi.Pages.Users.AddUser.ConfirmModel
@{
Expand All @@ -7,7 +7,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form trs-action="l => l.AddUser(Model.UserId!)">
<form action="@LinkGenerator.AddUser(Model.UserId!)" method="post">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>

<govuk-input asp-for="Email" type="email" disabled />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@page "/users/add"
@page "/users/add"
@model TeachingRecordSystem.SupportUi.Pages.Users.AddUser.IndexModel
@{
ViewBag.Title = "Add user";
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form trs-action="l => l.AddUser()">
<form action="@LinkGenerator.AddUser()" method="post">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>

<govuk-input asp-for="Email" type="email" autocomplete="off" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form trs-action="l => l.EditUser(Model.UserId!)">
<form action="@LinkGenerator.EditUser(Model.UserId!)" method="post">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>

<govuk-input asp-for="Email" type="email" disabled />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Identity.Web;
Expand All @@ -19,6 +21,7 @@
using TeachingRecordSystem.SupportUi.Infrastructure.Redis;
using TeachingRecordSystem.SupportUi.Infrastructure.Security;
using TeachingRecordSystem.SupportUi.Services;
using TeachingRecordSystem.SupportUi.TagHelpers;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -177,7 +180,8 @@
.AddTransient<CheckUserExistsFilter>()
.AddSingleton<IClock, Clock>()
.AddSupportUiServices(builder.Configuration, builder.Environment)
.AddSingleton<ReferenceDataCache>();
.AddSingleton<ReferenceDataCache>()
.AddSingleton<ITagHelperInitializer<FormTagHelper>, FormTagHelperInitializer>();

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.TagHelpers;

namespace TeachingRecordSystem.SupportUi.TagHelpers;

public class FormTagHelperInitializer : ITagHelperInitializer<FormTagHelper>
{
public void Initialize(FormTagHelper helper, ViewContext context)
{
helper.Antiforgery ??= true;
}
}

This file was deleted.

Loading