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,22 +426,24 @@ async function deleteOrganization(req, res){ | |||||||
|  |  | ||||||
|   try { |   try { | ||||||
|  |  | ||||||
|     const isOrganizationAdmin = await knex('OrganizationAdministrator') |     // Delete organization if admin | ||||||
|       .where('id_person', req.jwt.person_id) |     const deletedRows = await knex('Organization') | ||||||
|       .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 }) |       .where({ id: organizationIdToDelete }) | ||||||
|  |       .whereExists(function(){ | ||||||
|  |         this.select('*') | ||||||
|  |           .from('OrganizationAdministrator') | ||||||
|  |           .where('id_person', req.jwt.person_id) | ||||||
|  |           .where('id_organization', organizationIdToDelete) | ||||||
|  |       }) | ||||||
|       .del(); |       .del(); | ||||||
|  |  | ||||||
|     return res.status(200).json({success: true}); |     if(deletedRows == 0){ | ||||||
|  |       return res.status(403).json({error: "Forbidden"}); | ||||||
|  |     } | ||||||
|  |     else{ | ||||||
|  |       return res.status(200).json({success: true}); | ||||||
|  |     } | ||||||
|  |        | ||||||
|   } |   } | ||||||
|   catch (error) { |   catch (error) { | ||||||
|     console.error(error); |     console.error(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