Files
web-terminal/agent/test/security/tripwires.test.ts
Yaojia Wang 2af57e6686 feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)
Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.

Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
  capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay:   native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent:        host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e:    browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth:   Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web:    browser login + Web Crypto E2E + client-side preview rendering

Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.

NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
2026-07-02 06:10:16 +02:00

60 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { join } from 'node:path'
const SRC = join(import.meta.dirname, '..', '..', 'src')
function walk(dir: string): string[] {
const out: string[] = []
for (const name of readdirSync(dir)) {
const path = join(dir, name)
if (statSync(path).isDirectory()) out.push(...walk(path))
else if (name.endsWith('.ts')) out.push(path)
}
return out
}
const files = walk(SRC)
function code(path: string): string {
return readFileSync(path, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '')
}
describe('agent security tripwires (T18, INDEX §3)', () => {
it('INV9: no console.log anywhere in src', () => {
for (const f of files) {
expect(code(f), `console.log in ${f}`).not.toMatch(/console\.log/)
}
})
it('INV11: no ANSI/xterm/vt100 import anywhere in src (byte-shuttle)', () => {
for (const f of files) {
expect(code(f), `terminal-parser import in ${f}`).not.toMatch(/from ['"][^'"]*(xterm|ansi|vt100)[^'"]*['"]/)
}
})
it('INV2 anti-MITM: hostEndpoint imports NO verifier from relay-e2e (FIX 6b)', () => {
const he = code(join(SRC, 'e2e', 'hostEndpoint.ts'))
expect(he).not.toMatch(/from ['"]relay-e2e['"]/)
expect(he).not.toMatch(/verifyDeviceAuthProof/)
})
it('INV12: revocation.ts uses the frozen decoder, no bare integer reason literal', () => {
const rev = code(join(SRC, 'lifecycle', 'revocation.ts'))
expect(rev).toMatch(/decodeGoAwayReason/)
expect(rev).not.toMatch(/reason\s*[=:]\s*\d/)
expect(rev).not.toMatch(/===\s*[123]\b/)
})
it('INV4: identity exposes no raw private-key byte export', () => {
const id = code(join(SRC, 'keys', 'identity.ts'))
expect(id).not.toMatch(/exportPrivateRaw|privateKeyBytes|rawPrivateKey/)
})
it('every src module is well under the 800-line hard cap', () => {
for (const f of files) {
const lines = readFileSync(f, 'utf8').split('\n').length
expect(lines, `${f} is ${lines} lines`).toBeLessThan(800)
}
})
})