-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save entity process transactional #7627
base: production
Are you sure you want to change the base?
Conversation
…ess_transactional
@@ -33,81 +34,142 @@ | |||
} | |||
|
|||
findById(id: any, select?: any) { | |||
return this.dbForCurrentTenant().findById(id, select, { lean: true }); | |||
const session = dbSessionContext.getSession(); | |||
return this.dbForCurrentTenant().findById(id, select, { |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
This query object depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 4 days ago
To fix the problem, we need to ensure that the id
parameter is sanitized before being used in the MongoDB query. This can be achieved by using the $eq
operator to ensure that the user input is interpreted as a literal value and not as a query object. This change should be made in the findById
method of the MongooseModelWrapper
class in the app/api/odm/MultiTenantMongooseModel.ts
file.
-
Copy modified line R38
@@ -37,3 +37,3 @@ | ||
const session = dbSessionContext.getSession(); | ||
return this.dbForCurrentTenant().findById(id, select, { | ||
return this.dbForCurrentTenant().findById({ _id: { $eq: id } }, select, { | ||
lean: true, |
return this.dbForCurrentTenant().deleteMany(query); | ||
async deleteMany(query: UwaziFilterQuery<DataType<T>>, options: any = {}) { | ||
const session = dbSessionContext.getSession(); | ||
return this.dbForCurrentTenant().deleteMany(query, { |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
This query object depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 4 days ago
To fix the problem, we need to ensure that the user-provided data is interpreted as a literal value and not as a query object. This can be achieved by using the $eq
operator in the MongoDB query. This approach ensures that the user input is treated as a literal value, preventing any potential NoSQL injection attacks.
We will modify the deleteMany
method in the MongooseModelWrapper
class to use the $eq
operator for the _id
field. This change will ensure that the _id
is treated as a literal value in the query.
-
Copy modified lines R126-R127
@@ -125,3 +125,4 @@ | ||
const session = dbSessionContext.getSession(); | ||
return this.dbForCurrentTenant().deleteMany(query, { | ||
const sanitizedQuery = { _id: { $eq: query._id } }; | ||
return this.dbForCurrentTenant().deleteMany(sanitizedQuery, { | ||
...options, |
ca4fae2
to
f91c11d
Compare
f91c11d
to
a6f4bd8
Compare
…ess_transactional
e96c82c
to
76bf90c
Compare
fixes #7519