webhook-over-websocket

command module
v1.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

webhook-over-websocket

Release Go Version License

日本語

A tunnel tool that forwards external webhook requests to a local development server via WebSocket.

Overview

webhook-over-websocket allows you to receive webhooks from external services (e.g. GitHub, Stripe, Slack) on your local development machine without exposing it to the internet directly. It works by establishing a persistent WebSocket connection between a publicly accessible server and the client running locally.

flowchart TD
    A[External Service] -- HTTP --> B["Server<br>/webhook/{channel_id}"]
    B <-->|WebSocket| C["Client<br>(local machine)"]
    C -- HTTP --> D["Local application<br>(e.g. http://localhost:3000)"]

Architecture

Component Role
Server Publicly accessible HTTP server. Receives webhooks and forwards them over WebSocket to the connected client. Also exposes a Traefik HTTP Provider endpoint for dynamic routing when running at scale.
Client Runs on the local machine. Connects to the server via WebSocket, receives webhook payloads, and forwards them to the local application.
Server Endpoints
Endpoint Description
GET /new Issues a new channel_id (UUID) for a client to use. ?channel_id= requests a specific ID (1–128 characters of A-Z a-z 0-9 . _ -)
GET /traefik-config Returns dynamic Traefik routing configuration (HTTP Provider). Memberlist backend only
GET /internal/channels Returns active channel list (used for peer-to-peer sync in multi-replica deployments). Memberlist backend only
GET /ws/{channel_id} WebSocket upgrade endpoint for client connections
ANY /webhook/{channel_id}[/...] Receives external webhook requests (any HTTP method) and tunnels them to the client
GET /auth/login (auth mode only) Redirects to the GitHub OAuth consent page
GET /auth/callback (auth mode only) GitHub OAuth callback; returns a session JWT

Installation

Docker
docker pull ghcr.io/nonchan7720/webhook-over-websocket:latest
Go install
go install github.com/nonchan7720/webhook-over-websocket@latest
Binary download

Download the latest binary for your platform from the Releases page.

Usage

1. Start the server

Run the server on a publicly accessible host:

webhook-over-websocket server --port 8080

Or with Docker:

docker run --rm -p 8080:8080 ghcr.io/nonchan7720/webhook-over-websocket:latest server --port 8080

Server flags:

Flag Default Description
--port, -p 8080 Port to listen on
--cleanup-duration 5m Interval for cleaning up inactive channel sessions
--webhook-max-body-size 10485760 Maximum size of a webhook request body in bytes (larger requests receive 413)
--cluster-backend memberlist How replicas share state: memberlist or redis (see Clustering and High Availability)
--peer-domain (empty) (memberlist) Peer domain name for memberlist cluster discovery
--memberlist-port 7946 (memberlist) Port for memberlist gossip protocol
--memberlist-sync-duration 5s (memberlist) Interval for memberlist cluster synchronization
--redis-url (empty) (redis) Redis URL, e.g. redis://[user:password@]host:6379/0 or rediss://... for TLS (required with --cluster-backend redis)
--redis-key-prefix webhook-over-websocket (redis) Prefix of the Redis keys and Pub/Sub channels
--redis-heartbeat-duration 5s (redis) Interval for refreshing the ownership of connected channels
--redis-cluster-mode false (redis) Connect using the Redis Cluster protocol
--redis-tls-ca-file (empty) (redis) CA certificate file to verify the Redis server (enables TLS)
--redis-tls-insecure-skip-verify false (redis) Skip verifying the Redis server certificate (enables TLS; for testing only)
--github-client-id (empty) GitHub OAuth App client ID — enables authentication when set
--github-client-secret (empty) GitHub OAuth App client secret (required when --github-client-id is set)
--github-org (empty) Required GitHub organization — only members are allowed access
--jwt-signing-key (empty) Secret key for signing JWT tokens (required when --github-client-id is set)
2. Start the client

Run the client on your local machine, pointing it at the server and your local application:

webhook-over-websocket client \
  --server-url http://your-server.example.com \
  --target-url http://localhost:3000

On startup, the client prints the webhook URL to configure in the external service:

Issued Channel ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Please set the webhook destination as follows: http://your-server.example.com/webhook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
A tunnel to the server has been established.

Client flags:

