Skip to content

Commit

Permalink
Fix(csrf): Send csrf token for the /change-password path (#535)
Browse files Browse the repository at this point in the history
* Fix(csrf): Send csrf token for the `/change-password` path

Signed-off-by: Kaung Zin Hein <[email protected]>

* Fix(csrf): Attach csrf-token to the HTML form

Signed-off-by: Kaung Zin Hein <[email protected]>

---------

Signed-off-by: Kaung Zin Hein <[email protected]>
  • Loading branch information
Zen-cronic authored Oct 5, 2024
1 parent 069e270 commit 683d489
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/changepassword/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ChangePasswordController extends Controller {

async get(ctx: Context) {

const csrfToken = await ctx.getCsrf();
ctx.response.type = 'text/html';
ctx.response.body = changePasswordForm(ctx.query.msg, ctx.query.error);

ctx.response.body = changePasswordForm(ctx.query.msg, ctx.query.error, csrfToken);
}

async post(ctx: Context<any>) {
Expand Down
3 changes: 2 additions & 1 deletion src/changepassword/formats/html.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { render } from '../../templates.js';

export function changePasswordForm(msg: string, error: string) {
export function changePasswordForm(msg: string, error: string, csrfToken: string) {

return render('changepassword', {
title: 'Change Password',
msg: msg,
error: error,
action: '/change-password',
csrfToken: csrfToken,
});

}
2 changes: 2 additions & 0 deletions templates/changepassword.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<p class="form-options"><a href="/">Cancel</a></p>
</fieldset>

<input type="hidden" name="csrf-token" value="{{ csrfToken }}" />

{{#each hiddenFields}}
<input type="hidden" name="{{@key}}" value="{{this}}" />
{{/each}}
Expand Down

0 comments on commit 683d489

Please sign in to comment.