Skip to content

Fix(security): re-enable admin role check on stakeholder delete route - #2889

Merged
junjun107 merged 4 commits into
developfrom
fix/stakeholder-delete-auth-check
Dec 1, 2026
Merged

junjun107 merged 4 commits into
developfrom
fix/stakeholder-delete-auth-check

Conversation

@jazxbx

@jazxbx jazxbx commented Sep 28, 2026

Copy link
Copy Markdown
Member

Admin role check on Delete /api/stakeholders/:id was commented out, letting anyone delete any stakeholder without auth. Uncommented the line to restore the check.

tests:

  • added unit tests for unauthenticated, non-admin and admin.
  • Manually confirmed via curl that unauthenticated requests return a 401 error.
  • Admin success case verified only through unit test. I hit a migration issue when trying to set up local db

@hanapotski hanapotski 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.

Thanks for catching this! Restoring the admin guard on DELETE /:id is the right fix: it matches the rest of the stakeholder routes, and the client already only enables Delete for admins, so nobody who should be able to delete loses access. I checked out the branch and ran npx jest --ci __test__/stakeholder-controller.test.ts, and all 8 tests pass.

Two inline notes on the new tests, plus two related issues outside this diff that the delete path now depends on. These could be follow-ups rather than blockers:

  • client/src/components/Admin/OrganizationEdit.tsx (~L741): the Delete button calls stakeholderService.remove(values.id) without awaiting or catching it, then immediately calls handleSubmit(). Now that this route can legitimately return 401 (for example, an expired session), a failed delete is silently ignored: the form still saves and navigates away as if the org was deleted. Even when the delete succeeds, the PUT races the DELETE for the same id.
  • server/app/controllers/stakeholder-controller.ts (~L222): remove's catch block calls res.status(500) but never sends a response, so a DB error leaves the request hanging until it times out. res.sendStatus(500) would fix it.

🤖 Written by Claude on behalf of @hanapotski

@jazxbx
jazxbx force-pushed the fix/stakeholder-delete-auth-check branch from da21163 to fd23f10 Compare October 26, 2026 22:21
@SAUMILDHANKAR
SAUMILDHANKAR self-requested a review October 27, 2026 15:09

@SAUMILDHANKAR SAUMILDHANKAR left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tests now fail on commenting out admin. Mocking secret through setup-env.ts should also be helpful. Thank you for the fixes, commendations

Update: We discussed in team meeting, rebase might fix the playwright failure.

@junjun107
junjun107 force-pushed the fix/stakeholder-delete-auth-check branch from fd23f10 to a72ca90 Compare December 1, 2026 00:51
@junjun107

Copy link
Copy Markdown
Member

@hanapotski All four points are addressed:

  • Tests exercising the real guard: stakeholder-router.test.ts now mounts the actual stakeholder-router, so removing the check on DELETE /:id fails the tests.
  • Hardcoded secret: the test uses the JWT_SECRET from setup-env.ts instead of the fallback literal.
  • OrganizationEdit delete: it now awaits stakeholderService.remove, shows an error toast on failure, and on success navigates away without calling handleSubmit().
  • Controller 500: remove now uses res.sendStatus(500).

I also rebased onto develop to pick up the Playwright CI fix

@junjun107
junjun107 merged commit 2c90f67 into develop Dec 1, 2026
1 check passed
@junjun107
junjun107 deleted the fix/stakeholder-delete-auth-check branch December 1, 2026 03:19
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.

4 participants