Skip to content

Commit

Permalink
Merge pull request #795 from companieshouse/sec-113-implement-csrf-to…
Browse files Browse the repository at this point in the history
…kens-on-forms

SEC-113 Implement csrf token on forms where data is submitted
  • Loading branch information
mattch1 authored Oct 21, 2024
2 parents 4b5d21a + 845f5b7 commit 0760097
Show file tree
Hide file tree
Showing 25 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const sessionStore = new SessionStore(new Redis(`redis://${CACHE_SERVER}`));

const csrfProtectionMiddleware = CsrfProtectionMiddleware({
sessionStore,
enabled: false,
enabled: true,
sessionCookieName: COOKIE_NAME
});
app.use(csrfProtectionMiddleware);
Expand Down
2 changes: 1 addition & 1 deletion views/check-trading-status.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="govuk-grid-column-two-thirds">

<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if tradingStatusErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/confirm-company.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h1 class="govuk-heading-xl">Confirm this is the correct company</h1>
<h2 class="govuk-heading-l">{{company.companyName}}</h2>
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% set notDueWarningHTML %}
<p style="font-weight: 400; display: inline;">
You are not due to file a confirmation statement. If you file a confirmation statement today, it will show the date as
Expand Down
7 changes: 7 additions & 0 deletions views/includes/csrf_token.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{% from "web-security-node/components/csrf-token-input/macro.njk" import csrfTokenInput %}
{{
csrfTokenInput({
csrfToken: csrfToken
})
}}
2 changes: 1 addition & 1 deletion views/incorrect-information/wrong-officers.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% include "includes/error-alert-message.html" %}
{% if errorMsgText %}
{% set officersErrorMsg = {
Expand Down
2 changes: 1 addition & 1 deletion views/incorrect-information/wrong-psc-details.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% include "includes/error-alert-message.html" %}
{% if errorMsgText %}
{% set pscErrorMsg = {
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% include "includes/error-alert-message.html" %}
{% if errorMsgText %}
{% set roErrorMsg = {
Expand Down
2 changes: 1 addition & 1 deletion views/incorrect-information/wrong-registers.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% include "includes/error-alert-message.html" %}
{% if errorMsgText %}
{% set registerErrorMsg = {
Expand Down
1 change: 1 addition & 0 deletions views/incorrect-information/wrong-shareholders.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-xl">
You cannot use this service
</h1>
Expand Down
1 change: 1 addition & 0 deletions views/incorrect-information/wrong-sic.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-xl">
You cannot use this service
</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-xl">
You cannot use this service
</h1>
Expand Down
1 change: 1 addition & 0 deletions views/review.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h2 class="govuk-heading-m">
Company number: {{company.companyNumber}}<br>
Confirmation statement date: {{nextMadeUpToDate}}</h2>
<form action="" method="post">
{% include "includes/csrf_token.html" %}
{% if ecctEnabled %}
{% if confirmationStatementError or lawfulActivityStatementError %}

Expand Down
1 change: 1 addition & 0 deletions views/tasks/active-officers-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{% set activeOfficersError = false %}
{% endif %}
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-l">Check the officers' details</h1>

{% set naturalSecretaryHTML %}
Expand Down
1 change: 1 addition & 0 deletions views/tasks/active-officers.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<form action="" method="post">
{% include "includes/csrf_token.html" %}
{% if officerErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
1 change: 1 addition & 0 deletions views/tasks/active-psc-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{% set activePscsError = false %}
{% endif %}
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-l">Check the people with significant control (PSCs) details</h1>

{% include "includes/psc-details.html" %}
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/check-email-address.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if checkEmailErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
1 change: 1 addition & 0 deletions views/tasks/confirm-email-address.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<div class="govuk-grid-column">
<form action="" method="post">
{% include "includes/csrf_token.html" %}
<h1 class="govuk-heading-l">Check the email address</h1>
<dl>
<dt class="govuk-summary-list__key">Email address</dt>
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/people-with-significant-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="govuk-grid-column-three-quarters">

<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if peopleWithSignificantControlErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/provide-email-address.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if emailErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/psc-statement.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if pscStatementControlErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/register-locations.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if registerLocationsErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/registered-office-address.html
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">
<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if roaErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/shareholders.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="govuk-grid-column-two-thirds">

<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if shareholdersErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/sic.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="govuk-grid-column-two-thirds">

<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if sicCodeErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
2 changes: 1 addition & 1 deletion views/tasks/statement-of-capital.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="govuk-grid-column-two-thirds">

<form action="" method="post">

{% include "includes/csrf_token.html" %}
{% if statementOfCapitalErrorMsg %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down

0 comments on commit 0760097

Please sign in to comment.