i18next-http-middleware 3.7.3 → 3.7.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.
@@ -81,9 +81,8 @@ var LanguageDetector = function () {
81
81
  if (!detections) return;
82
82
  if (!Array.isArray(detections)) detections = [detections];
83
83
  detections = detections.filter(function (d) {
84
- return d !== undefined && d !== null;
85
- });
86
- detections = detections.map(function (d) {
84
+ return d !== undefined && d !== null && !utils.hasXSS(d);
85
+ }).map(function (d) {
87
86
  return _this.options.convertDetectedLanguage(d);
88
87
  });
89
88
  if (_this.services.languageUtils.getBestMatchFromCodes) {
package/cjs/utils.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.defaults = defaults;
7
7
  exports.escape = escape;
8
8
  exports.extend = extend;
9
+ exports.hasXSS = hasXSS;
9
10
  exports.removeLngFromUrl = removeLngFromUrl;
10
11
  exports.setPath = setPath;
11
12
  function setPath(object, path, newValue) {
@@ -60,4 +61,11 @@ function removeLngFromUrl(url, lookupFromPathIndex) {
60
61
  }
61
62
  function escape(str) {
62
63
  return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
64
+ }
65
+ function hasXSS(input) {
66
+ if (typeof input !== 'string') return false;
67
+ var xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
68
+ return xssPatterns.some(function (pattern) {
69
+ return pattern.test(input);
70
+ });
63
71
  }
@@ -72,9 +72,8 @@ var LanguageDetector = function () {
72
72
  if (!detections) return;
73
73
  if (!Array.isArray(detections)) detections = [detections];
74
74
  detections = detections.filter(function (d) {
75
- return d !== undefined && d !== null;
76
- });
77
- detections = detections.map(function (d) {
75
+ return d !== undefined && d !== null && !utils.hasXSS(d);
76
+ }).map(function (d) {
78
77
  return _this.options.convertDetectedLanguage(d);
79
78
  });
80
79
  if (_this.services.languageUtils.getBestMatchFromCodes) {
package/esm/utils.js CHANGED
@@ -50,4 +50,11 @@ export function removeLngFromUrl(url, lookupFromPathIndex) {
50
50
  }
51
51
  export function escape(str) {
52
52
  return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
53
+ }
54
+ export function hasXSS(input) {
55
+ if (typeof input !== 'string') return false;
56
+ var xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
57
+ return xssPatterns.some(function (pattern) {
58
+ return pattern.test(input);
59
+ });
53
60
  }
@@ -66,8 +66,9 @@ class LanguageDetector {
66
66
  if (!detections) return
67
67
  if (!Array.isArray(detections)) detections = [detections]
68
68
 
69
- detections = detections.filter((d) => d !== undefined && d !== null)
70
- detections = detections.map((d) => this.options.convertDetectedLanguage(d))
69
+ detections = detections
70
+ .filter((d) => d !== undefined && d !== null && !utils.hasXSS(d))
71
+ .map((d) => this.options.convertDetectedLanguage(d))
71
72
 
72
73
  if (this.services.languageUtils.getBestMatchFromCodes) { // new i18next v19.5.0
73
74
  found = this.services.languageUtils.getBestMatchFromCodes(detections)
package/lib/utils.js CHANGED
@@ -69,3 +69,26 @@ export function escape (str) {
69
69
  .replace(/\\/g, '&#x5C;')
70
70
  .replace(/`/g, '&#96;'))
71
71
  }
72
+
73
+ export function hasXSS (input) {
74
+ if (typeof input !== 'string') return false
75
+
76
+ // Common XSS attack patterns
77
+ const xssPatterns = [
78
+ /<\s*script.*?>/i,
79
+ /<\s*\/\s*script\s*>/i,
80
+ /<\s*img.*?on\w+\s*=/i,
81
+ /<\s*\w+\s*on\w+\s*=.*?>/i,
82
+ /javascript\s*:/i,
83
+ /vbscript\s*:/i,
84
+ /expression\s*\(/i,
85
+ /eval\s*\(/i,
86
+ /alert\s*\(/i,
87
+ /document\.cookie/i,
88
+ /document\.write\s*\(/i,
89
+ /window\.location/i,
90
+ /innerHTML/i
91
+ ]
92
+
93
+ return xssPatterns.some((pattern) => pattern.test(input))
94
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-http-middleware",
3
- "version": "3.7.3",
3
+ "version": "3.7.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",