feat: another security sweep
Node.js CI / CI (push) Failing after 10s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m50s

This commit is contained in:
2026-02-04 22:02:24 -08:00
parent 5eae636f2f
commit 9caf74945a
10 changed files with 416 additions and 36 deletions
+34 -1
View File
@@ -7,6 +7,7 @@ import type {
SuggestionEntity,
CreateSuggestionDto,
DeclineSuggestionDto,
AcceptWithEditsDto,
} from "@library/shared-types";
import { adminGuard } from "../../middleware/admin-guard";
import { bannedGuard } from "../../middleware/banned-guard";
@@ -132,7 +133,7 @@ export default async function (app: FastifyInstance): Promise<void> {
);
// Accept a suggestion with edits (admin only)
app.put<{ Params: { id: string }; Body: any }>(
app.put<{ Params: { id: string }; Body: AcceptWithEditsDto }>(
"/:id/accept-with-edits",
{
preHandler: [app.authenticate, adminGuard, app.csrfProtection],
@@ -192,4 +193,36 @@ export default async function (app: FastifyInstance): Promise<void> {
}
}
);
// Delete a suggestion (owner or admin only, only if unreviewed)
app.delete<{ Params: { id: string } }>(
"/:id",
{
preHandler: [app.authenticate, app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
const userId = request.user.id;
const isAdmin = request.user.isAdmin;
try {
const suggestion = await SuggestionService.deleteSuggestion(id, userId, isAdmin);
await AuditService.logFromRequest(request, {
action: AuditAction.ENTRY_DELETE,
category: isAdmin ? AuditCategory.ADMIN : AuditCategory.CONTENT,
resourceType: "Suggestion",
resourceId: suggestion.id,
details: `Deleted ${suggestion.entityType} suggestion: ${suggestion.title}`,
success: true,
});
reply.send({ success: true });
} catch (error) {
return reply.badRequest(
error instanceof Error ? error.message : "Failed to delete suggestion"
);
}
}
);
}