Skip to content

Commit 376debb

Browse files
committed
new validation work
1 parent 8c98743 commit 376debb

12 files changed

+365
-57
lines changed

.vs/VSWorkspaceState.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
"",
44
"\\bson-objectid",
55
"\\class-validator",
6-
"\\clone-deep",
76
"\\component_type",
8-
"\\data",
97
"\\jpv",
108
"\\kind_of",
11-
"\\models",
129
"\\routes"
1310
],
14-
"SelectedNode": "\\component_type\\component_type_internal_attacks.js",
11+
"SelectedNode": "\\class-validator\\schema.js",
1512
"PreviewInSolutionExplorer": false
1613
}
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

class-validator/class-validator_handling.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// import { UserValidationSchema } from "./schema.js";
2+
// registerSchema(UserValidationSchema);
3+
import { UserSchema } from "./schema.js";
4+
import { validate } from "class-validator";
15
import { createConnection } from 'mysql2';
2-
import { validate } from 'class-validator';
3-
import { UserValidationSchema } from "./schema.js";
46

5-
//var mysql = require('mysql2/promise')
6-
7-
function login(emailInput, passwordInput, connection) {
7+
function login(emailInput, passwordInput, connection)
8+
{
89
const sqlquery1 = `SELECT * FROM login WHERE email = ${emailInput} AND password = ${passwordInput}`;
910
console.log(sqlquery1);
1011
return new Promise(function (resolve, reject) {
@@ -21,14 +22,8 @@ function login(emailInput, passwordInput, connection) {
2122

2223
}
2324

24-
class intendedSchema {
25-
email;
26-
password;
27-
}
2825

29-
30-
function jsonHandle(emailInput)
31-
{
26+
function jsonHandle(emailInput) {
3227
let requirements = {
3328
host: 'localhost',
3429
user: 'root',
@@ -37,16 +32,12 @@ function jsonHandle(emailInput)
3732
};
3833
var connection = createConnection(requirements);
3934

40-
let test1Param = Object.assign(UserValidationSchema, emailInput);
35+
let test1Param = Object.assign(UserSchema, emailInput);
4136
console.log("This is the merged schema:")
4237
console.log(test1Param);
4338

44-
45-
46-
47-
4839
return new Promise(function (resolve, reject) {
49-
validate("myUserSchema", test1Param).then((errors) => {
40+
validate(test1Param).then((errors) => {
5041
if (errors.length > 0) {
5142
console.log('invalid email and or password, unable to validate user', errors);
5243
resolve("Class validator failed to validate user ");
@@ -67,4 +58,4 @@ function jsonHandle(emailInput)
6758

6859
export default {
6960
jsonHandle
70-
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// import { UserValidationSchema } from "./schema.js";
2+
// registerSchema(UserValidationSchema);
3+
import { UserSchema } from "./schema.js";
4+
import { validate } from "class-validator";
5+
import { createConnection } from 'mysql2';
6+
let requirements = {
7+
host: 'localhost',
8+
user: 'root',
9+
password: 'compsec2',
10+
database: 'sqldatabase'
11+
};
12+
const connection = createConnection(requirements);
13+
function bypassedValidation(emailInput, passwordInput) {
14+
const sqlquery1 = `SELECT * FROM login WHERE email = ${emailInput} AND password = ${passwordInput}`;
15+
connection.query(sqlquery1, function (error, rows) {
16+
if (error)
17+
throw error;
18+
console.log(rows);
19+
});
20+
}
21+
let schema = new UserSchema();
22+
schema.email = '';
23+
schema.password = '';
24+
let param = {
25+
email: '" OR 1=1--',
26+
password: '" OR 1=1--',
27+
constructor: false
28+
};
29+
let test1Param = Object.assign(schema, param);
30+
console.log(test1Param);
31+
validate(test1Param).then(errors => {
32+
if (errors.length > 0) {
33+
console.log('email and or password of wrong form', errors);
34+
}
35+
else {
36+
console.log('email and password of correct form input');
37+
bypassedValidation(test1Param.email, test1Param.password);
38+
}
39+
});
40+
// let schema2 = new UserSchema();
41+
// schema2.email = '';
42+
// schema2.password = '';
43+
// let ryn = {
44+
// email: '[email protected]',
45+
// pssword: 'Paass2',
46+
// incorrectField: 'I shouldnt be here',
47+
// constructor: false
48+
// };
49+
// let rynParam = Object.assign(schema2, ryn);
50+
// console.log(rynParam);
51+
// validate(rynParam).then(errors => {
52+
// if (errors.length > 0) {
53+
// console.log('email and or password of wrong form', errors);
54+
// } else {console.log('email and password of correct form input');
55+
// bypassedValidation(rynParam.email, rynParam.password);
56+
// }
57+
// });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { registerSchema } from "class-validator";
2+
// import { UserValidationSchema } from "./schema.js";
3+
// registerSchema(UserValidationSchema);
4+
import { UserSchema } from "./schema"
5+
import { validate } from "class-validator";
6+
import { createConnection } from 'mysql2';
7+
import { plainToClass, plainToInstance } from 'class-transformer'
8+
9+
10+
let requirements = {
11+
host: 'localhost',
12+
user: 'root',
13+
password: 'compsec2',
14+
database: 'sqldatabase'
15+
};
16+
17+
const connection = createConnection(requirements);
18+
function bypassedValidation(emailInput, passwordInput) {
19+
const sqlquery1 = `SELECT * FROM login WHERE email = ${emailInput} AND password = ${passwordInput}`;
20+
connection.query(sqlquery1, function(error, rows) {
21+
if (error) throw error;
22+
console.log(rows);
23+
});
24+
}
25+
26+
let schema = new UserSchema();
27+
schema.email = '';
28+
schema.password = '';
29+
30+
let param = {
31+
email: '" OR 1=1--',
32+
password: '" OR 1=1--',
33+
constructor: false
34+
};
35+
36+
let test1Param = Object.assign(schema, param);
37+
console.log(test1Param);
38+
39+
validate(test1Param).then(errors => {
40+
if (errors.length > 0) {
41+
console.log('email and or password of wrong form', errors);
42+
} else {console.log('email and password of correct form input');
43+
bypassedValidation(test1Param.email, test1Param.password);
44+
}
45+
});
46+
47+
48+
// let schema2 = new UserSchema();
49+
// schema2.email = '';
50+
// schema2.password = '';
51+
52+
// let ryn = {
53+
// email: '[email protected]',
54+
// pssword: 'Paass2',
55+
// incorrectField: 'I shouldnt be here',
56+
// constructor: false
57+
// };
58+
59+
// let rynParam = Object.assign(schema2, ryn);
60+
// console.log(rynParam);
61+
62+
63+
// validate(rynParam).then(errors => {
64+
// if (errors.length > 0) {
65+
// console.log('email and or password of wrong form', errors);
66+
// } else {console.log('email and password of correct form input');
67+
// bypassedValidation(rynParam.email, rynParam.password);
68+
// }
69+
// });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { createConnection } from 'mysql2';
2+
import { validate } from 'class-validator';
3+
import { UserValidationSchema } from "./schema.js";
4+
5+
//var mysql = require('mysql2/promise')
6+
7+
function login(emailInput, passwordInput, connection) {
8+
const sqlquery1 = `SELECT * FROM login WHERE email = ${emailInput} AND password = ${passwordInput}`;
9+
console.log(sqlquery1);
10+
return new Promise(function (resolve, reject) {
11+
connection.query(sqlquery1, function (error, rows) {
12+
if (error) {
13+
reject(new Error(error))
14+
}
15+
else {
16+
resolve(rows);
17+
}
18+
19+
});
20+
});
21+
22+
}
23+
24+
class intendedSchema {
25+
email;
26+
password;
27+
}
28+
29+
30+
function jsonHandle(emailInput)
31+
{
32+
let requirements = {
33+
host: 'localhost',
34+
user: 'root',
35+
password: 'compsec2',
36+
database: 'sqldatabase'
37+
};
38+
var connection = createConnection(requirements);
39+
40+
let test1Param = Object.assign(UserValidationSchema, emailInput);
41+
console.log("This is the merged schema:")
42+
console.log(test1Param);
43+
44+
45+
46+
47+
48+
return new Promise(function (resolve, reject) {
49+
validate("myUserSchema", test1Param).then((errors) => {
50+
if (errors.length > 0) {
51+
console.log('invalid email and or password, unable to validate user', errors);
52+
resolve("Class validator failed to validate user ");
53+
} else {
54+
console.log('valid email and password, user successfully validated. Relevant Database Information:');
55+
login(test1Param.email, test1Param.password, connection).then((results) => {
56+
57+
if (results.length == 0) {
58+
resolve("No user found");
59+
}
60+
resolve(results);
61+
})
62+
}
63+
});
64+
});
65+
66+
}
67+
68+
export default {
69+
jsonHandle
70+
}

class-validator/schema.js

+15-34
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
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-
},
1+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5+
return c > 3 && r && Object.defineProperty(target, key, r), r;
356
};
7+
import { IsEmail, MinLength, MaxLength } from 'class-validator';
8+
export class UserSchema {
9+
}
10+
__decorate([
11+
IsEmail()
12+
], UserSchema.prototype, "email", void 0);
13+
__decorate([
14+
MinLength(5),
15+
MaxLength(15)
16+
], UserSchema.prototype, "password", void 0);

class-validator/schema.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { validate, ValidationSchema, IsEmail, IsAlphanumeric, MinLength, MaxLength, IsEmpty, IsNotEmpty, Length } from 'class-validator';
2+
export class UserSchema {
3+
@IsEmail()
4+
email: string;
5+
6+
@MinLength(5)
7+
@MaxLength(15)
8+
password: string;
9+
10+
}

0 commit comments

Comments
 (0)