Skip to content

Potential fix for code scanning alert no. 5: Database query built from user-controlled sources#4

Merged
yynss21 merged 1 commit intomainfrom
alert-autofix-5
Dec 12, 2025
Merged

Potential fix for code scanning alert no. 5: Database query built from user-controlled sources#4
yynss21 merged 1 commit intomainfrom
alert-autofix-5

Conversation

@yynss21
Copy link
Owner

@yynss21 yynss21 commented Dec 12, 2025

Potential fix for https://github.com/byRespect/tracker-hub/security/code-scanning/5

To fix this problem, only allow fields that are explicitly permitted for update to be passed to findByIdAndUpdate. This is typically achieved by creating a whitelist of allowed update fields and then constructing a new object that contains only those fields from updateSessionDto. This process is called "whitelisting" or "picking" fields.

  • How to fix:
    Create a helper function (e.g., pick) that takes the incoming object and a list of allowed fields, and returns a new object with only those fields present.
    Use this function on the updateSessionDto before passing it to Mongoose's findByIdAndUpdate.

  • Where to change:
    In packages/backend/src/sessions/sessions.service.ts, inside the update method, immediately before the database call, use the helper to pick only allowed fields.

  • What is needed:

    • Add a pick function using plain TypeScript/JavaScript.
    • Define an array of allowed field names to be updated.
    • Apply this filter before the call to findByIdAndUpdate.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…m user-controlled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@yynss21 yynss21 marked this pull request as ready for review December 12, 2025 22:29
@yynss21 yynss21 merged commit 32f5aaa into main Dec 12, 2025
6 checks passed
@yynss21 yynss21 deleted the alert-autofix-5 branch December 12, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant