[bug]: http-message-sig accepts a Decimal `created`/`expires` and re-serializes it as an Integer in the signature base

Aperta Adatta ai principianti
#203 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript

Direzione di ricerca

Inizia in packages/http-message-sig/src/core.ts: leggi validateKnownParameters (intorno a L133-L151) e buildSignatureBase (intorno a L569-L580, chiamato vicino a L1032), oltre agli helper esistenti di scansione del testo grezzo rawParameterCount e assertNoRfc9651Syntax. Esegui la riproduzione dall'issue per confermare che il caso Decimal passa oggi, poi aggiungi un test usando created=1800000000.0. Fatto significa che created/expires contenenti un . vengono rifiutati mentre i valori Integer vengono ancora verificati.

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

Descrizione

Summary

RFC 9421 §2.3 defines created and expires as Integers. verifySignature accepts created=1800000000.0 (an RFC 8941 Decimal) and treats it as created=1800000000:

  • structured-headers parses Integers and Decimals into the same JS number (its readme: "Javascript can't differentiate between 1.0 and 1"), so the Number.isInteger check in validateKnownParameters (core.ts L133) passes.
  • buildSignatureBase (core.ts L569, called at L1032) re-serializes the parsed inner list, so @signature-params contains created=1800000000. RFC 8941 §4.1.5 serializes that Decimal as 1800000000.0.

The value that is checked is the value that was signed, so this is not a forgery or time-window bypass. It is a strictness bug. A fractional value such as 1800000000.5 is already rejected. web-bot-auth verify() inherits the behaviour.

Spec

RFC 9421 §2.3:

created: Creation time as a UNIX timestamp value of type Integer. Sub-second precision is not supported.

expires: Expiration time as a UNIX timestamp value of type Integer. Sub-second precision is not supported.

RFC 9421 §3.2, step 4: "Examine the signature parameters to confirm that the signature meets the requirements described in this document [...]"

RFC 8941 defines Integer (sf-integer = ["-"] 1*15DIGIT, §3.3.1) and Decimal (sf-decimal = ["-"] 1*12DIGIT "." 1*3DIGIT, §3.3.2) as distinct types.

Reproduction
import { generateKeyPairSync, sign, verify } from "node:crypto";
import { verifySignature } from "http-message-sig";

const { privateKey, publicKey } = generateKeyPairSync("ed25519");
const verifier = { algorithm: "ed25519", verify: (data, sig) => verify(null, data, publicKey, sig) };
const signBase = (params) =>
  sign(null, Buffer.from(`"@authority": example.com\n"@signature-params": ${params}`), privateKey).toString("base64");
const run = async (name, params, signature) => {
  const request = new Request("https://example.com/", {
    headers: { "signature-input": `sig1=${params}`, signature: `sig1=:${signature}:` },
  });
  try {
    const r = await verifySignature(request, {
      policy: { algorithms: ["ed25519"], requiredComponents: [], requiredParameters: [], now: 1800000010 },
      resolveVerifier: () => verifier,
    });
    console.log(name, "-> verified", JSON.stringify(r.parameters));
  } catch (e) {
    console.log(name, "->", e.message);
  }
};

const integer = `("@authority");created=1800000000;expires=1800003600`;
const decimal = `("@authority");created=1800000000.0;expires=1800003600.0`;
await run("A signed Integer, sent Decimal", decimal, signBase(integer));
await run("B signed and sent Decimal    ", decimal, signBase(decimal));

Expected: both rejected, because created and expires are not Integers.

Actual:

A signed Integer, sent Decimal -> verified {"created":1800000000,"expires":1800003600}
B signed and sent Decimal     -> Signature verification failed
Possible fix

Reject created/expires whose raw value in Signature-Input contains a .. http-message-sig already scans the raw field text (rawParameterCount, assertNoRfc9651Syntax). A test with created=1800000000.0 would cover it.

Environment
  • main at ce5e54fd7e05dd8ae14fd56198cfcba7acb6082e (structured-headers 2.1.1), built with npm ci && npm run build; npm [email protected] (structured-headers 2.0.3) 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.