Flag Default Description
--server-url (required) URL of the webhook-over-websocket server
--target-url http://localhost:3000 URL of the local application to forward webhook requests to
--insecure false Skip TLS certificate verification
--channel-id (empty) Channel ID to use instead of a random one (1–128 characters of A-Z a-z 0-9 . _ -)
--machine-channel-id false Use a channel ID fixed for this machine, derived from the machine ID (cannot be used with --channel-id)
--channel-key (derived from the machine ID) Secret that lets this client issue the same channel again
Which channel ID to use

The webhook URL is <server>/webhook/<channel_id>, so the channel ID decides whether you have to update the webhook settings of the external service after restarting the client.

Use case Command Webhook URL after a restart
Try it out once (no option) Changes (a random ID is issued every time)
Develop on your machine and keep the URL registered in the external service --machine-channel-id Stays the same
Run several local applications on one machine --channel-id app-a, --channel-id app-b, ... Stays the same
Run the client where the machine ID is not available or changes (e.g. containers) --channel-id <id> --channel-key <secret> Stays the same
# Develop on your machine: register the printed webhook URL once, then restart the client freely.
webhook-over-websocket client \
  --server-url http://your-server.example.com \
  --target-url http://localhost:3000 \
  --machine-channel-id

How the channel stays yours without logging in: The client sends a secret derived from the OS machine ID (the X-Channel-Key header), and the server binds the channel to it when authentication is disabled. A client with the same secret, that is, the same machine, can issue the channel again right after a restart; other clients get 409 from /new and 403 from /ws. With authentication enabled, the channel is bound to the logged-in user instead.

Notes:

  • Anyone who knows the webhook URL can send requests to it. --machine-channel-id derives an ID that cannot be guessed; do not use guessable values such as MAC addresses or host names with --channel-id.
  • --machine-channel-id gives the same ID to every client on the machine. Use --channel-id to run several clients at once.
  • Use the same --channel-key on every run (keep it secret); a different key cannot take over the channel.
  • If the client disappears without closing the connection (e.g. the network is cut), the server may keep the previous connection for up to 60 seconds, and the client cannot connect until then.
3. Configure the external service

Set the webhook URL in the external service (e.g. GitHub, Stripe) to:

http://your-server.example.com/webhook/<channel_id>

Any path suffix after the channel ID is preserved and forwarded to your local application as-is. Any HTTP method (GET, POST, PUT, PATCH, DELETE, etc.) is likewise forwarded unchanged, ngrok-like.

Authentication

When the server is configured with a GitHub OAuth App, only authenticated users can obtain channel_ids and connect via WebSocket. Two levels of access control are supported:

  1. Organization check – only members of a specific GitHub organization may authenticate (enabled via --github-org).
  2. Per-channel token – every channel_id is bound to a signed JWT whose sub (subject) claim equals the channel_id, so a token issued for one channel cannot be used for another.
Setup
  1. Create a GitHub OAuth App and set the callback URL to http://your-server.example.com/auth/callback.
  2. Start the server with the auth flags:
webhook-over-websocket server \
  --port 8080 \
  --github-client-id  <YOUR_CLIENT_ID> \
  --github-client-secret <YOUR_CLIENT_SECRET> \
  --github-org my-organization \
  --jwt-signing-key  <A_LONG_RANDOM_STRING>
New server endpoints (auth mode only)
Endpoint Description
GET /auth/github Redirects the user to the GitHub OAuth consent page
GET /auth/callback GitHub calls this after the user approves; returns the session JWT
Variable Description
POD_IP Pod IP address used as the server's own IP (Kubernetes). When set to a valid IPv4 address, it is used instead of auto-detection.

Clustering and High Availability

Traefik Integration with Memberlist

For production deployments with multiple server replicas (e.g. in Kubernetes), Traefik is used as a load balancer with dynamic routing so that webhook requests are always forwarded to the replica that holds the correct WebSocket connection.

Challenge: Traefik's HTTP Provider can only poll a single endpoint URL for configuration updates. In a multi-replica deployment, this creates a problem: how can a single endpoint return routing information for channels connected to different replicas?

Solution: HashiCorp Memberlist enables cluster coordination via a gossip-based membership protocol. When Traefik polls any single replica's /traefik-config endpoint, that replica automatically aggregates channel information from all cluster members and returns the complete routing configuration.

