From 90d45591621a318b5580de2b9d4ce0ffd62f7174 Mon Sep 17 00:00:00 2001 From: NHAS Date: Wed, 13 Sep 2023 13:36:25 +1200 Subject: [PATCH] Move to using more robust csrf protections --- go.mod | 2 +- go.sum | 6 + .../authenticators/methods/webauthn.go | 2 +- ui/src/js/devices.js | 6 +- ui/src/js/groups.js | 7 +- ui/src/js/policy.js | 8 +- ui/src/js/settings.js | 7 +- ui/src/js/tokens.js | 8 +- ui/src/js/users.js | 7 +- ui/templates/change_password.html | 1 + ui/templates/delete_modal.html | 1 + ui/templates/menus.html | 3 +- ui/ui_webserver.go | 144 +++++++++--------- 13 files changed, 117 insertions(+), 85 deletions(-) diff --git a/go.mod b/go.mod index 905e8df4..ed8d9651 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/NHAS/wag go 1.21.0 require ( - github.com/NHAS/session v0.0.0-20230912232900-857b7061aedb + github.com/NHAS/session v0.0.0-20230913013109-aef0bdd63caa github.com/NHAS/webauthn v0.0.0-20230701002608-24fb1253febd github.com/boombuler/barcode v1.0.1 github.com/cilium/ebpf v0.11.0 diff --git a/go.sum b/go.sum index 23be6815..73ccb3b1 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,12 @@ github.com/NHAS/session v0.0.0-20230829082122-79a308a78ac9 h1:xEvca6Mg8N0T2V5wkM github.com/NHAS/session v0.0.0-20230829082122-79a308a78ac9/go.mod h1:RrYUQgrmfMmXblxB8uWEWhmTKk24PT/VoMsyQ5PD580= github.com/NHAS/session v0.0.0-20230912232900-857b7061aedb h1:76HnrEP5YAV0bLaFhrbVv5SuaUYH+DJnPvIXYjdDkvw= github.com/NHAS/session v0.0.0-20230912232900-857b7061aedb/go.mod h1:RrYUQgrmfMmXblxB8uWEWhmTKk24PT/VoMsyQ5PD580= +github.com/NHAS/session v0.0.0-20230912234744-c2a3c81af157 h1:elFdIrZIamHa5iUwIAjmQcvt7y1OLnqdUXly/FzmrXg= +github.com/NHAS/session v0.0.0-20230912234744-c2a3c81af157/go.mod h1:RrYUQgrmfMmXblxB8uWEWhmTKk24PT/VoMsyQ5PD580= +github.com/NHAS/session v0.0.0-20230913001004-e3249bca36e8 h1:qe3uyCZEeRKTkx3UpJ8BhJcdJSnTcGc9r3QqqEDvb+M= +github.com/NHAS/session v0.0.0-20230913001004-e3249bca36e8/go.mod h1:RrYUQgrmfMmXblxB8uWEWhmTKk24PT/VoMsyQ5PD580= +github.com/NHAS/session v0.0.0-20230913013109-aef0bdd63caa h1:3fKRkxqoQtbOunf2lLIYkTvEC9qw3ADlOCWaugU7S+o= +github.com/NHAS/session v0.0.0-20230913013109-aef0bdd63caa/go.mod h1:RrYUQgrmfMmXblxB8uWEWhmTKk24PT/VoMsyQ5PD580= github.com/NHAS/webauthn v0.0.0-20230701002608-24fb1253febd h1:I3Zx79SVWGG5Qq2tbJDiEiKEpuY53EpUCXx8mYLlNVg= github.com/NHAS/webauthn v0.0.0-20230701002608-24fb1253febd/go.mod h1:hglmpEbAdMVhruL46LJXV56PPbEJO6ovBg0uhqIG9Dw= github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= diff --git a/internal/webserver/authenticators/methods/webauthn.go b/internal/webserver/authenticators/methods/webauthn.go index addc752a..a65a9292 100644 --- a/internal/webserver/authenticators/methods/webauthn.go +++ b/internal/webserver/authenticators/methods/webauthn.go @@ -28,7 +28,7 @@ type Webauthn struct { func (wa *Webauthn) Init(settings map[string]string) (err error) { - wa.sessions, err = session.NewStore[*webauthn.SessionData]("authentication", 30*time.Minute, 1800, false) + wa.sessions, err = session.NewStore[*webauthn.SessionData]("authentication", "WAG-CSRF", 30*time.Minute, 1800, false) return err } diff --git a/ui/src/js/devices.js b/ui/src/js/devices.js index 7604c9fe..21c4c9c0 100755 --- a/ui/src/js/devices.js +++ b/ui/src/js/devices.js @@ -121,7 +121,8 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() }, body: JSON.stringify(ids) }).then((response) => { @@ -180,7 +181,8 @@ function action(onDevices, action, table) { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/src/js/groups.js b/ui/src/js/groups.js index 339a476f..6dacf6e7 100755 --- a/ui/src/js/groups.js +++ b/ui/src/js/groups.js @@ -119,7 +119,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(ids) }).then((response) => { @@ -179,7 +181,8 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/src/js/policy.js b/ui/src/js/policy.js index 53bf0b4b..20afdf43 100755 --- a/ui/src/js/policy.js +++ b/ui/src/js/policy.js @@ -132,7 +132,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(ids) }).then((response) => { @@ -184,7 +186,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/src/js/settings.js b/ui/src/js/settings.js index c1eea2b8..e78630ae 100644 --- a/ui/src/js/settings.js +++ b/ui/src/js/settings.js @@ -14,7 +14,8 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() }, body: JSON.stringify(data) }).then((response) => { @@ -51,7 +52,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/src/js/tokens.js b/ui/src/js/tokens.js index 36f27eff..cd1beb53 100755 --- a/ui/src/js/tokens.js +++ b/ui/src/js/tokens.js @@ -99,7 +99,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(ids) }).then(f => { @@ -127,7 +129,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/src/js/users.js b/ui/src/js/users.js index 81fe1599..59b150ce 100755 --- a/ui/src/js/users.js +++ b/ui/src/js/users.js @@ -150,7 +150,9 @@ $(function () { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() + }, body: JSON.stringify(ids) }).then((response) => { @@ -205,7 +207,8 @@ function action(onUsers, action, table) { credentials: 'same-origin', redirect: 'follow', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'WAG-CSRF': $("#csrf_token").val() }, body: JSON.stringify(data) }).then((response) => { diff --git a/ui/templates/change_password.html b/ui/templates/change_password.html index 44379d0b..ef7dbf3e 100755 --- a/ui/templates/change_password.html +++ b/ui/templates/change_password.html @@ -7,6 +7,7 @@
Change Password
+ {{ csrfToken }}
diff --git a/ui/templates/delete_modal.html b/ui/templates/delete_modal.html index 0c2ca191..c00e80bd 100644 --- a/ui/templates/delete_modal.html +++ b/ui/templates/delete_modal.html @@ -1,4 +1,5 @@ {{define "deleteConfirmationModal"}} +{{ csrfToken }}