playsocketjs 5.2.0 → 5.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsocketjs",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "WebSocket wrapper for creating simple multiplayer systems with ease.",
5
5
  "type": "module",
6
6
  "module": "./src/client/client.js",
@@ -9,7 +9,7 @@ export const HEARTBEAT_INTERVAL = 5000;
9
9
  /**
10
10
  * Library version, must match package.json
11
11
  */
12
- export const VERSION = "5.2.0";
12
+ export const VERSION = "5.2.1";
13
13
 
14
14
  /**
15
15
  * Logging prefixes
@@ -110,7 +110,7 @@ export default class CRDTManager {
110
110
  importPropertyUpdate(update) {
111
111
  try {
112
112
  const { key, operation: rawOperation, vectorClock } = update;
113
- const operation = /** @type {Operation} */ (this.#sanitizeValue(rawOperation));
113
+ const operation = /** @type {Operation} */ (this.#normalizeAndCopy(rawOperation));
114
114
  if (this.#debug) console.log(CONSOLE_PREFIX + "Importing update:", update); // Debug
115
115
 
116
116
  // Check key limit to safeguard against too many keys
@@ -183,9 +183,9 @@ export default class CRDTManager {
183
183
  */
184
184
  updateProperty(key, type, value, secondValue) {
185
185
  try {
186
- // Sanitize inputs
187
- value = this.#sanitizeValue(value);
188
- secondValue = this.#sanitizeValue(secondValue);
186
+ // Normalize inputs
187
+ value = this.#normalizeAndCopy(value);
188
+ secondValue = this.#normalizeAndCopy(secondValue);
189
189
 
190
190
  // Debug log
191
191
  if (this.#debug) console.log(CONSOLE_PREFIX + `Updating property with key ${key}, type ${type}, value ${value} and secondValue ${secondValue}`);
@@ -431,20 +431,15 @@ export default class CRDTManager {
431
431
  }
432
432
 
433
433
  /**
434
- * Remove HTML to prevent XSS and enforce size limits
435
- * @param {*} value - Value to sanitize
436
- * @returns {*} Sanitized value
434
+ * Enforce size limit, normalize undefined to null, and return deep copy
435
+ * @param {*} value - Value to normalize
436
+ * @returns {*} Normalized value
437
437
  */
438
- #sanitizeValue(value) {
439
- if (value === undefined) return null; // Normalize undefined to null to avoid divergence in transport
440
-
441
- // Check total serialized size
442
- const jsonString = JSON.stringify(value);
443
- if (jsonString?.length > 50000) throw new Error("Value too large"); // 50KB limit
444
-
445
- if (typeof value === "string") return (value.includes("<") || value.includes(">")) ? value.replace(/[<>]/g, "") : value;
446
- if (Array.isArray(value)) return Array.from(value, item => this.#sanitizeValue(item));
447
- if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.#sanitizeValue(v)]));
438
+ #normalizeAndCopy(value) {
439
+ if (value === undefined) return null;
440
+ if (JSON.stringify(value)?.length > 50_000) throw new Error("Value too large"); // 50KB limit
441
+ if (Array.isArray(value)) return Array.from(value, item => this.#normalizeAndCopy(item));
442
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.#normalizeAndCopy(v)]));
448
443
  return value;
449
444
  }
450
445
 
@@ -8,7 +8,7 @@ export declare const HEARTBEAT_INTERVAL = 5000;
8
8
  /**
9
9
  * Library version, must match package.json
10
10
  */
11
- export declare const VERSION = "5.2.0";
11
+ export declare const VERSION = "5.2.1";
12
12
  /**
13
13
  * Logging prefixes
14
14
  */