Files
Rohit Ghumare a312640609 fix: security hardening and code quality fixes
* Security hardening and code quality fixes

- Replace execSync with execFileSync to prevent shell injection (providers, executor, fetcher, publish)
- Add security headers: X-Content-Type-Options, X-Frame-Options, Content-Security-Policy, Referrer-Policy
- Add input validation for save route name field to prevent path traversal
- Fix rate limiter IP extraction (x-forwarded-for + x-real-ip fallback)
- Default server bind to 127.0.0.1 instead of 0.0.0.0
- CORS fallback to * (configurable via options.corsOrigin)
- Use execFileSync in publish submit (avoid shell injection when opening browser)
- TLS-aware health checks and HTTPS support in RemoteTransport
- Conditional rejectUnauthorized for TLS (self-signed configurable)
- Add **/.env.local patterns to .gitignore
- Formatting: double quotes, trailing commas (Prettier)

* fix: address CodeRabbit and Devin review findings from PR #74

- TLS: default allowSelfSigned=true to preserve self-signed cert workflow;
  enforce rejectUnauthorized=true when trustedCAs are supplied in client context
- Signature verification: verifySecureMessage now cryptographically verifies
  signatures using PeerIdentity.verifyHex instead of only checking fingerprints
- WebSocket: fix timeout handle leak in performClientHandshake; add error
  logging to empty catch blocks; add per-socket error handler; pre-compute
  signature once in broadcast(); add send error callbacks; reject startup if
  TLS configured but certInfo missing
- Command parsing: replace broken regex tokenizer with shared splitCommand()
  utility that correctly handles --flag="value with spaces"
- Rate limiter: prefer x-real-ip, fall back to rightmost x-forwarded-for entry
- Save route: scope IPv6 prefix checks to actual IPv6 addresses; stop leaking
  internal error messages to clients
- Publish: extract shared parseSkillFrontmatter(); fix getRepoInfo to use
  async execFileSync; fix path containment checks with separator
- Remote transport: add rejectUnauthorized option; bracket IPv6 in URLs;
  fix host:port splitting for IPv6 with lastIndexOf
- Health checks: add tls/tlsAllowSelfSigned to Host type; pass https options
- Fetcher: validate owner/repo; derive indexDir from INDEX_PATH
- .gitignore: add recursive **/.env pattern, remove redundant entries

* fix(executor): restore shell feature support in shellExecutor

The previous security hardening replaced execSync with execFileSync,
which broke commands using pipes, redirects, and subshells. Now detects
shell metacharacters and falls back to sh -c for those commands while
keeping execFileSync for simple commands.
2026-02-22 21:39:47 +05:30
..
2026-02-20 00:16:28 +05:30

@skillkit/mesh

npm version License

Peer mesh network for SkillKit - Multi-machine agent distribution with secure peer-to-peer communication.

Installation

npm install @skillkit/mesh

Key Features

  • Peer Discovery: UDP multicast LAN discovery with signed announcements
  • Multi-Transport: HTTP, WebSocket, and UDP transport layers
  • Ed25519 Cryptography: Peer identity, message signing, and verification
  • XChaCha20-Poly1305: End-to-end message encryption
  • TLS Support: Self-signed certificates for secure transport
  • JWT Authentication: Challenge-response handshake with EdDSA tokens
  • Health Monitoring: Automatic peer health checks with latency tracking
  • Trust Management: Peer trust/revoke with fingerprint-based verification

Usage

Initialize Mesh Network

import { MeshHost, PeerIdentity, MeshSecurityConfig } from '@skillkit/mesh';

// Generate or load identity
const identity = await PeerIdentity.generate();
console.log('Fingerprint:', identity.fingerprint);

// Configure security
const security: MeshSecurityConfig = {
  discovery: { mode: 'signed' },
  transport: { encryption: 'required', tls: 'self-signed', requireAuth: true },
  trust: { autoTrustFirst: true },
};

// Create mesh host
const host = new MeshHost({
  hostId: 'my-workstation',
  identity,
  security,
});

await host.start();

Discover Peers

