[bug]: web-bot-auth (TS): verify() rejects signatures covering another label's Signature-Agent member (§5.2.2)

オープン
#202 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
56/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cryptography, node.js, typescript

調査の方向性

Read packages/web-bot-auth/src/index.ts around verifiedSignatureAgent (lines 232–246), then compare its label handling with the cited §5.2.1 and §5.2.2 requirements and the Appendix D.2 example. Reproduce with the supplied script and check the existing test for member keys independent of signature labels. Done means the conformant browser signature verifies while a signature missing a required covered component is rejected.

索引モデルが issue の本文から書いたものです。

説明

Summary

verify() rejects every signature that covers more than one keyed Signature-Agent member (signature must cover exactly one signature-agent member). draft-ietf-webbotauth-httpsig-protocol-01 §5.2.2 lets a signer cover another label's fields, and requires it to cover every component of that label's Signature-Input, which includes that label's Signature-Agent member. So a conformant outer signature always covers two keyed members, and verify() always rejects it. Appendix D.2 has exactly this shape.

The signature itself is valid: http-message-sig verifySignature with label: "browser" verifies the same request. The rejection comes from the count check in verifiedSignatureAgent (index.ts L232–L246).

Conversely, removing "signature-agent";key="agent" from the outer signature makes verify() accept it, although §5.2.2 forbids that (the component is listed in "signature-input";key="agent").

Spec

draft-ietf-webbotauth-httpsig-protocol-01, §5.2.1:

Its member keyed to the signature label MUST be signed as a component as defined in Section 2.1 of [HTTP-MESSAGE-SIGNATURES].

§5.2.2:

A signer MAY cover members from another signature label, which preserves evidence that another signer contributed to the request. A signer that covers "signature";key=X MUST also cover "signature-input";key=X, and MUST cover every component identifier listed in "signature-input";key=X.

Appendix D.2 signs browser=("@method" "@authority" "@path" "signature-agent";key="browser" "signature-agent";key="agent" "signature-input";key="agent" "signature";key="agent") and states: "The origin verifies each signature on its own." The same §5.2.2 paragraph and D.2 example are in draft-meunier-webbotauth-httpsig-protocol-01, the revision cited in the package README.

Reproduction
import { generateKeyPairSync, sign as edSign } from "node:crypto";
import { verify } from "web-bot-auth";
import { verifierFromJWK } from "web-bot-auth/crypto";

async function key() {
  const { privateKey, publicKey } = generateKeyPairSync("ed25519");
  const verifier = await verifierFromJWK(publicKey.export({ format: "jwk" }));
  return { verifier, sign: (base) => edSign(null, Buffer.from(base), privateKey).toString("base64") };
}
const agent = await key();
const browser = await key();
const created = 1800000000;
const params = (k, c) =>
  `;created=${c};expires=${created + 3600};keyid="${k.verifier.keyid}";alg="ed25519";tag="web-bot-auth"`;

// Shape of draft-ietf-webbotauth-httpsig-protocol-01, Appendix D.2
const agentInput = `("@method" "@authority" "@path" "signature-agent";key="agent")${params(agent, created)}`;
const agentSig = agent.sign(
  `"@method": GET\n"@authority": origin.example\n"@path": /resource\n` +
    `"signature-agent";key="agent": "https://agent.example"\n"@signature-params": ${agentInput}`
);
const browserInput =
  `("@method" "@authority" "@path" "signature-agent";key="browser" "signature-agent";key="agent" ` +
  `"signature-input";key="agent" "signature";key="agent")${params(browser, created + 1)}`;
const browserSig = browser.sign(
  `"@method": GET\n"@authority": origin.example\n"@path": /resource\n` +
    `"signature-agent";key="browser": "https://browser.example"\n` +
    `"signature-agent";key="agent": "https://agent.example"\n` +
    `"signature-input";key="agent": ${agentInput}\n` +
    `"signature";key="agent": :${agentSig}:\n` +
    `"@signature-params": ${browserInput}`
);
const request = () =>
  new Request("https://origin.example/resource", {
    headers: {
      "signature-agent": `agent="https://agent.example", browser="https://browser.example"`,
      "signature-input": `agent=${agentInput}, browser=${browserInput}`,
      signature: `agent=:${agentSig}:, browser=:${browserSig}:`,
    },
  });
const keys = [agent.verifier, browser.verifier];
const resolver = (c) => keys.find((v) => v.keyid === c.keyid);
const now = new Date((created + 10) * 1000);

for (const label of ["agent", "browser"]) {
  try {
    const r = await verify(request(), { label, now, resolver });
    console.log(label, "-> verified, signatureAgent:", r.signatureAgent.uri);
  } catch (e) {
    console.log(label, "->", e.message, "|", e.cause?.message);
  }
}

Expected:

agent -> verified, signatureAgent: https://agent.example
browser -> verified, signatureAgent: https://browser.example

Actual:

agent -> verified, signatureAgent: https://agent.example
browser -> Verifier resolution failed | signature must cover exactly one signature-agent member
Possible fix

Pass the candidate label to verifiedSignatureAgent. When more than one keyed member is covered, select the one whose key equals the label (§5.2.1), and reject only if none does. The single-member case stays as it is (it also covers relabeling permitted by §6.6.1), so the existing test "authenticates a member key independent from the signature label" keeps passing. This could be part of #171; related to #102 and #193.

Environment
  • main at ce5e54fd7e05dd8ae14fd56198cfcba7acb6082e, built with npm ci && npm run build; npm [email protected] gives the same output
  • Node.js v22.23.4, macOS
主要言語
Rust
スター
182
フォーク
49
平均マージ
1日 20分
マージ済み PR(30日)
19

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/web-bot-auth のほかの issue

cloudflare/web-bot-auth の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。