Skip to content

Commit 0ad4b05

Browse files
committed
extra code comments
1 parent 3f5170f commit 0ad4b05

File tree

6 files changed

+47
-37
lines changed

6 files changed

+47
-37
lines changed

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

bson-objectid/attack.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
const ObjectID = require("bson-objectid");
22

3-
// Working Example
3+
// Receives a JSON object and returns the bson-object ID
4+
function jsonDemo(input) {
5+
console.log(input);
6+
console.log(ObjectID(input));
7+
console.log(ObjectID(input).id);
8+
return ("bson-object ID says the id should be " + ObjectID(input).id);
9+
}
10+
11+
// Internal testing
412
function workingDemo() {
513
console.log(ObjectID("54495ad94c934721ede76d90"));
614
console.log(ObjectID.isValid(ObjectID("54495ad94c934721ede76d90")));
@@ -28,12 +36,6 @@ console.log(ObjectID.isValid(ObjectID(payload)));
2836

2937
}
3038

31-
function jsonDemo(input) {
32-
console.log(input);
33-
console.log(ObjectID(input));
34-
console.log(ObjectID(input).id);
35-
return ("bson-object ID says the id should be " + ObjectID(input).id);
36-
}
3739

3840
module.exports =
3941
{

component_type/component_type_handling.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const express = require('express')
22
var type = require('component-type')
33
var supplyAttack = require('./supply_chain-attack')
44

5-
// check type of passed JSON, confirm whether the type check can be tricked
5+
// check type of passed JSON, returns the type component type believes it is
66
function runComponent(payload)
77
{
88
return new Promise((resolve, reject) => {
@@ -11,14 +11,16 @@ function runComponent(payload)
1111

1212
}
1313

14+
// Call into another function to demo what a supply attack might look like
1415
function demoSupplyChain(input)
1516
{
1617
// Calling my module to attach a timestamp to this input object! Then I will type check it
17-
let obj = supplyAttack.supplyAttack(input);
18+
let obj = supplyAttack.sneakyTimestamp(input);
1819
return ("Component type thinks this is: " + type(obj));
1920

2021
}
2122

23+
// Used to demonstrate what our fix to the component-type external value-of attack is
2224
function demoValOfFix(obj)
2325
{
2426
if (typeof obj.valueOf === 'function')
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
var type = require('component-type')
22

3-
class testPollution {
4-
constructor() {
5-
Object.defineProperties(this, {
6-
[Symbol.toStringTag]: {
7-
value: "Array",
8-
writable: true
9-
}
10-
});
11-
this.valueOf = function valueOf() { return true; };
12-
}
13-
}
14-
15-
16-
class vals {
17-
constructor() { }
18-
19-
}
20-
21-
223
demo1()
234

24-
function demo1()
25-
{
26-
// validated how component-type works
5+
// Do a long demo of how component-type can be tricked by internal attackers
6+
function demo1() {
7+
// validated how component-type works
278
var check = new testPollution();
289
var dateObj = new Date;
2910
console.log("This is the component type result on a date object")
@@ -33,7 +14,7 @@ function demo1()
3314
console.log(" obj[Symbol.toStringTag] = 'Array';");
3415
dateObj[Symbol.toStringTag] = 'Array';
3516
console.log("component type will now return array for the date object!");
36-
console.log(" "+ type(dateObj));
17+
console.log(" " + type(dateObj));
3718

3819
console.log("\n\n");
3920
console.log("This is a custom made polluted object, we overode its toStringTag in the constructor");
@@ -53,4 +34,26 @@ function demo1()
5334
console.log("\n\n");
5435
}
5536

37+
// Example of how a constructor for an object can set its toStringTag to a different value
38+
class testPollution {
39+
constructor() {
40+
Object.defineProperties(this, {
41+
[Symbol.toStringTag]: {
42+
value: "Array",
43+
writable: true
44+
}
45+
});
46+
this.valueOf = function valueOf() { return true; };
47+
}
48+
}
49+
50+
// empty class used to show the value of attack by an internal or supply chain adversary
51+
class vals {
52+
constructor() { }
53+
54+
}
55+
56+
57+
58+
5659

component_type/supply_chain-attack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
function supplyAttack(input) {
3+
function sneakyTimestamp(input) {
44
input.timestamp = new Date();
55

66
if (input.username == "Execute Order 66") {
@@ -12,5 +12,5 @@ function supplyAttack(input) {
1212

1313
module.exports =
1414
{
15-
supplyAttack,
15+
sneakyTimestamp,
1616
}

kind_of/attack.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const kindOf = require('kind-of');
22

3+
// Receives JSON input and returns what kindof believes it is
4+
function jsonDemo(input) {
5+
return "Should return object, but instead returns " + kindOf(input)
6+
}
37

48

9+
// used for internal testing
510
const objectPretendingToBeSet = {
611
"id": "54495ad94c934721ede76d90",
712
"username": "bob",
@@ -10,13 +15,11 @@ const objectPretendingToBeSet = {
1015
"constructor":{"name":"Set"}
1116
}
1217

18+
// used in internal testing
1319
function demo1() {
1420
console.log(kindOf(objectPretendingToBeSet));
1521
}
1622

17-
function jsonDemo(input) {
18-
return "Should return object, but instead returns " + kindOf(input)
19-
}
2023

2124
module.exports =
2225
{

0 commit comments

Comments
 (0)