Skip to content

Commit

Permalink
fix the softdelete issue for the shared secret get by id
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyar-shamshi committed Nov 4, 2024
1 parent 6b7bc2a commit e9ef372
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions backend/src/services/secret-sharing/secret-sharing-dal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,36 @@ export const secretSharingDALFactory = (db: TDbClient) => {
tag: ""
});
} catch (error) {
console.log(error);
throw new DatabaseError({
error,
name: "Soft Delete Shared Secret"
});
}
};

const softDeleteByIdentifier = async (identifier: string) => {
try {
await db(TableName.SecretSharing).where({ identifier }).update({
encryptedValue: "",
iv: "",
tag: ""
});
} catch (error) {
console.log(error);
throw new DatabaseError({
error,
name: "Soft Delete Shared Secret By Identifier"
});
}
};

return {
...sharedSecretOrm,
countAllUserOrgSharedSecrets,
pruneExpiredSharedSecrets,
softDeleteById,
softDeleteByIdentifier,
findActiveSharedSecrets
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,14 @@ export const secretSharingServiceFactory = ({

// all secrets pass through here, meaning we check if its expired first and then check if it needs verification
// or can be safely sent to the client.

if (expiresAt !== null && expiresAt < new Date()) {
// check lifetime expiry
await secretSharingDAL.softDeleteById(sharedSecretId);
if (isUuidV4(sharedSecretId)) {
await secretSharingDAL.softDeleteById(sharedSecretId);
} else {
await secretSharingDAL.softDeleteByIdentifier(Buffer.from(sharedSecretId, "base64url").toString("hex"));
}
throw new ForbiddenRequestError({
message: "Access denied: Secret has expired by lifetime"
});
Expand Down

0 comments on commit e9ef372

Please sign in to comment.