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

Abierto
#202 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
56/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cryptography, node.js, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Rust
Estrellas
182
Forks
49
Merge medio
1 d 20 min
PR fusionados (30 d)
19

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cloudflare/web-bot-auth

Todos los issues de cloudflare/web-bot-auth

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.