Skip to content

fix(core): verify a claimed peer ID against its presented certificate - #41

Merged
Mearman merged 1 commit into
mainfrom
worktree-issue-40-peer-cert-verify
Sep 9, 2026
Merged

fix(core): verify a claimed peer ID against its presented certificate#41
Mearman merged 1 commit into
mainfrom
worktree-issue-40-peer-cert-verify

Conversation

@Mearman

@Mearman Mearman commented Sep 9, 2026

Copy link
Copy Markdown
Member

Fixes #40

Ordinary peer connections accepted a peer's identity purely from the self-reported peerId in introduce/pong/connectToPeer, over a rejectUnauthorized: false TLS connection with no fingerprint check against the certificate actually presented — despite tls-transport.ts's own doc comment claiming that check already existed.

Every bridge sets store.peerId = identity.fingerprint, so a peer's ID is always supposed to equal the fingerprint of its own certificate. This adds TlsTransport.verifyClaimedPeerId(), applied at the three points a remote peer's identity is established from a self-reported wire message:

  • the coordinator's introduce handler
  • the data server's pong handler
  • the client's own connectToPeer dial, which already holds the target peer's expected ID from the peer list

A mismatch (or no certificate at all) destroys the socket and reports it via onError instead of accepting the connection.

connect_request/connectToRemote (the invite-based remote-join flow) is untouched — it already requires explicit human approval via acceptConnection, a different trust mechanism from the always-on mesh path this issue is scoped to.

Added src/test/peer-id-verification.integration.test.ts covering all three rejection paths, plus confirmed the existing TLS/mesh/federation integration suites still pass with legitimate (matching) identities.

TlsTransport accepted introduce, pong, and connectToPeer identity claims
purely from the self-reported peerId in the wire message, over a
rejectUnauthorized: false TLS connection with no fingerprint check
against the certificate actually presented. Any socket could claim any
peerId regardless of the certificate it held, contradicting the
transport's own doc comment claiming fingerprint verification already
happened.

Add verifyClaimedPeerId(), applied wherever a remote peer's identity is
established from a self-reported wire message: the coordinator's
introduce handler, the data server's pong handler, and the client's own
connectToPeer dial (which already holds the peer's expected ID from the
peer list). A mismatch, or no certificate at all, destroys the socket
and reports an error rather than accepting the connection.
@Mearman
Mearman marked this pull request as ready for review September 9, 2026 21:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-09T21:57:10.483205Z 635f6eb Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Mearman
Mearman merged commit 15113b0 into main Sep 9, 2026
5 checks passed
@Mearman
Mearman deleted the worktree-issue-40-peer-cert-verify branch September 9, 2026 21:57
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.27.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ordinary peer connections never verify a peer's certificate against its claimed ID

1 participant