Skip to content

fix(lms): Stop echoing the user object with troop token in responses - #1248

Open
jeromehardaway wants to merge 1 commit into
masterfrom
fix/lms-user-echo
Open

fix(lms): Stop echoing the user object with troop token in responses#1248
jeromehardaway wants to merge 1 commit into
masterfrom
fix/lms-user-echo

Conversation

@jeromehardaway

Copy link
Copy Markdown
Contributor

Problem

Three LMS endpoints — including the production GET /api/lms/courses — returned req.user in the response body. That object includes troopToken, the caller's J0dI3 access credential, so every course listing shipped a bearer credential to the browser.

Fix

  • GET /api/lms/courses: response echo removed entirely — the endpoint returns courses, not identity.
  • GET /api/lms/test and GET /api/lms/admin-only (diagnostics whose point is proving auth/RBAC): return a sanitized { id, email, role } / { id, role } subset — never the token.

Verification

  • New regression tests (__tests__/pages/api/lms/no-user-echo.test.ts, 3 passing) drive each handler with an authenticated user carrying a sentinel token and assert the serialized response contains neither the token value nor a troopToken key.
  • npm run typecheck — pass.

Closes #1196

Three LMS endpoints (courses, test, admin-only) returned req.user in the response body,

exposing the caller's troopToken (their J0dI3 access credential) to the browser.

The courses endpoint drops the echo entirely; the two diagnostics return a sanitized

id/email/role subset. Regression tests assert no troopToken in any LMS response body.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vets-who-code-app Ready Ready Preview, Comment Jul 18, 2026 7:52pm

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a security issue where several LMS API endpoints were including req.user in response bodies, unintentionally leaking the caller’s troopToken to the browser.

Changes:

  • Removed req.user entirely from GET /api/lms/courses responses.
  • Updated GET /api/lms/test and GET /api/lms/admin-only to return only a sanitized subset of identity fields (no token).
  • Added regression tests ensuring LMS responses do not include troopToken (key) or the token value.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/pages/api/lms/test.ts Replaces full req.user echo with a sanitized identity subset in the response payload.
src/pages/api/lms/courses/index.ts Removes user from the response body to prevent token leakage.
src/pages/api/lms/admin-only.ts Returns only a minimal, sanitized identity subset instead of echoing req.user.
tests/pages/api/lms/no-user-echo.test.ts Adds regression coverage to prevent reintroducing token/user echoing across LMS endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to 74
// Do not echo req.user — it carries the caller's troop access token.
res.status(200).json({
user: req.user,
courses: coursesWithStats,
message: "Courses retrieved successfully",
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the user field is being removed from the /api/lms/courses response to prevent exposing the troop token, should the documented response at the top of index.ts also be updated to remove user: { id, email, role } so it matches the new response shape?

@jeromehardaway
jeromehardaway requested a review from msgem0523 July 29, 2026 23:58

@msgem0523 msgem0523 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the user field is being removed from the /api/lms/courses response to prevent exposing the troop token, should the documented response at the top of index.ts also be updated to remove user: { id, email, role } so it matches the new response shape?

@jeromehardaway

Copy link
Copy Markdown
Contributor Author

Since the user field is being removed from the /api/lms/courses response to prevent exposing the troop token, should the documented response at the top of index.ts also be updated to remove user: { id, email, role } so it matches the new response shape?

This one will have to be nuked since we are moving LMS completely to Jodie in a separate repo.

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.

accounts: Stop echoing user object with troop token from LMS endpoints

3 participants