Skip to content

Commit 8ba8fc3

Browse files
dahliaclaude
andcommitted
Ensure Date header is set for RFC 9421 signatures
- Automatically add Date header when missing from requests - Add validation for missing headers in signature base creation - Improve timestamp handling with proper variable scoping 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0010f16 commit 8ba8fc3

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

fedify/sig/http.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ export function createRfc9421SignatureBase(
253253
throw new Error(`Unsupported derived component: ${component}`);
254254
} else {
255255
// Regular header
256-
value = request.headers.get(component) || "";
256+
const header = request.headers.get(component);
257+
if (header == null) throw new Error(`Missing header: ${component}`);
258+
value = header;
257259
}
258260

259261
// Format the component as per RFC 9421 Section 2.1
@@ -406,8 +408,12 @@ async function signRequestRfc9421(
406408
}
407409

408410
// Use provided timestamp or current time
409-
const created = ((currentTime ?? Temporal.Now.instant()).epochMilliseconds /
410-
1000) | 0; // Convert to seconds and truncate to integer
411+
currentTime ??= Temporal.Now.instant();
412+
const created = (currentTime.epochMilliseconds / 1000) | 0; // Convert to seconds and truncate to integer
413+
414+
if (!headers.has("Date")) {
415+
headers.set("Date", new Date(currentTime.toString()).toUTCString());
416+
}
411417

412418
// Define components to include in the signature
413419
const components = [

0 commit comments

Comments
 (0)