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

Aperta
#202 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cryptography, node.js, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Rust
Stelle
182
Fork
49
Merge medio
1g 20m
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/web-bot-auth

Tutte le issue di cloudflare/web-bot-auth

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.