Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix membership inactive

Thiago Araujo da Silvaabae3c6c12fa
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 469f788040..557a6bb714 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -198,6 +198,15 @@ without it, any token that issuer signed for any application in the customer's e
Enabling the grant or changing the audience therefore requires `OrgPermissionSsoActions.Edit` on top of
the usual `OauthClients` check.
+**`getOrgPermission` is not a membership check, and token exchange is the one user-token path that
+cannot borrow login's.** It builds a CASL ability out of the actor's roles; the org-scope query in
+`permission-dal.ts` filters on org, actor and scope and never reads `Membership.isActive` or
+`Membership.status`. Every other route holding a user token got it from a browser login, and
+`selectOrganization` (`auth-login-service.ts`) rejects an inactive membership there. Token exchange
+mints a user token with no login in front of it, so it checks membership state itself
+(`exchangeSubjectToken` in `oauth-client-service.ts`) — without that, deactivating a member stops
+revoking their access. Any future non-interactive way of minting a user token needs the same check.
+
**That gate covers secret rotation too, and leaving it off any one path defeats it.** Rotation returns
the new secret in its response, so on an exchange application it hands the caller a working credential
for acting as any of the org's users — the same authority as enabling the grant. `OauthClients` Edit
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.ts
index 48e352a9b5..ac58202da1 100644
--- a/backend/src/services/oauth-client/oauth-client-service.ts
+++ b/backend/src/services/oauth-client/oauth-client-service.ts
@@ -1,6 +1,6 @@
import { ForbiddenError } from "@casl/ability";
-import { OrganizationActionScope, TOauthClients, TOrganizations } from "@app/db/schemas";
+import { OrganizationActionScope, OrgMembershipStatus, TOauthClients, TOrganizations } from "@app/db/schemas";
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
import { TOidcConfigDALFactory } from "@app/ee/services/oidc/oidc-config-dal";
import {
@@ -62,7 +62,7 @@ type TOauthClientServiceFactoryDep = {
| "rotateRefreshToken"
| "revokeSessionsByUserAgent"
>;
- orgDAL: Pick<TOrgDALFactory, "findById">;
+ orgDAL: Pick<TOrgDALFactory, "findById" | "findEffectiveOrgMembership">;
userDAL: Pick<TUserDALFactory, "findById">;
oidcConfigDAL: Pick<TOidcConfigDALFactory, "findOne">;
userAliasDAL: Pick<TUserAliasDALFactory, "findOne">;
@@ -580,6 +580,33 @@ export const oauthClientServiceFactory = ({
});
}
+ const orgMembership = await orgDAL.findEffectiveOrgMembership({
+ actorType: ActorType.USER,
+ actorId: user.id,
+ orgId: client.orgId,
+ acceptAnyStatus: true
+ });
+
+ if (!orgMembership) {
+ throw new UnauthorizedError({
+ message: "The user this token identifies is not a member of this application's organization."
+ });
+ }
+
+ if (orgMembership.status === OrgMembershipStatus.Invited) {
+ throw new UnauthorizedError({
+ message:
+ "The user this token identifies has been invited to this application's organization but has not joined it yet."
+ });
+ }
+
+ if (!orgMembership.isActive) {
+ throw new UnauthorizedError({
+ message:
+ "The membership of the user this token identifies has been deactivated in this organization, so an application cannot act on their behalf."
+ });
+ }
+
await permissionService.getOrgPermission({
actor: ActorType.USER,
actorId: user.id,