How it works:

  1. Each server instance joins the memberlist cluster using the --peer-domain flag for DNS-based peer discovery
  2. Servers periodically exchange information about their active channels via the gossip protocol
  3. When Traefik polls /traefik-config on any replica, that replica:
    • Collects its own active channels
    • Queries all other alive cluster members via /internal/channels
    • Aggregates all channel information and generates the complete Traefik routing configuration
  4. Inactive or failed nodes are automatically detected and removed from the cluster

Configuration example:

Server:

webhook-over-websocket server \
  --port 8080 \
  --peer-domain webhook-service.default.svc.cluster.local \
  --memberlist-port 7946 \
  --memberlist-sync-duration 5s

Traefik static configuration:

providers:
  http:
    endpoint: "http://webhook-over-websocket-service/traefik-config"
    pollInterval: "5s"

With this setup, Traefik can query any single replica (via the Kubernetes service), and that replica will return routing information for all channels across the entire cluster.

Redis Pub/Sub

The memberlist backend requires that the replicas can reach each other directly (gossip and /internal/channels) and that Traefik can route to every replica. When that is not possible — for example, replicas running in multiple clusters in an active-active setup — use the Redis backend instead. All traffic between replicas then goes through Redis, and neither Traefik nor memberlist is needed: a plain load balancer can send any request to any replica.

How it works:

  1. GET /new registers the issued channel in Redis, so /ws/{channel_id} can be accepted by any replica.
  2. The replica that accepts the WebSocket registers itself as the owner of the channel and keeps the ownership alive with a heartbeat (--redis-heartbeat-duration). The registration is removed when the client disconnects.
  3. When a webhook arrives at a replica that does not hold the WebSocket, the request is published to the owner's channel in Redis. The owner sends it to the client, and the response (headers, body chunks and EOF) is published back and streamed to the caller.
  4. Authentication results (/auth/callback) are broadcast to all replicas through Redis as well.

Messages between replicas use a compact binary format, and payloads larger than 1 KiB are compressed with zstd when it makes them smaller. This keeps the Pub/Sub output buffers in Redis small.

Configuration example:

# Pass the URL through the environment so that the password does not appear in the process list.
export WOW_REDIS_URL=rediss://user:password@redis.example.com:6379/0
webhook-over-websocket server \
  --port 8080 \
  --cluster-backend redis
  • Use rediss:// (or --redis-tls-ca-file) for TLS. Managed Redis services with in-transit encryption work with rediss:// as is.
  • Use --redis-cluster-mode when Redis runs in cluster mode.
  • /traefik-config and /internal/channels are not served with the Redis backend.

Security: Redis is a trust boundary. Messages between replicas are neither signed nor encrypted by the application, so anyone who can subscribe or publish to these channels can read the relayed webhooks and the session tokens of /auth/callback, and can inject requests to the connected clients.

  • Use a dedicated Redis, or a Redis ACL user limited to the prefix (~<prefix>:* &<prefix>:*) and the commands in use.
  • Use rediss:// to encrypt the traffic.
  • Give each environment sharing a Redis (e.g. production and staging) its own --redis-key-prefix; environments with the same prefix interfere with each other. All replicas of one environment, including the old and new versions during a rolling update and replicas in other clusters, must use the same prefix.
  • A relayed webhook is as large as its request body (up to --webhook-max-body-size). Keep the Pub/Sub client-output-buffer-limit of Redis well above it, or Redis disconnects the subscriber of the replica, which drops the messages to all of its channels until it resubscribes.

Limitations: Redis Pub/Sub delivers messages at most once. If the replica holding the WebSocket goes away while a webhook is in flight, the caller receives 504 Gateway Timeout.

Development

Tooling with mise

Go and golangci-lint are declared in mise.toml, so mise installs the same versions CI uses:

mise install
make test   # go test -race ./...
make lint   # golangci-lint run ./...
make e2e    # end-to-end tests (tests/e2e) with the Postman CLI, for both the memberlist and Redis backends

CI (.github/workflows/test.yaml) sets up the tools from mise.toml as well, so bumping a version there updates both local and CI environments. Claude Code on the web runs scripts/mise-setup.sh on session start to install them.

Docker Compose

The repository also includes a Docker Compose file for local development:

docker compose up -d

This mounts the repository source into the container so you can edit files locally.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
cmd
tests
e2e/target command
Command target is the local HTTP server that the E2E tests (tests/e2e/run.sh) forward webhooks to through the `client` subcommand.
Command target is the local HTTP server that the E2E tests (tests/e2e/run.sh) forward webhooks to through the `client` subcommand.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL