Skip to content

fix: bring in post-handoff messaging and server hardening - #9

Closed
shmlkv wants to merge 6 commits into
mainfrom
feat/dashboard-v2-handoff
Closed

shmlkv wants to merge 6 commits into
mainfrom
feat/dashboard-v2-handoff

Conversation

@shmlkv

@shmlkv shmlkv commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The dashboard handoff PR #7 has already merged, but this branch subsequently received six commits that are still absent from this repository's main. This follow-up brings in those changes: direct-message encryption, TTYA connection handling, local API restrictions, and resilience when peers disconnect or cannot be reached.

What changed

  • Exchange X25519 public keys during the identity handshake and replace placeholder DM encryption with ECDH-derived Double Ratchet encryption/decryption. Persist each peer's ratchet state in SQLite.
  • Extend TTYA handling with an initial signed bridge frame with signature/timestamp verification and a five-second authentication deadline. Bound frame and receive-buffer sizes at 64 KiB and validate incoming request/response shapes.
  • Limit the bridge's disconnected request queue to 1,000 entries and clean up stale browser visitors.
  • Require a localhost Origin for browser mutations, or a loopback source IP when Origin is absent. Add a 30-second public-group join timeout and return a generic failure message while logging details server-side.
  • Escape agent fingerprints in generated HTML, restrict data-directory/database permissions, and update the static-file dependency and serialization override.
  • Handle emitted Agent errors by default so network failures do not terminate the Node process solely because no consumer registered an error listener.
  • Add dashboard routing/hook, crypto, and Agent regression coverage; add a root typecheck script and adjust TypeScript configuration.

Review notes

The six commits include a documentation-site addition and its exact revert; there is no net documentation-site addition. The final comparison contains 27 changed files, including a substantial lockfile update.

The signed TTYA frame proves possession of the supplied ephemeral key; this change does not establish a configured trusted-bridge identity or mutual authentication. The newer security integration already present in shmlkv/network.self.md contains additional hardening beyond this branch.

Validation

  • Reviewed the current GitHub comparison against this repository's main and confirmed these six commits remain unmerged here.
  • Inspected the implementation and included regression tests. Tests were not rerun on this historical branch while preparing this PR; the website redesign's newer test results do not validate this branch.

shmlkv added 6 commits April 27, 2026 18:45
New packages/docs with 10 pages: intro (what/how/concepts),
connect-your-agent (MCP/Node SDK/TTYA), deep-dive (protocol/
encryption/security/API). Dashboard theme, dark mode default.
Add docs link to dashboard navbar.
- Add escapeHTML helper for <title> and body contexts in TTYA chat page
- Update stale test assertion (status-bar → status-pill)
- Remove rootDir/outDir from root tsconfig (packages set their own)
- Add typecheck script to root package.json
- Add dashboard test coverage (routes + useRoute hook, 25 tests)
- Gitignore .diagrams/ and scripts/gen-tldr.mjs
- Update @fastify/static to ^9.1.1 (CVE path traversal + route bypass)
- Pin serialize-javascript >=7.0.5 via pnpm.overrides (RCE fix)
- Fix CORS origin bypass: reject missing Origin, fallback to IP check
- Add 30s timeout on joinPublicGroup to prevent connection pool exhaustion
- Sanitize error messages in API responses (no internal leakage)
- Set 0700/0600 permissions on data directory and database file
- Add MAX_TTYA_FRAME_SIZE (64KB) to prevent OOM via malicious peers
- Add runtime validation (isValidTTYARequest/Response) for P2P messages
- Cap pending request queue at 1000 entries
- Add visitor map TTL cleanup (30min stale, 5min interval)
…ation

DM Encryption (replaces broken placeholder):
- Add X25519 public key exchange in identity handshake
- Implement ECDH shared secret derivation (computeSharedSecret)
- Wire Double Ratchet into agent.ts for send/receive DMs
- Add SQLite table + RatchetStateRepository for per-peer state persistence
- Add MAX_TTYA_FRAME_SIZE (64KB) to both bridge and ttya-manager

TTYA Bridge Authentication:
- Bridge generates ephemeral Ed25519 keypair on startup
- Sends signed auth frame (agentPubKey || timestamp) on connection
- Agent verifies signature + timestamp (±5min tolerance)
- 5-second auth timeout — unauthenticated connections are dropped
- Receive buffer size guard prevents OOM from malicious peers
Add default 'error' event listener in Agent constructor. Without it,
any error emitted by SwarmManager (e.g. failed P2P handshake, peer
disconnect) kills the Node.js process — documented EventEmitter behavior.

This fixes guaranteed crashes in MCP server and CLI when peers are
unreachable or network conditions are degraded.
@shmlkv shmlkv closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant