Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the softdelete issue for the shared secret get by id #2687

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/src/services/secret-sharing/secret-sharing-dal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,27 @@ export const secretSharingDALFactory = (db: TDbClient) => {
}
};

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

return {
...sharedSecretOrm,
countAllUserOrgSharedSecrets,
pruneExpiredSharedSecrets,
softDeleteById,
softDeleteByIdentifier,
findActiveSharedSecrets
};
};
12 changes: 10 additions & 2 deletions backend/src/services/secret-sharing/secret-sharing-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,23 @@ export const secretSharingServiceFactory = ({
// 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"
});
}

if (expiresAfterViews !== null && expiresAfterViews === 0) {
// check view count 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 view count"
});
Expand Down