mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Update api_controller.js
This commit is contained in:
@ -426,23 +426,25 @@ async function deleteOrganization(req, res){
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const isOrganizationAdmin = await knex('OrganizationAdministrator')
|
// Delete organization if admin
|
||||||
|
const deletedRows = await knex('Organization')
|
||||||
|
.where({ id: organizationIdToDelete })
|
||||||
|
.whereExists(function(){
|
||||||
|
this.select('*')
|
||||||
|
.from('OrganizationAdministrator')
|
||||||
.where('id_person', req.jwt.person_id)
|
.where('id_person', req.jwt.person_id)
|
||||||
.where('id_organization', organizationIdToDelete)
|
.where('id_organization', organizationIdToDelete)
|
||||||
.select('*')
|
})
|
||||||
.first();
|
|
||||||
|
|
||||||
// Potential TOCTOU weakeness not to be worried about
|
|
||||||
if(!isOrganizationAdmin){
|
|
||||||
return res.status(403).json({error : "Forbidden"});
|
|
||||||
}
|
|
||||||
|
|
||||||
await knex('Organization')
|
|
||||||
.where({ id: organizationIdToDelete })
|
|
||||||
.del();
|
.del();
|
||||||
|
|
||||||
|
if(deletedRows == 0){
|
||||||
|
return res.status(403).json({error: "Forbidden"});
|
||||||
|
}
|
||||||
|
else{
|
||||||
return res.status(200).json({success: true});
|
return res.status(200).json({success: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return res.status(500).json({error : "Internal server error"});
|
return res.status(500).json({error : "Internal server error"});
|
||||||
@ -473,6 +475,7 @@ async function createOrganizationPost(req, res){
|
|||||||
.first();
|
.first();
|
||||||
|
|
||||||
// Non-exploitable TOC/TOU weakness
|
// Non-exploitable TOC/TOU weakness
|
||||||
|
// For more information https://softwareengineering.stackexchange.com/questions/451038/when-should-i-be-worried-of-time-of-check-time-of-use-vulnerabilities-during-dat
|
||||||
if(!isOrganizationAdmin){
|
if(!isOrganizationAdmin){
|
||||||
return res.status(403).json({error : "Forbidden"});
|
return res.status(403).json({error : "Forbidden"});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user