Security/tenant data isolation hardening - #102
Merged
jobbykings merged 2 commits intoJun 22, 2026
Merged
Conversation
jobbykings
approved these changes
Jun 22, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hardens tenant data isolation across the middleware, service, and query layers to prevent cross-tenant data leakage in multi-institution deployments. The changes add runtime guards, audit logging, an admin override mechanism with explicit scope change, and a comprehensive test suite.
Key changes:
backend/src/middleware/tenant.js— FixedensureTenantUserto correctly resolve user IDs from JWT payloads; addedverifyTenantAccessmiddleware (returns 403 on URL param mismatch); addedadminScopeOverridefor super_admin scope switching with full audit trail; addedwithTenantScopehelper to wrap query filters withtenantIdbackend/src/services/tenantService.js— AddedvalidateTenantAccessguard and wired it into 5 methods (getTenantUsers,updateTenantSettings,updateTenantBranding,updateTenantStatus,deleteTenant)backend/src/services/tenantAnalyticsService.js— Added optionaltenantIdfilter togetGrowthMetricsand passed it fromgetTenantAnalyticsfor proper scopingbackend/tests/services/tenant.isolation.test.js— New file with 26 tests across 6 suites covering context establishment, query scoping, cross-tenant denial, admin override, audit logging, and end-to-end isolationRelated Issue
Closes #67
Type of Change
Packages Affected
contracts/(Soroban / Rust)backend/(Node / Express)frontend/(Next.js)docs/How Has This Been Tested?
Ran the new integration test suite (
tests/services/tenant.isolation.test.js) — all 26 tests pass:Checklist
Breaking Changes
None
Additional Notes / Screenshots
Audit log output examples
Cross-tenant denied:
Admin scope override: