Skip to content

Commit

Permalink
feat(security): improve app security
Browse files Browse the repository at this point in the history
  • Loading branch information
Daves2126 committed Oct 16, 2023
1 parent 559328e commit 3019765
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/database/repositories/serverProperties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const ServerProperties = require('../../schemas/serverProperties');
const ServerPropertiesCategory = require('../../schemas/serverPropertiesCategory');

async function findCategoryByKey(key) {
return ServerPropertiesCategory.findOne({ key });
return await ServerPropertiesCategory.findOne({ key });

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
}

async function findPropertyByKeyAndCategory(key, category) {
return ServerProperties.findOne({ key, category });
return await ServerProperties.findOne({ key, category });
}

async function findPropertyByKey(key) {
return ServerProperties.findOne({ key });
return await ServerProperties.findOne({ key });

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
}


Expand Down Expand Up @@ -157,5 +157,6 @@ module.exports = {
findCategoryByKey,
findPropertyByKeyAndCategory,
createProperty,
getCategoryById
getCategoryById,
findPropertyByKey
};
5 changes: 2 additions & 3 deletions src/middlewares/checkUniqueKeyServerPropertiesCategory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const ServerPropertiesCategory = require('../database/schemas/serverPropertiesCategory');

const repository = require("../database/repositories/serverProperties/index")
const checkUniqueKeyServerPropertiesCategory = async (req, res, next) => {
try {
const existingCategory = await ServerPropertiesCategory.findOne({ key: req.body.key });
const existingCategory = await repository.findCategoryByKey(req.body.key);
if (existingCategory) {
return res.status(400).json({ error: 'Category with this key already exists' });
}
Expand Down

0 comments on commit 3019765

Please sign in to comment.