Skip to content
Open
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
9 changes: 7 additions & 2 deletions backend/controllers/userSheetProgressController.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ exports.saveProgress = async (req, res) => {
});
}

if (completedTopics !== undefined && !Array.isArray(completedTopics)) {
if (
completedTopics !== undefined &&
(typeof completedTopics !== "object" ||
completedTopics === null ||
Array.isArray(completedTopics))
) {
return res.status(400).json({
success: false,
error: "Invalid completedTopics field, must be an array",
error: "Invalid completedTopics field, must be an object",
Comment on lines +63 to +71

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Validate completedTopics values against the record contract.

This check accepts any non-null, non-array object. For example, { "0-0-0": "true" } passes validation, but backend/Input_validators/ValidateUserSheetProgress.js:5-10 requires string keys with boolean values. Validate that the value is a plain object and that every property value is boolean before persisting it.

Proposed fix
   if (
     completedTopics !== undefined &&
-    (typeof completedTopics !== "object" ||
-      completedTopics === null ||
-      Array.isArray(completedTopics))
+    (completedTopics === null ||
+      typeof completedTopics !== "object" ||
+      Array.isArray(completedTopics) ||
+      Object.values(completedTopics).some(
+        (value) => typeof value !== "boolean"
+      ))
   ) {
     return res.status(400).json({
       success: false,
-      error: "Invalid completedTopics field, must be an object",
+      error: "Invalid completedTopics field, must be an object with boolean values",
     });
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/controllers/userSheetProgressController.js` around lines 63 - 71,
Strengthen the completedTopics validation in the user sheet progress controller
to require a plain object and boolean values for every property, matching the
contract enforced by ValidateUserSheetProgress. Reject non-plain objects and any
entry whose value is not boolean before persisting the record, while preserving
the existing 400 response.

});
}

Expand Down
Loading