Skip to content

Perf & security: DB indexes, partial updates, route dedup, XSS fix#8

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/identify-and-suggest-code-improvements
Draft

Perf & security: DB indexes, partial updates, route dedup, XSS fix#8
Copilot wants to merge 3 commits intomasterfrom
copilot/identify-and-suggest-code-improvements

Conversation

Copy link

Copilot AI commented Mar 18, 2026

Several inefficiencies and one XSS vulnerability across the data layer, server routes, and client-side rendering.

Database (database.js)

  • Missing indexes — added CREATE INDEX IF NOT EXISTS on completed, priority, and created_at DESC; previously every query did a full table scan
  • Partial updates clobbered existing dataupdateTask always sent all 4 columns, setting unprovided fields to NULL; now builds the SET clause dynamically from only the defined arguments
// Before: always overwrites every column
UPDATE tasks SET title = ?, description = ?, priority = ?, completed = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?

// After: only touches what was passed
if (title !== undefined)     { fields.push('title = ?');     values.push(title); }
if (description !== undefined) { ... }
// ...
const sql = `UPDATE tasks SET ${fields.join(', ')} WHERE id = ?`;

Server routes (index.js)

  • GET / and GET /tasks were identical 10-line blocks; extracted into a single renderTasks handler

Client (public/script.js)

  • Unnecessary API call on delete — deleting the last task fired a full GET /api/tasks reload; now renders the empty state directly
  • XSStitle, description, priority, and id were interpolated raw into innerHTML; added escapeHtml() applied to all user-supplied values
  • CSS class injectiontask.priority was used as a class name without validation; whitelisted to low/medium/high with medium as fallback

Tests (tests/database.test.js)

New test file using an in-memory SQLite DB covering partial-update correctness and the no-fields error path of updateTask.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 18, 2026 06:56
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
…S/injection fixes

Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and improve slow or inefficient code Perf & security: DB indexes, partial updates, route dedup, XSS fix Mar 18, 2026
Copilot AI requested a review from kavyashri-as March 18, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants