Skip to content

Commit 8c98743

Browse files
committed
switched to es6 modules
1 parent 0ad4b05 commit 8c98743

24 files changed

+21867
-18297
lines changed
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

bson-objectid/attack.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const ObjectID = require("bson-objectid");
1+
import ObjectID from "bson-objectid";
2+
import pkg from 'bson-objectid';
3+
const { isValid } = pkg;
4+
5+
26

37
// Receives a JSON object and returns the bson-object ID
48
function jsonDemo(input) {
@@ -11,7 +15,7 @@ function jsonDemo(input) {
1115
// Internal testing
1216
function workingDemo() {
1317
console.log(ObjectID("54495ad94c934721ede76d90"));
14-
console.log(ObjectID.isValid(ObjectID("54495ad94c934721ede76d90")));
18+
console.log(isValid(ObjectID("54495ad94c934721ede76d90")));
1519

1620
// Attack Example
1721
const payload = {
@@ -27,17 +31,17 @@ object_id_payload.hello = "goodbye" // Forged objectID object is mutable.
2731
console.log(object_id_payload.hello)
2832
object_id_payload.new = "hi"
2933
console.log(object_id_payload)
30-
console.log(ObjectID.isValid(object_id_payload)); // Forged ObjectID fails ObjectID.isValid check (potential mitigation)
34+
console.log(isValid(object_id_payload)); // Forged ObjectID fails ObjectID.isValid check (potential mitigation)
3135

3236
console.log(ObjectID(payload).id)
3337
console.log(ObjectID(payload));
34-
console.log(ObjectID.isValid(ObjectID(payload)));
38+
console.log(isValid(ObjectID(payload)));
3539

3640

3741
}
3842

3943

40-
module.exports =
44+
export default
4145
{
4246
jsonDemo
4347
}

class-validator/class-validator_handling.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var mysql = require('mysql2');
2-
var classValidator = require('class-validator');
1+
import { createConnection } from 'mysql2';
2+
import { validate } from 'class-validator';
3+
import { UserValidationSchema } from "./schema.js";
34

45
//var mysql = require('mysql2/promise')
56

@@ -34,15 +35,18 @@ function jsonHandle(emailInput)
3435
password: 'compsec2',
3536
database: 'sqldatabase'
3637
};
37-
var connection = mysql.createConnection(requirements);
38+
var connection = createConnection(requirements);
3839

39-
let test1Param = Object.assign(intendedSchema, emailInput);
40+
let test1Param = Object.assign(UserValidationSchema, emailInput);
4041
console.log("This is the merged schema:")
4142
console.log(test1Param);
4243

4344

45+
46+
47+
4448
return new Promise(function (resolve, reject) {
45-
classValidator.validate(test1Param).then((errors) => {
49+
validate("myUserSchema", test1Param).then((errors) => {
4650
if (errors.length > 0) {
4751
console.log('invalid email and or password, unable to validate user', errors);
4852
resolve("Class validator failed to validate user ");
@@ -55,13 +59,12 @@ function jsonHandle(emailInput)
5559
}
5660
resolve(results);
5761
})
58-
5962
}
6063
});
6164
});
6265

6366
}
6467

65-
module.exports = {
68+
export default {
6669
jsonHandle
6770
}

class-validator/schema.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
validate,
3+
validateOrReject,
4+
Contains,
5+
IsInt,
6+
Length,
7+
IsEmail,
8+
IsFQDN,
9+
IsDate,
10+
Min,
11+
Max,
12+
IsString,
13+
} from 'class-validator';
14+
15+
export let UserValidationSchema = {
16+
name: 'myUserSchema',
17+
properties: {
18+
email: [
19+
{
20+
type: 'isEmail',
21+
constraints: []
22+
}
23+
],
24+
password: [
25+
{
26+
type: 'minLength',
27+
constraints: [1]
28+
},
29+
{
30+
type: 'maxLength',
31+
constraints: [15]
32+
},
33+
],
34+
},
35+
};

clone-deep/attack.js

-11
This file was deleted.

component_type/component_type_handling.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const express = require('express')
2-
var type = require('component-type')
3-
var supplyAttack = require('./supply_chain-attack')
1+
import express from 'express'
2+
import type from 'component-type'
3+
import { sneakyTimestamp } from './supply_chain-attack.js'
44

