Skip to content

Commit

Permalink
BAU: Fixes csrf implicit verification on delete page
Browse files Browse the repository at this point in the history
  • Loading branch information
willfish committed Sep 19, 2024
1 parent 7bda130 commit d947587
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/controllers/deleteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { type NextFunction, type Request, type Response } from 'express'
import { ApiService } from '../services/apiService'
import { CommonService } from '../services/commonService'
import { DashboardPresenter } from '../presenters/dashboardPresenter'
import { generateToken } from '../config/csrf'

export const showDeleteKey = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
const user = CommonService.handleRequest(req)
const customerKeyId = req.params.customerKeyId
const apiKey = await ApiService.getKey(user, customerKeyId)
const createdAt = DashboardPresenter.formatDate(apiKey.CreatedAt, true)
const csrfToken = generateToken(req, res)

res.render('delete', { apiKey, createdAt, backLinkHref: '/dashboard' })
res.render('delete', { apiKey, csrfToken, createdAt, backLinkHref: '/dashboard' })
} catch (error) {
next(error)
}
Expand Down
1 change: 1 addition & 0 deletions views/delete.njk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</table>
<form method="POST"
action="/dashboard/{{ apiKey.CustomerApiKeyId }}/delete">
<input type="hidden" name="_csrf" value="{{csrfToken}}">
<div class="govuk-button-group">
<button class="govuk-button govuk-button--warning" data-module="govuk-button">Delete</button>
<a href="/dashboard" class="govuk-link">Cancel</a>
Expand Down

0 comments on commit d947587

Please sign in to comment.