@redsocs/spam-warden 1.3.2 → 1.3.4

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/README.md CHANGED
@@ -193,7 +193,6 @@ Sanitized: "Win [CARD_MASKED] now! [at]TUNA_FISH"
193
193
 
194
194
  About
195
195
 
196
- - **Version** 1.3.0 (Engine v11.06)
197
196
  - **Author:** [RedSocs](https://github.com/RedSocs)
198
197
  - **License:** MIT
199
198
  - **Inquiries & Enterprise Support:** [pichit[at]redsocs.com](https://www.google.com/search?q=mailto%3Apichit%40redsocs.com)
@@ -255,18 +255,41 @@ var SWModule = (() => {
255
255
  } catch (e) {
256
256
  }
257
257
  },
258
- _send: function(url, data) {
258
+ _send: async function(url, data) {
259
259
  if (!url) return;
260
260
  let finalUrl = url.indexOf("://") === -1 ? (/(^localhost|^127\.0\.0\.1)(:\d+)?(\/|$)/i.test(url) ? "http://" : "https://") + url : url;
261
261
  if (typeof navigator !== "undefined" && navigator.sendBeacon) {
262
262
  try {
263
- if (navigator.sendBeacon(finalUrl, new Blob([JSON.stringify(data)], { type: "application/json" }))) return;
263
+ const success = navigator.sendBeacon(finalUrl, new Blob([JSON.stringify(data)], { type: "application/json" }));
264
+ if (success) return;
264
265
  } catch (e) {
266
+ console.warn("[SpamWarden] Beacon failed, falling back to fetch.");
265
267
  }
266
268
  }
267
269
  if (typeof fetch !== "undefined") {
268
- fetch(finalUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), keepalive: true }).catch(() => {
269
- });
270
+ try {
271
+ const response = await fetch(finalUrl, {
272
+ method: "POST",
273
+ headers: { "Content-Type": "application/json" },
274
+ body: JSON.stringify(data),
275
+ keepalive: true
276
+ });
277
+ if (!response.ok) {
278
+ throw new Error(`SIEM rejected payload: ${response.status}`);
279
+ }
280
+ } catch (err) {
281
+ console.error("[SpamWarden] \u26A0\uFE0F Critical: Telemetry delivery failed.", err);
282
+ this._persistToAuditQueue(data);
283
+ }
284
+ }
285
+ },
286
+ // Helper to ensure we have a record even if the network is dead
287
+ _persistToAuditQueue: function(data) {
288
+ try {
289
+ const queue = JSON.parse(localStorage.getItem("sw_audit_queue") || "[]");
290
+ queue.push({ timestamp: Date.now(), data });
291
+ localStorage.setItem("sw_audit_queue", JSON.stringify(queue.slice(-10)));
292
+ } catch (e) {
270
293
  }
271
294
  }
272
295
  };
@@ -291,23 +314,6 @@ var SWModule = (() => {
291
314
  e.stopImmediatePropagation();
292
315
  if (self._config.onSpam) self._config.onSpam(result);
293
316
  else alert("Submission Blocked: System detected malicious input.");
294
- } else {
295
- const guardEl = document.getElementById("sw-guard");
296
- if (guardEl) {
297
- const token = guardEl.getAttribute("data-sw-token") || "";
298
- const dynamicSeed = guardEl.getAttribute("data-sw-seed") || "";
299
- const payload = combinedText + token + dynamicSeed;
300
- let hash = 5381;
301
- for (let i = 0; i < payload.length; i++) {
302
- hash = (hash << 5) + hash + payload.charCodeAt(i);
303
- }
304
- const signature = Math.abs(hash).toString(16);
305
- const sigInput = document.createElement("input");
306
- sigInput.type = "hidden";
307
- sigInput.name = "sw_signature";
308
- sigInput.value = signature;
309
- e.target.appendChild(sigInput);
310
- }
311
317
  }
312
318
  }
313
319
  }, true);
@@ -386,7 +392,6 @@ var SWModule = (() => {
386
392
  } else {
387
393
  window.spamwarden = {
388
394
  version: SpamWarden.version,
389
- spamcheck: do_pow(),
390
395
  isSpam: function() {
391
396
  return this.spamcheck().isSpam;
392
397
  }