@arnaudw38/nodebb-plugin-spam-be-gone 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +7 -68
- package/package.json +5 -5
- package/public/js/scripts.js +3 -145
- package/CHANGELOG.md +0 -68
package/library.js
CHANGED
|
@@ -4,6 +4,7 @@ const util = require('util');
|
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const querystring = require('querystring');
|
|
6
6
|
const Honeypot = require('project-honeypot');
|
|
7
|
+
const stopforumspam = require('stopforumspam');
|
|
7
8
|
|
|
8
9
|
const winston = require.main.require('winston');
|
|
9
10
|
const nconf = require.main.require('nconf');
|
|
@@ -99,6 +100,9 @@ Plugin.load = async function (params) {
|
|
|
99
100
|
if (!settings.akismetMinReputationHam) {
|
|
100
101
|
settings.akismetMinReputationHam = 10;
|
|
101
102
|
}
|
|
103
|
+
if (settings.stopforumspamApiKey) {
|
|
104
|
+
stopforumspam.Key(settings.stopforumspamApiKey);
|
|
105
|
+
}
|
|
102
106
|
|
|
103
107
|
pluginSettings = settings;
|
|
104
108
|
|
|
@@ -133,7 +137,7 @@ Plugin.report = async function (req, res, next) {
|
|
|
133
137
|
if (isAdmin) {
|
|
134
138
|
return res.status(403).send({ message: '[[spam-be-gone:cant-report-admin]]' });
|
|
135
139
|
}
|
|
136
|
-
await
|
|
140
|
+
await stopforumspam.submit({ ip: ips[0], email: fields.email, username: fields.username }, `Manual submission from user: ${req.uid} to user: ${fields.uid} via ${pluginData.id}`);
|
|
137
141
|
res.status(200).json({ message: '[[spam-be-gone:user-reported]]' });
|
|
138
142
|
} catch (err) {
|
|
139
143
|
winston.error(`[plugins/${pluginData.nbbId}][report-error] ${err.message}`);
|
|
@@ -148,7 +152,7 @@ Plugin.reportFromQueue = async (req, res) => {
|
|
|
148
152
|
}
|
|
149
153
|
const submitData = { ip: data.ip, email: data.email, username: data.username };
|
|
150
154
|
try {
|
|
151
|
-
await
|
|
155
|
+
await stopforumspam.submit(submitData, `Manual submission from user: ${req.uid} to user: ${data.username} via ${pluginData.id}`);
|
|
152
156
|
res.status(200).json({ message: '[[spam-be-gone:user-reported]]' });
|
|
153
157
|
} catch (err) {
|
|
154
158
|
winston.error(`[plugins/${pluginData.nbbId}][report-error] ${err.message}\n${JSON.stringify(submitData, null, 4)}`);
|
|
@@ -279,7 +283,7 @@ Plugin.getRegistrationQueue = async function (data) {
|
|
|
279
283
|
async function augmentWitSpamData(user) {
|
|
280
284
|
try {
|
|
281
285
|
user.ip = user.ip.replace('::ffff:', '');
|
|
282
|
-
let body = await
|
|
286
|
+
let body = await stopforumspam.isSpammer({ ip: user.ip, email: user.email, username: user.username, f: 'json' });
|
|
283
287
|
if (!body) {
|
|
284
288
|
body = { success: 1, username: { frequency: 0, appears: 0 }, email: { frequency: 0, appears: 0 }, ip: { frequency: 0, appears: 0, asn: null } };
|
|
285
289
|
}
|
|
@@ -392,71 +396,6 @@ Plugin._turnstileCheck = async function (req) {
|
|
|
392
396
|
});
|
|
393
397
|
};
|
|
394
398
|
|
|
395
|
-
|
|
396
|
-
async function stopForumSpamLookup({ ip, email, username }) {
|
|
397
|
-
const params = new URLSearchParams();
|
|
398
|
-
params.set('f', 'json');
|
|
399
|
-
if (ip) params.set('ip', ip);
|
|
400
|
-
if (email) params.set('email', email);
|
|
401
|
-
if (username) params.set('username', username);
|
|
402
|
-
|
|
403
|
-
const res = await fetch(`https://api.stopforumspam.org/api?${params.toString()}`, {
|
|
404
|
-
headers: {
|
|
405
|
-
accept: 'application/json',
|
|
406
|
-
'user-agent': pluginData.id,
|
|
407
|
-
},
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
if (!res.ok) {
|
|
411
|
-
throw new Error(`StopForumSpam lookup failed (${res.status})`);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return await res.json();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async function stopForumSpamSubmit({ ip, email, username }, evidence) {
|
|
418
|
-
if (!pluginSettings.stopforumspamApiKey) {
|
|
419
|
-
throw new Error('[[spam-be-gone:sfs-api-key-not-set]]');
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
const body = new URLSearchParams();
|
|
423
|
-
body.set('api_key', pluginSettings.stopforumspamApiKey);
|
|
424
|
-
body.set('api', 'json');
|
|
425
|
-
if (ip) body.set('ip_addr', ip);
|
|
426
|
-
if (email) body.set('email', email);
|
|
427
|
-
if (username) body.set('username', username);
|
|
428
|
-
if (evidence) body.set('evidence', evidence);
|
|
429
|
-
|
|
430
|
-
const res = await fetch('https://www.stopforumspam.com/add.php', {
|
|
431
|
-
method: 'POST',
|
|
432
|
-
headers: {
|
|
433
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
434
|
-
accept: 'application/json, text/plain;q=0.9, */*;q=0.8',
|
|
435
|
-
'user-agent': pluginData.id,
|
|
436
|
-
},
|
|
437
|
-
body: body.toString(),
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
const text = await res.text();
|
|
441
|
-
if (!res.ok) {
|
|
442
|
-
throw new Error(`StopForumSpam submit failed (${res.status})`);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
try {
|
|
446
|
-
const parsed = JSON.parse(text);
|
|
447
|
-
if (parsed.success === 0 || parsed.error) {
|
|
448
|
-
throw new Error(parsed.error || 'StopForumSpam submit failed');
|
|
449
|
-
}
|
|
450
|
-
return parsed;
|
|
451
|
-
} catch (err) {
|
|
452
|
-
// Some SFS responses can be plain text; consider HTTP 200 success as accepted.
|
|
453
|
-
if (/error/i.test(text)) {
|
|
454
|
-
throw err instanceof Error ? err : new Error('StopForumSpam submit failed');
|
|
455
|
-
}
|
|
456
|
-
return { success: 1, raw: text };
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
399
|
Plugin.admin = {
|
|
461
400
|
menu: function (custom_header, callback) {
|
|
462
401
|
custom_header.plugins.push({ route: `/plugins/${pluginData.nbbId}`, icon: pluginData.faIcon, name: pluginData.name });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnaudw38/nodebb-plugin-spam-be-gone",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Anti-spam plugin for NodeBB 4.x using Akismet, StopForumSpam
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Anti-spam plugin for NodeBB 4.x using Akismet, StopForumSpam, ProjectHoneyPot, and Cloudflare Turnstile (Turnstile-only fork)",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"scripts": {},
|
|
7
7
|
"repository": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"async": "^3.2.0",
|
|
36
|
-
"project-honeypot": "~0.0.0"
|
|
36
|
+
"project-honeypot": "~0.0.0",
|
|
37
|
+
"stopforumspam": "^1.3.8"
|
|
37
38
|
},
|
|
38
39
|
"nbbpm": {
|
|
39
40
|
"compatibility": "^4.0.0"
|
|
@@ -49,8 +50,7 @@
|
|
|
49
50
|
"upgrades/",
|
|
50
51
|
"plugin.json",
|
|
51
52
|
"README.md",
|
|
52
|
-
"LICENSE"
|
|
53
|
-
"CHANGELOG.md"
|
|
53
|
+
"LICENSE"
|
|
54
54
|
],
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
package/public/js/scripts.js
CHANGED
|
@@ -5,11 +5,6 @@
|
|
|
5
5
|
$(function () {
|
|
6
6
|
var pluginName = 'spam-be-gone';
|
|
7
7
|
var turnstileScriptUrl = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
|
8
|
-
var turnstileState = {
|
|
9
|
-
widgets: {},
|
|
10
|
-
loginBindingsAttached: false,
|
|
11
|
-
loginResetTimers: [],
|
|
12
|
-
};
|
|
13
8
|
|
|
14
9
|
function getTurnstileArgs() {
|
|
15
10
|
return ajaxify.data && ajaxify.data.turnstileArgs;
|
|
@@ -30,126 +25,7 @@ $(function () {
|
|
|
30
25
|
});
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
function
|
|
34
|
-
var input = document.querySelector('input[name="cf-turnstile-response"]');
|
|
35
|
-
return input && input.value;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getCurrentLoginTurnstileTargetId() {
|
|
39
|
-
var args = getTurnstileArgs();
|
|
40
|
-
return args && args.targetId;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function resetTurnstileWidget(targetId) {
|
|
44
|
-
if (typeof turnstile === 'undefined') {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
targetId = targetId || getCurrentLoginTurnstileTargetId();
|
|
48
|
-
if (!targetId) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
var widgetId = turnstileState.widgets[targetId];
|
|
52
|
-
if (widgetId === undefined || widgetId === null) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
turnstile.reset(widgetId);
|
|
57
|
-
return true;
|
|
58
|
-
} catch (err) {
|
|
59
|
-
// Ignore reset errors when the widget is already destroyed by navigation.
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function scheduleLoginTurnstileReset() {
|
|
65
|
-
// Turnstile tokens are single-use. On failed login, NodeBB often keeps the user on the
|
|
66
|
-
// same page and may handle submission via AJAX/click handlers. We try multiple delayed resets.
|
|
67
|
-
turnstileState.loginResetTimers.forEach(function (timerId) {
|
|
68
|
-
window.clearTimeout(timerId);
|
|
69
|
-
});
|
|
70
|
-
turnstileState.loginResetTimers = [];
|
|
71
|
-
|
|
72
|
-
[700, 1400, 2600, 4200].forEach(function (delay) {
|
|
73
|
-
var timerId = window.setTimeout(function () {
|
|
74
|
-
var onLoginPage = !ajaxify.data || !ajaxify.data.tpl_url || ajaxify.data.tpl_url === 'login';
|
|
75
|
-
if (!onLoginPage) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
var targetId = getCurrentLoginTurnstileTargetId();
|
|
79
|
-
if (!targetId || !document.getElementById(targetId)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
resetTurnstileWidget(targetId);
|
|
83
|
-
}, delay);
|
|
84
|
-
turnstileState.loginResetTimers.push(timerId);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function bindLoginRetryReset() {
|
|
89
|
-
if (turnstileState.loginBindingsAttached) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
turnstileState.loginBindingsAttached = true;
|
|
93
|
-
|
|
94
|
-
function loginSubmitTrigger() {
|
|
95
|
-
scheduleLoginTurnstileReset();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Native capture listeners only (avoid duplicate handlers/race conditions with jQuery delegates).
|
|
99
|
-
document.addEventListener('click', function (ev) {
|
|
100
|
-
var btn = ev.target && ev.target.closest ? ev.target.closest('[component="login/submit"], #login [type="submit"], form[action*="/login"] [type="submit"], form[data-action="login"] [type="submit"], button[type="submit"]') : null;
|
|
101
|
-
if (!btn) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
var inLogin = btn.closest && btn.closest('#login, form[action*="/login"], form[data-action="login"], [component="login"]');
|
|
105
|
-
if (inLogin || (ajaxify.data && ajaxify.data.tpl_url === 'login')) {
|
|
106
|
-
loginSubmitTrigger();
|
|
107
|
-
}
|
|
108
|
-
}, true);
|
|
109
|
-
|
|
110
|
-
// Enter key in login fields for themes that trigger login without a click event.
|
|
111
|
-
document.addEventListener('keydown', function (ev) {
|
|
112
|
-
if (ev.key !== 'Enter') {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
var el = ev.target;
|
|
116
|
-
if (!el || !el.closest) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
var inLogin = el.closest('#login, form[action*="/login"], form[data-action="login"], [component="login"]');
|
|
120
|
-
if (inLogin || (ajaxify.data && ajaxify.data.tpl_url === 'login')) {
|
|
121
|
-
loginSubmitTrigger();
|
|
122
|
-
}
|
|
123
|
-
}, true);
|
|
124
|
-
|
|
125
|
-
// Extra safety: reset again when a login error alert appears (covers AJAX flows that do not
|
|
126
|
-
// reliably trigger the expected submit/click path in some themes).
|
|
127
|
-
if (window.MutationObserver) {
|
|
128
|
-
var observer = new MutationObserver(function (mutations) {
|
|
129
|
-
var onLoginPage = !ajaxify.data || !ajaxify.data.tpl_url || ajaxify.data.tpl_url === 'login';
|
|
130
|
-
if (!onLoginPage) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
for (var i = 0; i < mutations.length; i += 1) {
|
|
134
|
-
for (var j = 0; j < mutations[i].addedNodes.length; j += 1) {
|
|
135
|
-
var n = mutations[i].addedNodes[j];
|
|
136
|
-
if (!n || n.nodeType !== 1) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
var hasError = (n.matches && n.matches('.alert-danger, .alert-error, .text-danger, [component="alerts/error"]')) ||
|
|
140
|
-
(n.querySelector && n.querySelector('.alert-danger, .alert-error, .text-danger, [component="alerts/error"]'));
|
|
141
|
-
if (hasError) {
|
|
142
|
-
scheduleLoginTurnstileReset();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function renderTurnstileIfNeeded(isLoginPage) {
|
|
28
|
+
function renderTurnstileIfNeeded(isLoginPage) {
|
|
153
29
|
var args = getTurnstileArgs();
|
|
154
30
|
if (!args || (isLoginPage && !args.addLoginTurnstile)) {
|
|
155
31
|
return;
|
|
@@ -161,18 +37,10 @@ function renderTurnstileIfNeeded(isLoginPage) {
|
|
|
161
37
|
return;
|
|
162
38
|
}
|
|
163
39
|
var target = document.getElementById(args.targetId);
|
|
164
|
-
if (!target) {
|
|
40
|
+
if (!target || target.dataset.turnstileRendered === '1') {
|
|
165
41
|
return;
|
|
166
42
|
}
|
|
167
|
-
|
|
168
|
-
if (target.dataset.turnstileRendered === '1') {
|
|
169
|
-
if (isLoginPage) {
|
|
170
|
-
bindLoginRetryReset();
|
|
171
|
-
}
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
var widgetId = turnstile.render('#' + args.targetId, {
|
|
43
|
+
turnstile.render('#' + args.targetId, {
|
|
176
44
|
sitekey: args.siteKey,
|
|
177
45
|
theme: args.theme || 'auto',
|
|
178
46
|
size: args.size || 'normal',
|
|
@@ -187,18 +55,8 @@ function renderTurnstileIfNeeded(isLoginPage) {
|
|
|
187
55
|
'error-callback': function () {
|
|
188
56
|
require(['alerts'], function (alerts) { alerts.error('[[spam-be-gone:captcha-not-verified]]'); });
|
|
189
57
|
},
|
|
190
|
-
'expired-callback': function () {
|
|
191
|
-
resetTurnstileWidget(args.targetId);
|
|
192
|
-
},
|
|
193
|
-
'timeout-callback': function () {
|
|
194
|
-
resetTurnstileWidget(args.targetId);
|
|
195
|
-
},
|
|
196
58
|
});
|
|
197
59
|
target.dataset.turnstileRendered = '1';
|
|
198
|
-
turnstileState.widgets[args.targetId] = widgetId;
|
|
199
|
-
if (isLoginPage) {
|
|
200
|
-
bindLoginRetryReset();
|
|
201
|
-
}
|
|
202
60
|
})
|
|
203
61
|
.catch(function () {
|
|
204
62
|
require(['alerts'], function (alerts) { alerts.error('Failed to load Cloudflare Turnstile'); });
|
package/CHANGELOG.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
## [1.0.8] - 2026-02-25
|
|
6
|
-
|
|
7
|
-
### Fixed
|
|
8
|
-
- Fixed Turnstile login retry reset in themes/login flows where previous click/enter hooks did not reliably trigger the widget reset.
|
|
9
|
-
- Made login retry reset logic target the current Turnstile container dynamically instead of relying on a stale target id.
|
|
10
|
-
- Added a fallback reset trigger when login error alerts are rendered on the login page.
|
|
11
|
-
|
|
12
|
-
## [1.0.7] - 2026-02-25
|
|
13
|
-
|
|
14
|
-
### Fixed
|
|
15
|
-
- Login retry Turnstile reset now uses native event listeners only (removed jQuery delegated login listeners).
|
|
16
|
-
- Prevented duplicate retry-reset triggers caused by mixed jQuery + native listeners on some NodeBB themes.
|
|
17
|
-
|
|
18
|
-
### Changed
|
|
19
|
-
- Simplified login retry detection to click + Enter key flows (removed submit listener).
|
|
20
|
-
|
|
21
|
-
## [1.0.6] - 2026-02-25
|
|
22
|
-
|
|
23
|
-
### Fixed
|
|
24
|
-
- Fixed login retry Turnstile reset trigger on NodeBB login flows that do not emit the expected jQuery submit/click events.
|
|
25
|
-
- Prevented missing reset after failed login without page reload by adding capture-phase submit/click/Enter listeners.
|
|
26
|
-
|
|
27
|
-
## [1.0.5] - 2026-02-25
|
|
28
|
-
|
|
29
|
-
### Fixed
|
|
30
|
-
- Fixed Turnstile not resetting after a failed login attempt when retrying on the same page.
|
|
31
|
-
- Reset is now triggered after login submit if the user remains on the login page, even if the hidden Turnstile token input has already been cleared by client-side login logic.
|
|
32
|
-
|
|
33
|
-
## [1.0.4] - 2026-02-25
|
|
34
|
-
|
|
35
|
-
### Fixed
|
|
36
|
-
- Fixed login UX regression where the Turnstile widget was resetting while typing in the username/password fields.
|
|
37
|
-
- Turnstile now resets only after a login submission retry flow (failed login without page reload), not on every keystroke.
|
|
38
|
-
|
|
39
|
-
## [1.0.3] - 2026-02-25
|
|
40
|
-
|
|
41
|
-
### Fixed
|
|
42
|
-
- Fixed Cloudflare Turnstile failure on login retry without page reload.
|
|
43
|
-
- Reset Turnstile widget automatically after a failed login attempt (Turnstile tokens are single-use).
|
|
44
|
-
- Improved login flow reliability when users retry authentication on the same page.
|
|
45
|
-
|
|
46
|
-
### Improved
|
|
47
|
-
- Added safer Turnstile widget state handling on the login form.
|
|
48
|
-
- Added callbacks handling for expired/timeout token states.
|
|
49
|
-
- Better UX during repeated login attempts without manual refresh.
|
|
50
|
-
- Removed deprecated `stopforumspam` npm dependency and replaced it with direct StopForumSpam API requests using native `fetch` (eliminates `q` / `node-domexception` install warnings).
|
|
51
|
-
|
|
52
|
-
## [1.0.2] - 2026-02-25
|
|
53
|
-
|
|
54
|
-
### UI
|
|
55
|
-
- Replaced visible 'Turnstile' label with a more user-friendly label:
|
|
56
|
-
- French: `Vérification de sécurité`
|
|
57
|
-
|
|
58
|
-
## [1.0.1] - 2026-02-25
|
|
59
|
-
|
|
60
|
-
### Changed
|
|
61
|
-
- Refactored plugin for NodeBB 4.x compatibility.
|
|
62
|
-
- Removed legacy reCAPTCHA and hCaptcha integrations.
|
|
63
|
-
- Added Cloudflare Turnstile support (register + optional login protection).
|
|
64
|
-
- Simplified package/tooling for a minimal runtime-focused plugin setup.
|
|
65
|
-
|
|
66
|
-
### Docs
|
|
67
|
-
- Rewrote README in English (Turnstile-only, no images).
|
|
68
|
-
- Added npm-ready/publish-ready package metadata and documentation.
|