LibreChat/packages/api/src/acl
Danny Avila 47a8749428
🔒 fix: Prevent Role Grants on Shared Links (#14137)
* 🔒 fix: Prevent Cross-Tenant Role Grants on Shared Links

The shared-link access middleware falls back to a system-wide lookup so a
share owned by another tenant still resolves, then evaluates the ACL under
the share owner's tenant. It was passing the viewer's `role` from their own
tenant into that check. Role ACL principals are unqualified name strings, so
a tenant-B user with role USER could satisfy a tenant-A private share granted
to role USER (default role names collide across every tenant).

Pass the viewer's role only for same-tenant views; use `null` for cross-tenant
views so getUserPrincipals never builds a ROLE principal. `null` (not
`undefined`) is required: `undefined` re-derives the role via an unscoped
User lookup under runAsSystem for tenantId-less shares, reopening the bypass.

Widen checkPermission's `role` param to `string | null`. Adds regression
coverage for both the cross-tenant denial and same-tenant allow paths.

* 🔒 fix: Use authenticated user tenant for same-tenant role trust

Codex P2: share file routes (<img>/download) authenticate via
optionalShareFileAuth from the refresh cookie and never establish tenant ALS
context, so getTenantId() is undefined there. Comparing the share tenant to the
ALS context wrongly denied a legitimate same-tenant viewer their ROLE grant on
file/preview/download requests, even though the main share route authorized them.

Compare the share tenant against the authenticated user's own tenantId, which is
populated in both the JWT and cookie-auth paths (tenantContextMiddleware itself
derives the ALS tenant from user.tenantId, and req.tenantId is never set, so
user.tenantId is the authoritative, non-spoofable source). Adds a regression test
for the no-ALS-context cookie-auth file request.
2026-07-07 07:04:52 -04:00
..
accessControlService.spec.ts 🔗 feat: Add Granular Access Control to Shared Links via ACL System (#13051) 2026-06-03 14:17:17 -04:00
accessControlService.ts 🔒 fix: Prevent Role Grants on Shared Links (#14137) 2026-07-07 07:04:52 -04:00