fix(federation): address code review findings for FED-011

- Fix race window: store pendingHmacSecret AFTER remote peer confirms,
  not before (admin endpoint + auto-rotation worker)
- Add hex validation on newSecret at /peer/rotate endpoint
- Use pending-secret-aware signing in initial sync worker
- Add test for corrupt state (pendingHmacSecret set, secretRotationAt null)
This commit is contained in:
Jannis Braun
2026-03-31 21:01:02 +02:00
parent f91312a6d9
commit abdaf99bb4
3 changed files with 32 additions and 42 deletions
@@ -67,4 +67,14 @@ describe('verifyPeerSignature', () => {
const sig = signRequest(body, primarySecret, timestamp, null);
expect(verifyPeerSignature(body, sig, timestamp, null, makePeer())).toBe(true);
});
it('does not try pending secret when secretRotationAt is null', () => {
const timestamp = Date.now();
const sig = signRequest(body, pendingSecret, timestamp, nonce);
const peer = makePeer({
pendingHmacSecret: pendingSecret,
secretRotationAt: null,
});
expect(verifyPeerSignature(body, sig, timestamp, nonce, peer)).toBe(false);
});
});