Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,15 @@ async def delete(self, db: Database):
"project_partnerships",
]

# Whitelist of allowed table names to prevent SQL injection via
# dynamic table name interpolation, since table names cannot be parameterized.
allowed_tables = set(related_tables)

# Start a transaction to ensure atomic deletion
async with db.transaction():
# Loop through each table and execute the delete query
for table in related_tables:
if table not in allowed_tables:
raise ValueError(f"Invalid table name: {table}")
await db.execute(
f"DELETE FROM {table} WHERE project_id = :project_id",
{"project_id": self.id},
Expand Down
Loading