Skip to content

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

feat: addressed llm review

=ddc8cc6a2f5b
diff --git a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-dal.ts b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-dal.ts
index 7694a8f457..f8f873f44c 100644
--- a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-dal.ts
+++ b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-dal.ts
@@ -48,11 +48,11 @@ export const dynamicSecretLeaseDALFactory = (db: TDbClient) => {
const countLeasesForDynamicSecret = async (dynamicSecretId: string, tx?: Knex) => {
try {
- const doc = await (tx || db.replicaNode())(TableName.DynamicSecretLease)
- .count("*")
+ const doc = (await (tx || db.replicaNode())(TableName.DynamicSecretLease)
+ .count("* as count")
.where({ dynamicSecretId })
- .first();
- return parseInt(doc || "0", 10);
+ .first()) as { count: string | number } | undefined;
+ return parseInt(String(doc?.count ?? "0"), 10);
} catch (error) {
throw new DatabaseError({ error, name: "DynamicSecretCountLeases" });
}
diff --git a/backend/src/ee/services/dynamic-secret/providers/oauth.test.ts b/backend/src/ee/services/dynamic-secret/providers/oauth.test.ts
index d0f2d4c02a..5bc7ae2d3b 100644
--- a/backend/src/ee/services/dynamic-secret/providers/oauth.test.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/oauth.test.ts
@@ -152,17 +152,32 @@ describe("OAuthProvider.validateProviderInputs", () => {
).rejects.toThrow("can't be changed while this dynamic secret has active leases");
});
- test("allows a token URL change when there are no leases, and a client ID change with leases", async () => {
- const provider = OAuthProvider();
+ test("rejects a client ID change while leases are active", async () => {
await expect(
- provider.validateProviderInputs(
- { ...baseInputs, tokenUrl: "https://other.example.com/token" },
+ OAuthProvider().validateProviderInputs(
+ { ...baseInputs, clientId: "rotated-client" },
+ { ...metadata, previousInputs: baseInputs, hasActiveLeases: true }
+ )
+ ).rejects.toThrow("client ID can't be changed while this dynamic secret has active leases");
+ });
+
+ test("allows token URL and client ID changes when there are no leases", async () => {
+ await expect(
+ OAuthProvider().validateProviderInputs(
+ { ...baseInputs, tokenUrl: "https://other.example.com/token", clientId: "rotated-client" },
{ ...metadata, previousInputs: baseInputs, hasActiveLeases: false }
)
).resolves.toBeDefined();
+ });
+
+ test("allows rotating the secret, auth method and revocation URL while leases are active", async () => {
await expect(
- provider.validateProviderInputs(
- { ...baseInputs, clientId: "rotated-client" },
+ OAuthProvider().validateProviderInputs(
+ {
+ ...baseInputs,
+ revocationUrl: "https://auth.example.com/oauth2/v2/revoke",
+ clientAuth: { method: OAuthClientAuthMethod.ClientSecretPost, clientSecret: "rotated-secret" }
+ },
{ ...metadata, previousInputs: baseInputs, hasActiveLeases: true }
)
).resolves.toBeDefined();
diff --git a/backend/src/ee/services/dynamic-secret/providers/oauth.ts b/backend/src/ee/services/dynamic-secret/providers/oauth.ts
index f48dc7f50b..2a7a0b295a 100644
--- a/backend/src/ee/services/dynamic-secret/providers/oauth.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/oauth.ts
@@ -151,14 +151,24 @@ export const OAuthProvider = (): TDynamicProviderFns => {
) => {
const providerInputs = await $parseInputs(inputs);
- const previousTokenUrl = (previousInputs as { tokenUrl?: unknown } | undefined)?.tokenUrl;
- if (hasActiveLeases && typeof previousTokenUrl === "string" && previousTokenUrl !== providerInputs.tokenUrl) {
+ if (!hasActiveLeases) return providerInputs;
+
+ const previous = previousInputs as { tokenUrl?: unknown; clientId?: unknown } | undefined;
+ if (typeof previous?.tokenUrl === "string" && previous.tokenUrl !== providerInputs.tokenUrl) {
throw new BadRequestError({
message:
"The token URL can't be changed while this dynamic secret has active leases, because their tokens were issued by the current authorization server. Revoke the active leases first, then change the token URL."
});
}
+ // RFC 7009 section 2.1: a server only lets the client that was issued a token revoke it
+ if (typeof previous?.clientId === "string" && previous.clientId !== providerInputs.clientId) {
+ throw new BadRequestError({
+ message:
+ "The client ID can't be changed while this dynamic secret has active leases, because only the client that issued their tokens can revoke them. Revoke the active leases first, then change the client ID."
+ });
+ }
+
return providerInputs;
};