Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
block from deleting org
Thiago Araujo da Silva376ff382cfa1
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 46e1bfc970..98986356d3 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -183,8 +183,9 @@ Auth extraction happens in `src/server/plugins/auth/`:which reads `user.superAdmin` rather than a CASL ability- OAuth client CRUD + consent (`v1/oauth-router.ts`) and `ee/v1/assume-privilege-router.ts`, where adelegated token could widen its own grant- - four org routes held back individually and commented as such: `GET /v1/organization`,- `GET /v1/organization/accessible-with-sub-orgs`, `POST /v2/organization`, `GET /v1/organization/:organizationId`+ - five org routes held back individually and commented as such: `GET /v1/organization`,+ `GET /v1/organization/accessible-with-sub-orgs`, `POST /v2/organization`, `GET /v1/organization/:organizationId`,+ `DELETE /v2/organization/:organizationId`Rough proxy: nothing passing `requireOrg: false` accepts `AuthMode.OAUTH`, since with no org there's noability to narrow. Before adding `AuthMode.OAUTH` to a route, check the handler actually builds an@@ -200,6 +201,13 @@ Auth extraction happens in `src/server/plugins/auth/`:no subject, any member with an identity token can already call it, and a gate would change first-partybehaviour. Weigh a route in this position on what it returns.+ **A route that mints session tokens can't accept a delegated one.** `DELETE /v2/organization/:organizationId`+ deletes the org the caller's token points at, so it reissues the user's session through+ `loginService.generateUserTokens` and returns it. `generateUserTokens` has no oauthClientId, scopes or+ delegation parameter, so the reissued pair is a first-party session regardless of what came in: a+ delegated caller would exit with credentials good for account management and org creation, the families+ deliberately closed to OAuth. Weigh any route that issues credentials the same way.+**Delegated tokens carry exactly one delegation marker, never both** (`oauth-client-types.ts`):- `scopes: [...]` from the authorization code grant. `permission-service` intersects the user's CASL ruleswith them (`applyOauthScopeToOrgRules` / `applyOauthScopeToProjectRules`).diff --git a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.tsindex 1babf8d793..3f2acea77b 100644--- a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts+++ b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts@@ -317,6 +317,20 @@ describe("Full delegation marker on a delegated OAuth token", async () => {expect(res.statusCode).toBe(403);});+ // Org deletion reissues the caller's session through generateUserTokens, which has no oauthClientId+ // or delegation parameter, so a delegated caller would exit holding a first-party session.+ test("a fully-delegated token cannot delete the organization", async () => {+ const token = signDelegatedToken({ delegation: OauthDelegationMode.Full });++ const res = await testServer.inject({+ method: "DELETE",+ url: `/api/v2/organization/${seedData1.organization.id}`,+ headers: { authorization: `Bearer ${token}` }+ });++ expect(res.statusCode).toBe(403);+ });+// Account routes authenticate on userId alone and build no permission, so they have to stay// unreachable whatever delegation marker the token carries.test("a fully-delegated token is still rejected on a JWT-only account route", async () => {diff --git a/backend/src/server/routes/v2/organization-router.ts b/backend/src/server/routes/v2/organization-router.tsindex 30a0505eb0..85cbbdd4f6 100644--- a/backend/src/server/routes/v2/organization-router.ts+++ b/backend/src/server/routes/v2/organization-router.ts@@ -471,7 +471,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {})}},- onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.OAUTH]),+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),handler: async (req, res) => {if (req.auth.actor !== ActorType.USER) return;diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdxindex 6f7f319439..34d73aab59 100644--- a/docs/documentation/platform/oauth-token-exchange.mdx+++ b/docs/documentation/platform/oauth-token-exchange.mdx@@ -56,9 +56,10 @@ Structurally, this is your organization's OIDC sign-in with the token handed oveThe issued token carries the user's **full effective permissions**, not a narrowed subset. There is no consent screen and no scope list: an organization admin approves the delegation once, when registering the application.-Two things it deliberately cannot do:+Three things it deliberately cannot do:- **Manage the user's account.** Changing MFA, revoking sessions, and other account self-management actions are never reachable with a delegated token.+- **Create or delete an organization.** Both require the user's own sign-in, so a delegated token is rejected on those endpoints even when the user is an organization admin.- **Outlive its access token.** No refresh token is issued, so your middleware exchanges again against the still-valid identity provider token.<Warning>