Skip to content

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

fix(dynamic-secrets): allow hyphens in normalized usernames

Vlad Ligai6b369999ff57
diff --git a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.test.ts b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.test.ts
index 2086554196..477796c88c 100644
--- a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.test.ts
+++ b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.test.ts
@@ -7,10 +7,13 @@ describe("toSafeUsername", () => {
expect(toSafeUsername("build_agent01")).toBe("build_agent01");
});
- test("replaces disallowed characters (including hyphen) with underscore", () => {
+ test("replaces disallowed characters with underscore", () => {
expect(toSafeUsername("name with spaces")).toBe("name_with_spaces");
expect(toSafeUsername("a.b@c")).toBe("a_b_c");
- expect(toSafeUsername("ci-runner")).toBe("ci_runner");
+ });
+
+ test("keeps letters, digits, underscore and hyphen", () => {
+ expect(toSafeUsername("ci-runner_01")).toBe("ci-runner_01");
});
test("caps the result at 63 characters", () => {
diff --git a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.ts b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.ts
index f8860f9541..de04757486 100644
--- a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.ts
+++ b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-service.ts
@@ -35,12 +35,11 @@ import {
TDynamicSecretLeaseServiceFactory
} from "./dynamic-secret-lease-types";
-// Normalizes an untrusted value (identity name / email) to a plain database identifier:
-// letters, digits and underscore only, capped at 63 chars (Postgres' identifier length
-// limit). Hyphens are folded to underscores too, keeping the derived username to the most
-// conservative identifier set. Exported for testing.
+// Normalizes a value (identity name / email) to a plain database identifier: letters, digits,
+// underscore and hyphen, with everything else folded to underscore and the length capped at 63
+// chars (Postgres' identifier length limit). Exported for testing.
export const toSafeUsername = (raw: string): string =>
- new RE2("[^a-zA-Z0-9_]", "g").replace(raw, "_").slice(0, 63) || "inf_user";
+ new RE2("[^a-zA-Z0-9_-]", "g").replace(raw, "_").slice(0, 63) || "inf_user";
type TDynamicSecretLeaseServiceFactoryDep = {
dynamicSecretLeaseDAL: TDynamicSecretLeaseDALFactory;