Skip to content

Commit f6cf3b4

Browse files
committed
Class validation works with a post
1 parent 47c98a7 commit f6cf3b4

File tree

6 files changed

+65
-28
lines changed

6 files changed

+65
-28
lines changed

.vs/VSWorkspaceState.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"\\models",
1212
"\\routes"
1313
],
14-
"SelectedNode": "\\routes\\class-validator.routes.js",
14+
"SelectedNode": "\\routes\\index.routes.js",
1515
"PreviewInSolutionExplorer": false
1616
}
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.
+50-27
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,68 @@
11
var mysql = require('mysql2');
22
var classValidator = require('class-validator');
3+
//var mysql = require('mysql2/promise')
34

4-
let requirements = {
5-
host: 'localhost',
6-
user: 'root',
7-
password: 'compsec2',
8-
database: 'sqldatabase'
9-
};
10-
var connection = mysql.createConnection(requirements);
11-
12-
function bypassedValidation(emailInput, passwordInput) {
5+
function bypassedValidation(emailInput, passwordInput, connection) {
136
const sqlquery1 = `SELECT * FROM login WHERE email = ${emailInput} AND password = ${passwordInput}`;
14-
connection.query(sqlquery1, function (error, rows) {
15-
if (error) throw error;
16-
console.log(rows);
7+
return new Promise(function (resolve, reject) {
8+
connection.query(sqlquery1, function (error, rows) {
9+
if (error) {
10+
reject(new Error(error))
11+
}
12+
else {
13+
resolve(rows);
14+
}
15+
16+
});
1717
});
18-
19-
return ;
18+
2019
}
21-
class attackSchema {
20+
class intendedSchema {
2221
email;
2322
password
2423
}
24+
2525
let param = {
2626
email: ' " OR 1=1--',
2727
password: ' " OR 1=1--',
2828
constructor: false
2929
};
3030

31-
let test1Param = Object.assign(attackSchema, param);
32-
console.log("This is the merged schema:")
33-
console.log(test1Param);
3431

3532

36-
classValidator.validate(test1Param).then(errors => {
37-
if (errors.length > 0) {
38-
console.log('invalid email and or password, unable to validate user', errors);
39-
} else {
40-
console.log('valid email and password, user successfully validated. Relevant Database Information:');
41-
bypassedValidation(test1Param.email, test1Param.password);
42-
}
43-
});
33+
function jsonHandle(emailInput)
34+
{
35+
console.log("into the json");
36+
let requirements = {
37+
host: 'localhost',
38+
user: 'root',
39+
password: 'compsec2',
40+
database: 'sqldatabase'
41+
};
42+
var connection = mysql.createConnection(requirements);
43+
44+
let test1Param = Object.assign(intendedSchema, param);
45+
console.log("This is the merged schema:")
46+
console.log(test1Param);
47+
48+
49+
return new Promise(function (resolve, reject) {
50+
classValidator.validate(test1Param).then((errors) => {
51+
if (errors.length > 0) {
52+
console.log('invalid email and or password, unable to validate user', errors);
53+
resolve("Class validator failed to validate user ");
54+
} else {
55+
console.log('valid email and password, user successfully validated. Relevant Database Information:');
56+
bypassedValidation(test1Param.email, test1Param.password, connection).then((results) => {
57+
resolve(results);
58+
})
59+
60+
}
61+
});
62+
});
63+
64+
}
4465

45-
return;
66+
module.exports = {
67+
jsonHandle
68+
}

routes/class-validator.routes.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const express = require('express')
2+
const router = express.Router()
3+
const class_validator = require('../class-validator/class-validator_handling')
4+
5+
module.exports = router
6+
7+
router.post('/', async (req, res) => {
8+
let prom = class_validator.jsonHandle(req.body);
9+
let resolved = Promise.resolve(prom)
10+
resolved.then(function (values) {
11+
res.json(values);
12+
})
13+
})

routes/index.routes.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ router.use('/component_type', require('./component_type_routes'))
77
router.use('/jpv', require('./jpv.routes'))
88
router.use('/bson', require('./bson.routes'))
99
router.use('/kindof', require('./kindof.routes'))
10+
router.use('/class-validator', require('./class-validator.routes'))
1011

0 commit comments

Comments
 (0)