Skip to content

Commit

Permalink
Fix code scanning alert no. 41: Database query built from user-contro…
Browse files Browse the repository at this point in the history
…lled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
Jonhvmp and github-advanced-security[bot] authored Dec 16, 2024
1 parent 6e228e2 commit e36e566
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backend/src/repositories/snippetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export const findSnippetById = (id: string) => {
};

export const updateSnippetById = (id: string, updateData: any) => {
return Snippet.findByIdAndUpdate(id, { $set: updateData }, { new: true, runValidators: true });
// Validate updateData to ensure it only contains allowed fields
const allowedFields = ['title', 'description', 'language', 'tags', 'code', 'favorite'];
const sanitizedData: any = {};
for (const key in updateData) {
if (allowedFields.includes(key)) {
sanitizedData[key] = updateData[key];
}
}
return Snippet.findByIdAndUpdate(id, { $set: sanitizedData }, { new: true, runValidators: true });
};

export const deleteSnippetById = (id: string) => {
Expand Down

0 comments on commit e36e566

Please sign in to comment.