55
// check type of passed JSON, returns the type component type believes it is
66
function runComponent(payload)
@@ -15,7 +15,7 @@ function runComponent(payload)
1515
function demoSupplyChain(input)
1616
{
1717
// Calling my module to attach a timestamp to this input object! Then I will type check it
18-
let obj = supplyAttack.sneakyTimestamp(input);
18+
let obj = sneakyTimestamp(input);
1919
return ("Component type thinks this is: " + type(obj));
2020

2121
}
@@ -37,7 +37,7 @@ function demoValOfFix(obj)
3737

3838
}
3939

40-
module.exports = {
40+
export default {
4141
runComponent,
4242
demoValOfFix,
4343
demoSupplyChain

component_type/component_type_internal_attacks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var type = require('component-type')
1+
import type from 'component-type';
22

33
demo1()
44

component_type/supply_chain-attack.js

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

2-
3-
function sneakyTimestamp(input) {
2+
export function sneakyTimestamp(input) {
43
input.timestamp = new Date();
54

65
if (input.username == "Execute Order 66") {
@@ -9,8 +8,3 @@ function sneakyTimestamp(input) {
98
}
109
return input;
1110
}
12-
13-
module.exports =
14-
{
15-
sneakyTimestamp,
16-
}

data/payloads.json

-1
This file was deleted.

index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const express = require('express')
2-
const morgan = require('morgan')
1+
import express, { json, urlencoded } from 'express'
2+
import morgan from 'morgan'
3+
import router from './routes/index.routes.js'
34

45
const app = express()
56
app.use(morgan('tiny'))
67

7-
app.use(express.json())
8-
app.use(express.urlencoded({ extended: true }))
9-
app.use(require('./routes/index.routes'))
8+
app.use(json())
9+
app.use(urlencoded({ extended: true }))
10+
app.use(router)
1011

12+
//app.use(require('./routes/index.routes'))
1113

1214
// app.get('/', (req, res) => {
1315
// res.json({ message: 'Hello world' })

jpv/2.2.1_JPV_internal_attack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const jpv = require('jpv')
1+
import { validate } from 'jpv';
22
exampleJPV()
33

44
// Demo for the constructor bypass on version 2.2.1
@@ -23,7 +23,7 @@ function exampleJPV() {
2323
};
2424

2525
// jpv.validate(input, schema) should return false, but, as of 2.2.1, returns true
26-
console.log("jpv.validate(input, schema) = " + jpv.validate(input, schema));
26+
console.log("jpv.validate(input, schema) = " + validate(input, schema));
2727
console.log(input.constructor === schema.constructor);
2828

2929
// To fix this, we could check that the constructor is not inherited

jpv/jpv_handling.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const express = require('express')
2-
const jpv = require('jpv')
1+
import pkg from 'jpv';
2+
const { validate } = pkg;
33

44

55
// Bypass check on 2.0.1 for map validation
@@ -10,7 +10,7 @@ function checkJPVMapOrig(input)
1010
should_be_map: new Map()
1111
}
1212

13-
return ("Validation bypassed: " + jpv.validate(input, mapPattern));
13+
return ("Validation bypassed: " + validate(input, mapPattern));
1414
}
1515

1616
// Bypass check on 2.0.1 for array validation
@@ -20,7 +20,7 @@ function checkJPVArrayOrig(input)
2020
should_be_array: []
2121
};
2222

23-
return ("Validation bypassed: " + jpv.validate(input, arrayPattern));
23+
return ("Validation bypassed: " + validate(input, arrayPattern));
2424
}
2525

2626

@@ -42,7 +42,7 @@ function traverse(o,func) {
4242
}
4343
}
4444

45-
module.exports = {
45+
export default {
4646
checkJPVMapOrig,
4747
checkJPVArrayOrig,
4848
}

kind_of/attack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const kindOf = require('kind-of');
1+
import kindOf from 'kind-of';
22

33
// Receives JSON input and returns what kindof believes it is
44
function jsonDemo(input) {
@@ -21,7 +21,7 @@ function demo1() {
2121
}
2222

2323

24-
module.exports =
24+
export default
2525
{
2626
jsonDemo
2727
}

models/payload.model.js

-65
This file was deleted.

0 commit comments

Comments
 (0)