Skip to content

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

Addressed greptile comments

Carlos Monastyrski12bf0f80ab8d
diff --git a/backend/src/services/certificate/certificate-dal.ts b/backend/src/services/certificate/certificate-dal.ts
index 3439d75949..43ea771861 100644
--- a/backend/src/services/certificate/certificate-dal.ts
+++ b/backend/src/services/certificate/certificate-dal.ts
@@ -360,6 +360,33 @@ export const certificateDALFactory = (db: TDbClient) => {
}
};
+ const findByThumbprintInOrg = async ({
+ orgId,
+ column,
+ fingerprint,
+ limit
+ }: {
+ orgId: string;
+ column: "fingerprintSha1" | "fingerprintSha256";
+ fingerprint: string;
+ limit?: number;
+ }): Promise<TCertificates[]> => {
+ try {
+ const query = db
+ .replicaNode()(TableName.Certificate)
+ .join(TableName.Project, `${TableName.Certificate}.projectId`, `${TableName.Project}.id`)
+ .where(`${TableName.Project}.orgId`, orgId)
+ .where(`${TableName.Certificate}.${column}`, fingerprint)
+ .select(selectAllTableCols(TableName.Certificate));
+
+ if (limit) void query.limit(limit);
+
+ return await query;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Find certificate by thumbprint in org" });
+ }
+ };
+
const findActiveCertificatesByIds = async (certificateIds: string[]): Promise<TCertificates[]> => {
try {
if (certificateIds.length === 0) {
@@ -1133,6 +1160,7 @@ export const certificateDALFactory = (db: TDbClient) => {
findAllActiveCertsForSubscriber,
findActiveDigiCertCertsByOrderIds,
findExpiredSyncedCertificates,
+ findByThumbprintInOrg,
findActiveCertificatesByIds,
findActiveCertificatesForSync,
findCertificatesEligibleForRenewal,
diff --git a/backend/src/services/certificate/certificate-fns.ts b/backend/src/services/certificate/certificate-fns.ts
index 0e30e6f716..86b5f3ec03 100644
--- a/backend/src/services/certificate/certificate-fns.ts
+++ b/backend/src/services/certificate/certificate-fns.ts
@@ -201,8 +201,8 @@ export enum CertificateThumbprintAlgorithm {
/**
* Normalize a user-supplied certificate thumbprint into the colon-delimited fingerprint format
* stored on the certificate (e.g., "1A:2F:..."). Accepts thumbprints with or without colons,
- * whitespace, or "0x" prefixes, in any case. Returns the matching algorithm based on digest length
- * (40 hex chars => SHA-1, 64 hex chars => SHA-256).
+ * whitespace, or other separators, in any case. Returns the matching algorithm based on digest
+ * length (40 hex chars => SHA-1, 64 hex chars => SHA-256).
*/
export const normalizeThumbprint = (thumbprint: string) => {
const hex = thumbprint.replace(new RE2("[^a-fA-F0-9]", "g"), "");
diff --git a/backend/src/services/certificate/certificate-service.ts b/backend/src/services/certificate/certificate-service.ts
index 049a8a0f86..36ddc26ed7 100644
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@ -78,6 +78,7 @@ type TCertificateServiceFactoryDep = {
| "deleteById"
| "update"
| "find"
+ | "findByThumbprintInOrg"
| "transaction"
| "create"
| "findById"
@@ -431,12 +432,14 @@ export const certificateServiceFactory = ({
cert = await certificateDAL.findOne({ serialNumber });
} else if (thumbprint) {
const { algorithm, fingerprint } = normalizeThumbprint(thumbprint);
- const filter =
- algorithm === CertificateThumbprintAlgorithm.SHA1
- ? { fingerprintSha1: fingerprint }
- : { fingerprintSha256: fingerprint };
+ const column = algorithm === CertificateThumbprintAlgorithm.SHA1 ? "fingerprintSha1" : "fingerprintSha256";
- const matches = await certificateDAL.find(filter, { limit: 2 });
+ const matches = await certificateDAL.findByThumbprintInOrg({
+ orgId: actorOrgId,
+ column,
+ fingerprint,
+ limit: 2
+ });
if (matches.length > 1) {
throw new BadRequestError({
message: