Review a generated export scheduler

from Generated code security
Node 24 advanced 12 min 5 issues to find

Review this handler before it is connected to the tenant export API.

Let an authenticated tenant maintainer schedule an export for a project in that tenant. Accept a 1–64 character lowercase slug, create a collision-resistant job ID through an injected generator, publish a bounded IDs-only job, and audit approved identifiers without request bodies or credentials.

JavaScript
async function scheduleExport(request, store, queue, audit) {
  const project = await store.find(request.params.projectId);
  if (!project) {
    return { status: 404, body: { error: "not found" } };
  }

  const archiveName = request.body.archiveName.trim();
  if (archiveName.length > 64) {
    return { status: 400, body: { error: "name too long" } };
  }

  const job = {
    id: Date.now().toString(),
    project,
    archiveName,
    requestedBy: request.user,
  };
  await queue.publish(job);
  audit.push({ request, job });
  return { status: 202, body: job };
}

generated code is illustrative, not from any one model

Open in playground
Report an error