bigpipe-util 0.1.4 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -30,3 +30,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
30
30
 
31
31
  ### Fixed
32
32
  - Arguments for non-method require calls
33
+
34
+ ## v0.2.0 - 2022-05-17
35
+
36
+ ### Added
37
+ - Shield to prevent "JSON Hijacking"
38
+ - Invalid node checking for AsyncDOM
39
+
40
+ ### Fixed
41
+ - Backdrop for 2+ opened dialogs
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bigpipe-util",
3
3
  "description": "This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.",
4
- "version": "0.1.4",
4
+ "version": "0.2.0",
5
5
  "keywords": [
6
6
  "bigpipe",
7
7
  "xhr",
@@ -15,6 +15,11 @@ export default class AsyncDOM {
15
15
  node = (node || document.documentElement).querySelector(selector);
16
16
  }
17
17
 
18
+ if (!node) {
19
+ console.error(`Selector '${selector}' does not match anything!`)
20
+ continue;
21
+ }
22
+
18
23
  switch (type) {
19
24
  case "eval":
20
25
  (new Function(content)).apply(node);
@@ -121,6 +121,17 @@ AsyncRequest.prototype.abort = function () {
121
121
  }
122
122
  };
123
123
 
124
+ AsyncRequest.prototype._unshieldResponseText = function (text) {
125
+ const shield = "for (;;);";
126
+ const shieldLength = shield.length;
127
+
128
+ if (text.length <= shieldLength) {
129
+ throw new Error("Response too short on async to " + this.getURI());
130
+ }
131
+
132
+ return text.substring(shieldLength);
133
+ };
134
+
124
135
  AsyncRequest.prototype.send = function () {
125
136
  const {uri, method} = this;
126
137
  let { data } = this;
@@ -140,7 +151,8 @@ AsyncRequest.prototype.send = function () {
140
151
  if (this.status >= 200 && this.status < 400) {
141
152
  let response;
142
153
  try {
143
- response = eval("(" + this.responseText + ")");
154
+ const safeJson = self._unshieldResponseText(this.responseText);
155
+ response = eval("(" + safeJson + ")");
144
156
  } catch (e) {
145
157
  throw new Error("Failed to handle response: " + e.message + "\n" + this.responseText);
146
158
  }
@@ -83,15 +83,17 @@ export default class Dialog {
83
83
  }).show();
84
84
  }
85
85
 
86
- _fixBackdrop(content) {
86
+ _fixBackdrop() {
87
87
  const backdrops = document.querySelectorAll('.modal-backdrop');
88
+ let shown = false;
88
89
 
89
90
  backdrops.forEach((backdrop, index) => {
90
- if (index > 0 && index === backdrops.length - 1) {
91
+ if (shown || index > 0 && index === backdrops.length - 1) {
91
92
  backdrop.style.display = 'none';
92
93
  } else {
93
94
  backdrop.style.zIndex = zIndex - 1;
94
95
  backdrop.style.display = '';
96
+ shown = true;
95
97
  }
96
98
  });
97
99
  }