Skip to content

Commit c6b1bef

Browse files
committed
Bug fix: Fix broken confirmation forms due to 'DOMNodeInserted' removal
1 parent 3d8e975 commit c6b1bef

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "showdown-chatbot",
3-
"version": "2.11.3",
3+
"version": "2.11.4",
44
"author": {
55
"name": "Agustin San Roman",
66
"email": "agustinsanromanguzman@gmail.com",

src/server/html-maker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports.generate = function (body, loginData, menu, options) {
3131
}
3232
}
3333

34-
buf += '<script type="text/javascript" src="/static/csrf-protect.js"></script>';
34+
buf += '<script type="text/javascript" src="/static/csrf-protect-v2.js"></script>';
3535

3636
if (options.scripts) {
3737
for (let i = 0; i < options.scripts.length; i++) {
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,38 @@ function getCookie(name) {
66
if (parts.length == 2) return parts.pop().split(";").shift();
77
}
88

9-
document.addEventListener("DOMContentLoaded", function () {
10-
if (window.$) {
11-
$(document).bind('ajaxSend', function (elm, xhr, s) {
12-
if (s.type != 'GET') {
13-
xhr.setRequestHeader('x-csrf-token', getCookie("usertoken"));
14-
}
15-
});
16-
}
17-
9+
function updateForms() {
1810
var forms = document.getElementsByTagName("form");
1911
for (var i = 0; i < forms.length; i++) {
2012
var form = forms[i];
21-
if ((form.method + "").toLowerCase() === "post") {
22-
var input = document.createElement("input");
23-
input.type = "hidden";
24-
input.name = "x-csrf-token";
25-
input.value = getCookie("usertoken");
26-
form.appendChild(input);
13+
14+
if (form.csrf_modified) {
15+
continue;
2716
}
28-
}
29-
});
3017

31-
document.addEventListener('DOMNodeInserted', function(e) {
32-
if (e.target.localName === "form") {
33-
var form = e.target;
3418
if ((form.method + "").toLowerCase() === "post") {
3519
var input = document.createElement("input");
3620
input.type = "hidden";
3721
input.name = "x-csrf-token";
3822
input.value = getCookie("usertoken");
3923
form.appendChild(input);
4024
}
25+
26+
form.csrf_modified = "true";
4127
}
28+
}
29+
30+
document.addEventListener("DOMContentLoaded", function () {
31+
if (window.$) {
32+
$(document).bind('ajaxSend', function (elm, xhr, s) {
33+
if (s.type != 'GET') {
34+
xhr.setRequestHeader('x-csrf-token', getCookie("usertoken"));
35+
}
36+
});
37+
}
38+
39+
updateForms();
40+
41+
var observer = new MutationObserver(updateForms);
42+
observer.observe(document.querySelector("body"), { childList: true, subtree: true, attributes: false });
4243
});

0 commit comments

Comments
 (0)