import { LocalDiscovery } from '@skillkit/mesh';

// Start discovery
const discovery = new LocalDiscovery({
  identity,
  port: 41234,
});

discovery.on('peer', (peer) => {
  console.log('Found peer:', peer.hostId, peer.fingerprint);
});

await discovery.start();
await discovery.announce();

Send Messages

// Send to a specific peer
await host.send('peer-fingerprint', {
  type: 'skill-sync',
  payload: { skills: ['react-patterns', 'api-design'] },
});

// Broadcast to all peers
await host.broadcast({
  type: 'announcement',
  payload: { message: 'New skill available' },
});

Secure Transport

import { SecureWebSocketTransport, TLSManager } from '@skillkit/mesh';

// Generate TLS certificate
const certInfo = await TLSManager.generateCertificate(identity, 'my-host');

// Create secure WebSocket transport
const transport = new SecureWebSocketTransport({
  port: 8443,
  tls: {
    cert: certInfo.cert,
    key: certInfo.key,
  },
  requireAuth: true,
});

await transport.listen();

Trust Management

import { SecureKeystore } from '@skillkit/mesh';

// Initialize keystore
const keystore = new SecureKeystore({
  path: '~/.skillkit/mesh/identity',
});

// Trust a peer
await keystore.addTrustedPeer(peerFingerprint, peerPublicKey);

// Revoke trust
await keystore.revokePeer(peerFingerprint);

// List trusted peers
const trusted = await keystore.getTrustedPeers();

Security Levels

Level Discovery Transport Auth Use Case
development open none none Local dev
signed signed optional optional Trusted LAN
secure (default) signed required required Production
strict trusted-only required mTLS High security

API Reference

MeshHost

interface MeshHost {
  start(): Promise<void>;
  stop(): Promise<void>;
  send(peerId: string, message: TransportMessage): Promise<void>;
  broadcast(message: TransportMessage): Promise<void>;
  getPeers(): PeerInfo[];
  on(event: 'message' | 'peer' | 'disconnect', handler: Function): void;
}

PeerIdentity

interface PeerIdentity {
  static generate(): Promise<PeerIdentity>;
  static fromPrivateKey(key: Uint8Array): Promise<PeerIdentity>;
  static load(path: string, passphrase?: string): Promise<PeerIdentity>;
  save(path: string, passphrase?: string): Promise<void>;
  sign(message: Uint8Array): Promise<Uint8Array>;
  static verify(sig: Uint8Array, msg: Uint8Array, pubKey: Uint8Array): Promise<boolean>;
  deriveSharedSecret(peerPublicKey: Uint8Array): Uint8Array;
  get publicKey(): Uint8Array;
  get fingerprint(): string;
}

Types

interface PeerInfo {
  hostId: string;
  fingerprint: string;
  address: string;
  port: number;
  status: 'online' | 'offline';
  latency?: number;
}

interface TransportMessage {
  type: string;
  payload: unknown;
  signature?: string;
  senderFingerprint?: string;
}

interface MeshSecurityConfig {
  discovery: { mode: 'open' | 'signed' | 'trusted-only' };
  transport: { encryption: 'none' | 'optional' | 'required'; tls: 'none' | 'self-signed' | 'ca-signed'; requireAuth: boolean };
  trust: { autoTrustFirst: boolean; requireManualApproval?: boolean; trustedFingerprints?: string[] };
}

CLI Commands

skillkit mesh init            # Initialize mesh network
skillkit mesh add <address>   # Add a host to mesh
skillkit mesh remove <id>     # Remove a host
skillkit mesh list            # List known hosts
skillkit mesh discover        # Discover hosts on LAN
skillkit mesh health          # Check host health
skillkit mesh status          # Show mesh status

# Security
skillkit mesh security init   # Setup encryption keys
skillkit mesh security status # Show security status
skillkit mesh peer trust <id> # Trust a peer
skillkit mesh peer revoke <id># Revoke peer trust
skillkit mesh peer list       # List trusted peers

Documentation

Full documentation: https://github.com/rohitg00/skillkit

License

Apache-2.0