Skip to content

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

dedup metadata

Matheus Nogueira8b509e2f858e
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
index baa323d060..0d0c094045 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
@@ -463,9 +463,17 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
.orderBy(`${TableName.ResourceMetadata}.createdAt`, "asc")
.orderBy(`${TableName.ResourceMetadata}.id`, "asc");
+ // Deduplicate tags by tagId per secret: the junction table has no unique
+ // constraint on the FK pair, and the PIT update path can reinsert duplicates.
const tagsBySecretId = new Map<string, { id: string; color: string; slug: string; name: string }[]>();
+ const seenTags = new Set<string>();
for (const t of tagRows) {
const sid = t.secretId;
+ const dedupeKey = `${sid}:${t.tagId}`;
+ // eslint-disable-next-line no-continue
+ if (seenTags.has(dedupeKey)) continue;
+ seenTags.add(dedupeKey);
+
let arr = tagsBySecretId.get(sid);
if (!arr) {
arr = [];
@@ -483,8 +491,14 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
string,
{ id: string; key: string; value: string | null; encryptedValue: Buffer | null }[]
>();
+ const seenMeta = new Set<string>();
for (const m of metadataRows) {
const sid = m.secretId as string;
+ const dedupeKey = `${sid}:${m.metadataId}`;
+ // eslint-disable-next-line no-continue
+ if (seenMeta.has(dedupeKey)) continue;
+ seenMeta.add(dedupeKey);
+
let arr = metaBySecretId.get(sid);
if (!arr) {
arr = [];