Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@andypols
Copy link
Contributor

@andypols andypols commented Jul 4, 2025

Summary

A recent penetration test identified that the /api/v1/user endpoint exposes sensitive internal user data, including:

  • Password hashes
  • Okta authentication IDs
  • Internal database identifiers (_id)
  • Other fields not intended for the UI

Root Cause

The API response was serializing raw user objects directly from the database, without filtering or transforming the fields. A previous fix attempt (#741) tried to exclude the password field using:

collection.find(query, { password: 0 }).toArray();

However, this projection syntax is no longer valid in MongoDB Node.js Driver v5, where the second argument to find() must be an explicit FindOptions object. As a result, the fix was ineffective, and sensitive fields continued to be returned.

Fix

This PR addresses the issue on two levels:

  1. Corrects the MongoDB projection syntax so that password fields are properly excluded:
collection.find(query).project({ password: 0 }).toArray();
  1. Introduces a public-facing serialisation object to explicitly control which user fields are returned to the UI. Instead of returning raw database user objects, each user is now mapped to a PublicUser shape that includes only the fields required by the frontend. All internal and sensitive fields are explicitly excluded by design.

@netlify
Copy link

netlify bot commented Jul 4, 2025

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 0b44c50
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/686e66c258bb69000843762b

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 4, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: andypols / name: Andy Pols (c985308)
  • ✅ login: jescalada / name: Juan Escalada (0b44c50)

@github-actions github-actions bot added the fix label Jul 4, 2025
Copy link
Contributor

@jescalada jescalada left a comment

Choose a reason for hiding this comment

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

Did some manual testing, LGTM so far! 👍🏼

While testing, I found some more "leaky" spots for user info:

src/service/routes/auth.js

  • Leak in the router.post('/login') call:
    image

  • Leak in router.post('profile') call:
    image

  • Leak in router.get('/me') call:
    image

@codecov
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.37%. Comparing base (d48c882) to head (0b44c50).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1090      +/-   ##
==========================================
+ Coverage   76.91%   77.37%   +0.46%     
==========================================
  Files          55       55              
  Lines        2270     2272       +2     
  Branches      255      255              
==========================================
+ Hits         1746     1758      +12     
+ Misses        494      484      -10     
  Partials       30       30              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jescalada
Copy link
Contributor

This should be good to merge. Feel free to add the remaining fixes/tests in a new PR!

@jescalada jescalada merged commit afedd47 into finos:main Jul 9, 2025
14 checks passed
@andypols andypols deleted the fix-users-api-password-leak branch July 14, 2025 11:02
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.

2 participants