Node.js based forum software built for the modern web
fix(activitypub): add required algorithm parameter to RFC 9421 Signature-Input header
Julian Lambce41a39d347
diff --git a/src/activitypub/signatures.js b/src/activitypub/signatures.jsindex 31a9863e62..ccb74436b4 100644--- a/src/activitypub/signatures.js+++ b/src/activitypub/signatures.js@@ -93,6 +93,9 @@ Signatures.signRfc9421 = async ({ key, keyId }, url, method = 'GET', digest = nuheadersToSign.digest = digest;}+ // Import private key early to determine algorithm for Signature-Input+ const privateKey = await importPrivateKey(key, ['sign']);+// Determine signed components list// @method + @target-uri (not @request-target) so that verifiers requiring// those components explicitly (e.g. Mitra) can validate the signature@@ -102,13 +105,12 @@ Signatures.signRfc9421 = async ({ key, keyId }, url, method = 'GET', digest = nu}// Build Signature-Input header- const signatureInput = `sig1=("${components.join('" "')}");created=${created};keyid="${keyId}"`;+ // RFC 9421 Section 2.2: algorithm parameter is required+ const algorithm = getDraftAlgoString(privateKey);+ const signatureInput = `sig1=("${components.join('" "')}");algorithm="${algorithm}";created=${created};keyid="${keyId}"`;headersToSign['signature-input'] = signatureInput;try {- // Import private key- const privateKey = await importPrivateKey(key, ['sign']);-// Build signature baseconst base = new RFC9421SignatureBaseFactory({method,diff --git a/test/activitypub/signatures.js b/test/activitypub/signatures.jsindex 9749618e6c..577a30cc2c 100644--- a/test/activitypub/signatures.js+++ b/test/activitypub/signatures.js@@ -257,9 +257,9 @@ describe('http signature signing and verification', () => {await activitypub.signatures.signRfc9421(keyData, endpoint, 'GET');const { host } = nconf.get('url_parsed');- const paramsMatch = signatureInput.match(/^sig1=(\([^)]*\));created=(\d+);keyid="([^"]*)"$/);+ const paramsMatch = signatureInput.match(/^sig1=(\([^)]*\));algorithm="([^"]*)";created=(\d+);keyid="([^"]*)"$/);assert(paramsMatch, `unexpected Signature-Input format: ${signatureInput}`);- const [, componentsInnerList, created, keyId] = paramsMatch;+ const [, componentsInnerList, algorithm, created, keyId] = paramsMatch;const componentIds = [...componentsInnerList.matchAll(/"([^"]*)"/g)].map((m) => m[1]);const componentValues = {'@method': 'GET',@@ -268,7 +268,7 @@ describe('http signature signing and verification', () => {date,};const lines = componentIds.map((id) => `"${id}": ${componentValues[id]}`);- lines.push(`"@signature-params": ${componentsInnerList};created=${created};keyid="${keyId}"`);+ lines.push(`"@signature-params": ${componentsInnerList};algorithm="${algorithm}";created=${created};keyid="${keyId}"`);const expectedBase = lines.join('\n');const publicKeyPem = await activitypub.getPublicKey('uid', uid);