From 2c53e744c23d2606c09347e136c5b12bf9bf59a7 Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Fri, 31 Oct 2025 09:12:14 -0700 Subject: [PATCH] Fix link header overriding issue and challenge dal find method bug --- .../pki-acme/pki-acme-challenge-dal.ts | 2 +- .../ee/services/pki-acme/pki-acme-schemas.ts | 2 + .../ee/services/pki-acme/pki-acme-service.ts | 84 ++++++++++--------- .../ee/services/pki-acme/pki-acme-types.ts | 2 +- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts index d23827a37..b8c909497 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts @@ -20,7 +20,7 @@ export const pkiAcmeChallengeDALFactory = (db: TDbClient) => { .join(TableName.PkiAcmeAuth, `${TableName.PkiAcmeChallenge}.authId`, `${TableName.PkiAcmeAuth}.id`) .select( selectAllTableCols(TableName.PkiAcmeChallenge), - db.ref("token").withSchema(TableName.PkiAcmeChallenge).as("token") + db.ref("token").withSchema(TableName.PkiAcmeAuth).as("token") ) .where(`${TableName.PkiAcmeChallenge}.id`, challengeId) .where(`${TableName.PkiAcmeChallenge}.authId`, authId) diff --git a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts b/backend/src/ee/services/pki-acme/pki-acme-schemas.ts index 25a3db3f4..0c9015700 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-schemas.ts @@ -158,6 +158,8 @@ export const GetAcmeAuthorizationResponseSchema = z.object({ ) }); +export const RespondToAcmeChallengeBodySchema = z.object({}); + export const RespondToAcmeChallengeResponseSchema = z.object({ type: z.enum(Object.values(AcmeChallengeType) as [string, ...string[]]), url: z.string(), diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.ts index c55a46542..d47d480f0 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-service.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts @@ -300,10 +300,10 @@ export const pkiAcmeServiceFactory = ({ contact: existingAccount.emails, orders: buildUrl(profile.id, `/accounts/${existingAccount.id}/orders`) }, - headers: [ - ["Location", buildUrl(profile.id, `/accounts/${existingAccount.id}`)], - ["Link", `<${buildUrl(profile.id, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profile.id, `/accounts/${existingAccount.id}`), + Link: `<${buildUrl(profile.id, "/directory")}>;rel="index"` + } }; } @@ -322,10 +322,10 @@ export const pkiAcmeServiceFactory = ({ contact: newAccount.emails, orders: buildUrl(profile.id, `/accounts/${newAccount.id}/orders`) }, - headers: [ - ["Location", buildUrl(profile.id, `/accounts/${newAccount.id}`)], - ["Link", `<${buildUrl(profile.id, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profile.id, `/accounts/${newAccount.id}`), + Link: `<${buildUrl(profile.id, "/directory")}>;rel="index"` + } }; }; @@ -345,10 +345,10 @@ export const pkiAcmeServiceFactory = ({ body: { status: "deactivated" }, - headers: [ - ["Location", buildUrl(profileId, `/accounts/${accountId}`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/accounts/${accountId}`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -432,10 +432,10 @@ export const pkiAcmeServiceFactory = ({ profileId, order }), - headers: [ - ["Location", buildUrl(profileId, `/orders/${order.id}`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/orders/${order.id}`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -455,10 +455,10 @@ export const pkiAcmeServiceFactory = ({ return { status: 200, body: buildAcmeOrderResource({ profileId, order }), - headers: [ - ["Location", buildUrl(profileId, `/orders/${orderId}`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/orders/${orderId}`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -482,10 +482,10 @@ export const pkiAcmeServiceFactory = ({ return { status: 200, body: buildAcmeOrderResource({ profileId, order }), - headers: [ - ["Location", buildUrl(profileId, `/orders/${orderId}`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/orders/${orderId}`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -507,10 +507,10 @@ export const pkiAcmeServiceFactory = ({ return { status: 200, body: "FIXME-certificate-pem", - headers: [ - ["Location", buildUrl(profileId, `/orders/${orderId}/certificate`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/orders/${orderId}/certificate`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -528,10 +528,10 @@ export const pkiAcmeServiceFactory = ({ body: { orders: [] }, - headers: [ - ["Location", buildUrl(profileId, `/accounts/${accountId}/orders`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/accounts/${accountId}/orders`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -569,10 +569,10 @@ export const pkiAcmeServiceFactory = ({ }; }) }, - headers: [ - ["Location", buildUrl(profileId, `/authorizations/${authzId}`)], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/authorizations/${authzId}`), + Link: `<${buildUrl(profileId, "/directory")}>;rel="index"` + } }; }; @@ -600,11 +600,13 @@ export const pkiAcmeServiceFactory = ({ status: challenge.status, token: challenge.token }, - headers: [ - ["Location", buildUrl(profileId, `/authorizations/${authzId}/challenges/http-01`)], - ["Link", `<${buildUrl(profileId, `/authorizations/${authzId}`)}>;rel="up"`], - ["Link", `<${buildUrl(profileId, "/directory")}>;rel="index"`] - ] + headers: { + Location: buildUrl(profileId, `/authorizations/${authzId}/challenges/${challengeId}`), + Link: [ + `<${buildUrl(profileId, `/authorizations/${authzId}`)}>;rel="up"`, + `<${buildUrl(profileId, "/directory")}>;rel="index"` + ] + } }; }; diff --git a/backend/src/ee/services/pki-acme/pki-acme-types.ts b/backend/src/ee/services/pki-acme/pki-acme-types.ts index dbd1ad25f..d2f96deb4 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-types.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-types.ts @@ -44,7 +44,7 @@ export type TAuthenciatedJwsPayload = TJwsPayload & { }; export type TAcmeResponse = { status: number; - headers: [string, string][]; + headers: Record; body: TPayload; };