Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

librats

Latest version: v3.0.7

Overview

Last scanned
29 Nov 2026
Published
29 Nov 2026
npm package Publisher: degitx
171 Stars
34 Forks
13 Versions
1.1K Downloads
C++ Repo language

Scan summary

librats was last scanned on 29 Nov 2026 at version 3.0.7. Risk score 0 of 100. High-severity rules fired.

  • Releases: 13 versions; the latest was published on 29 Nov 2026.
  • Findings: 2 rules fired in version 3.0.7 (1 high, 1 medium). The score describes this version only.
  • Downloads: 1,074 downloads.

Versions

13 versions published
Versions and the rules that fired in each
VersionPublishedStatus
3.0.7 LATEST 29 Nov 2026 2 rules fired
3.0.6 10 Nov 2026 2 rules fired
3.0.5 7 Nov 2026 2 rules fired
2.3.7 3 Sep 2026 Not shown
2.3.6 3 Sep 2026 Not shown

Rules fired in 3.0.7: 2

Findings

1 High 1 Medium

Findings for v3.0.7. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

Several suspicious behaviors form a known attack pattern

Several behaviors that are each common on their own, such as reading registry credentials, contacting a variable host or running shell commands, appear together in this package in a combination associated with attacks. The finding message lists the behaviors that were combined.

HIGH

Possible command injection in install-time code

MEDIUM
Checking access…

🔒 Create a free account to see all 2 findings with descriptions and instance counts

The score describes 3.0.7; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

librats for Node.js

npm license: MIT node: >=20

Peer-to-peer networking for Node.js. Your programs connect to each other directly, with no server in between, over encrypted connections. They find each other on the local network or across the internet, get through home routers, and exchange messages, JSON values and files.

You could build with it:

  • a chat or messenger with no server
  • an app whose copies on several computers keep each other in sync
  • a tool that finds other copies of itself on the local network
  • file sharing, or live audio and video between peers
  • a Node service that talks to apps built on librats in other languages: the same library exists for C++, C, Python, Java/Android, React Native and iOS

Things to know before you pick it:

  • The networking is native. Sockets, encryption and delivery run in C++ on their own threads, not on the event loop, so one node keeps thousands of peers connected and moves gigabits per second.
  • It runs in Node.js, not in the browser. It is a native addon, so it needs Node.js 20+ on Windows, Linux or macOS, and it is compiled when installed.
  • It speaks its own protocol. It uses the BitTorrent DHT to find peers, but it connects only to other librats programs, not to WebRTC, libp2p or BitTorrent clients.

Documentation

  • This page is the guide: installation, the concepts, and every feature with an example.
  • index.d.ts is the full API reference, every method and option with its default. The types ship with the package, so your editor shows the same text on hover.
  • Examples: runnable scripts, a chat, pub/sub, file transfer.
  • librats.com and the main README describe the library as a whole, how it works inside, and the other languages.
  • Questions and bugs: GitHub issues.

On this page:

  • Installation
  • Hello, world and a first real node
  • Example: a chat with no server
  • Connecting to peers and who can connect
  • Sending messages, including bulk and live audio/video
  • More features: JSON, pub/sub, file transfer, NAT traversal, reconnection
  • Configuration, lifecycle, errors, logging

Installation

npm install librats

There is no prebuilt binary yet: installing compiles the C++ library and the addon, which takes a few minutes the first time. You need:

  • Node.js 20 or newer
  • CMake 3.14 or newer
  • Python 3, which node-gyp runs on
  • a C++17 compiler: Visual Studio Build Tools 2017+ on Windows (the "Desktop development with C++" workload), build-essential on Linux, Xcode Command Line Tools on macOS

If the install fails, it is almost always one of these missing or not on the PATH; INSTALLATION.md goes through the build step by step. The hello world below is a quick check that the install worked.

The package is CommonJS and works from ES modules and TypeScript too:

const { RatsNode } = require('librats');         // CommonJS
import { RatsNode, setLogLevel } from 'librats'; // ES module or TypeScript

Hello, world

Two nodes in one script, so it runs on one machine with nothing else to set up:

const { RatsNode, setLogLevel } = require('librats');

setLogLevel('warn');   // librats logs its startup at 'info'; keep the output short

const alice = new RatsNode();
const bob = new RatsNode();

bob.on('greeting', (peerId, data) => {
  console.log(`bob got "${data}" from ${peerId.slice(0, 8)}…`);
  alice.destroy();     // a node keeps the process running until it is destroyed
  bob.destroy();
});

alice.onPeerConnected((peerId) => {
  console.log(`alice is connected to ${peerId.slice(0, 8)}…`);
  alice.send(peerId, 'greeting', 'hello, bob');
});

alice.start();
bob.start();
alice.connect('127.0.0.1', bob.listenPort);
alice is connected to de975867…
bob got "hello, bob" from bafc5b54…

What happened: each node got a peer id, a long hex string that is its identity. start() opened a port, picked by the system because none was given. Alice dialed Bob's port; the two exchanged keys, and once each knew who the other is, onPeerConnected fired. Alice then sent a message on a channel named 'greeting', and Bob's handler for that channel received it.

In a real app each node is a separate program, usually on its own computer, and the nodes find each other by themselves instead of being told an address.

A first real node

const { RatsNode } = require('librats');

const node = new RatsNode({ listenPort: 8080, dataDir: './state' });

node.onPeerConnected((peerId) => node.send(peerId, 'chat', 'hello'));
node.on('chat', (peerId, data) => console.log(peerId, data.toString()));
node.enableMdns();   // find other nodes on the local network

node.start();
console.log('I am', node.localId, 'on port', node.listenPort);

Run this script on two computers in the same network. The nodes find each other, connect, and greet each other. To connect by hand instead, call node.connect('192.168.1.10', 8080) after start().

A few things to know from the start:

  • A node is identified by its peer id, a 64-character hex string. The id is the node's public key, so nobody else can claim it. Pass dataDir to keep the same identity across restarts; without it the node gets a new id every run.
  • protocol separates applications. It defaults to 'librats/1.0'. It is bound into the handshake, so nodes with different protocols cannot connect to each other, and the DHT only finds nodes with the same one. Give your app its own, such as 'my-app/1.0'. It is not a password, though: see who can connect.
  • Set the node up before start(). Features (enableMdns(), enableDht(), …) and the node's own handlers (on, onPeerConnected, …) can only be added before the node starts; afterwards they throw ALREADY_STARTED. JSON handlers and pub/sub subscriptions are the exception and can come and go at any time.
  • Handlers run on the JS thread. librats does its networking on its own threads and passes events to JavaScript through the event loop, so handlers are ordinary JS code. A busy JS thread does not slow the network down; events wait in a queue until it is free, and that queue grows meanwhile.
  • Destroy the node when you are done. While a node has handlers registered, it keeps the process alive, so the program does not end until you call destroy(). See lifecycle.

Example: a chat with no server

Everyone who runs this script with the same room name is in the same chat. Nodes on one network find each other over mDNS, and nodes elsewhere through the DHT. /connect dials someone directly.

const readline = require('readline');
const { RatsNode, setLogLevel } = require('librats');

const [name = 'anon', room = 'lobby', port = '0'] = process.argv.slice(2);
setLogLevel('error');    // library logs would interleave with the chat

// The protocol is bound into the handshake: only nodes in the same room can
// connect, and the DHT, which searches by protocol, looks for exactly them.
const node = new RatsNode({ protocol: `rats-chat/${room}`, listenPort: Number(port) });

node.enableMdns();       // the local network
node.enableDht();        // the internet
node.enableJson();       // messages are { name, text } objects

const short = (peerId) => peerId.slice(0, 8);

node.onPeerConnected((peerId) => print(`* ${short(peerId)} joined`));
node.onPeerDisconnected((peerId, reason) => print(`* ${short(peerId)} left (${reason})`));
node.onJson('say', (peerId, msg) => {
  // Anything can arrive from a peer, so check the shape before using it.
  if (typeof msg?.text !== 'string') return;
  print(`${String(msg.name).slice(0, 32)}: ${msg.text}`);
});

node.start();
console.log(`room "${room}", port ${node.listenPort}, id ${short(node.localId)}`);
console.log('/connect <host> <port>, /peers, /quit\n');

const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.setPrompt('> ');
rl.prompt();

rl.on('line', (line) => {
  const [command, ...args] = line.trim().split(/\s+/);
  try {
    if (command === '/connect') node.connect(args[0], Number(args[1]));
    else if (command === '/peers') console.log(node.peerIds.map(short).join(' ') || 'nobody yet');
    else if (command === '/quit') return rl.close();
    else if (line.trim()) node.broadcastJson('say', { name, text: line.trim() });
  } catch (err) {
    console.log(`! ${err.message}`);
  }
  rl.prompt();
});

// Ctrl+C or Ctrl+D. The node's callbacks keep the process alive, so destroy it.
let closed = false;
rl.on('SIGINT', () => rl.close());
rl.on('close', () => {
  closed = true;
  node.destroy();
});

// Print over the prompt line without mangling what is being typed.
function print(text) {
  if (closed) return;   // a last event can arrive while the node is being destroyed
  readline.clearLine(process.stdout, 0);
  readline.cursorTo(process.stdout, 0);
  console.log(text);
  rl.prompt(true);
}

To try it, save it as chat.js in a project where librats is installed, and run it in two terminals, on one computer or on two in the same network:

node chat.js alice
node chat.js bob
room "lobby", port 50113, id 850568e0       room "lobby", port 64991, id f7e5a523
/connect <host> <port>, /peers, /quit       /connect <host> <port>, /peers, /quit

* f7e5a523 joined                           * 850568e0 joined
> bob: hello from bob                       > hello from bob
> привет 👋                                 alice: привет 👋

What happens and where the limits are:

  • On the same network the nodes find each other by themselves, over mDNS, usually within a few seconds. Where multicast does not get through (some guest Wi-Fi, VPNs), /connect <host> <port> dials directly; the port is the one the script prints at start.
  • Through the internet, the DHT needs time and a reachable node. A new node first joins the DHT, then announces itself and searches every 30 seconds, so finding each other takes from tens of seconds to a few minutes. Then one side has to accept the connection: a public address, a forwarded port, or a router that agrees to forward one (node.enablePortMapping() asks it over UPnP and NAT-PMP). Two nodes behind NAT with nobody in common to help them cannot connect, as described in NAT traversal.
  • There is no history. A message reaches whoever is connected at the moment. broadcastJson sends it to every connected peer and the peers do not pass it on, so a large room needs every member connected to every other. examples/gossipsub_chat.js is the same chat over pub/sub, where messages also spread through intermediate peers.

Connecting to peers

node.connect('example.com', 8080);   // a name or an IP address
node.disconnect(peerId);             // false if it was not connected

node.peerCount;                      // how many peers are connected
node.peerIds;                        // their ids
node.peerInfo(peerId);               // { transport, direction, address, transports }, or null
node.maxPeers = 50;                  // cap on peers, enforced on inbound; 0 is no cap

connect() returns immediately. A connection that succeeds arrives as onPeerConnected. One that fails arrives as onDialFailed, but only for an IP address: a dial by host name fails silently. onPeerDisconnected reports why a peer left as a string: 'peer-closed', 'idle-timeout', 'slow-consumer', and so on (see CloseReason in index.d.ts).

Each node listens on one port over both UDP and TCP. A dial tries UDP first and also tries TCP if UDP does not succeed within 1.2 seconds. peerInfo(id).transport shows which one was used.

What the node knows about itself: node.localId, node.listenPort (the real port when 0 was asked for), node.observedAddresses (its own addresses as connected peers see them, which is how a node behind NAT learns its public address) and node.natMapping (see NAT traversal).

There are three ways for nodes to find each other without knowing an address, and they can be combined:

How it finds peers
enableMdns() multicast on the local network
enableDht(port?, discoveryKey?) the BitTorrent mainline DHT, worldwide. By default it looks for nodes with the same protocol; dhtSetKeys([...]) replaces the keys at any time, also while running
enablePeerExchange() connected peers tell each other about the peers they hold, so one contact is enough to find the rest
Who can connect

Every connection is encrypted and authenticated with the Noise protocol. When onPeerConnected reports a peer id, the other side has proved it holds that id's private key, and nobody in between can read or change the traffic.

What librats does not decide is whether you want that peer. Any node with the same protocol string can connect to yours, and the string is not secret: it is in your app, and the DHT lookup is derived from it. If only certain peers may talk to your node, keep a list of the ids you trust, which stay fixed when the peers use dataDir, and drop everyone else:

const trusted = new Set(['3f2a…', '9c41…']);   // full 64-character ids
node.onPeerConnected((peerId) => {
  if (!trusted.has(peerId)) node.disconnect(peerId);
});

The same goes for what peers send: a handler gets whatever bytes the peer chose to send, so check them before using them.

Sending messages

Messages travel on named channels: a name you choose, such as 'chat' or 'state'. You send a string or a Buffer, and the handler always gets a Buffer.

node.on('state', (peerId, data) => apply(JSON.parse(data)));

node.send(peerId, 'state', JSON.stringify(state));   // one peer; throws NO_SUCH_PEER if not connected
node.broadcast('state', JSON.stringify(state));      // every connected peer

What a channel guarantees:

  • Reliable and in order. Everything a node sends to a peer arrives in the order it was sent, across all channels (live messages aside).
  • Only while the connection lasts. If the peer disconnects, what was still queued for it is lost. There is no store-and-forward: a peer that is offline does not get the message later.
  • Up to almost 64 MiB per message. A larger message is not delivered: send() still returns, and a warning in the log says it was refused. Split big data into pieces, or use file transfer.
  • Only to a peer that listens. A message on a channel the receiver has no handler for is dropped silently.

Channel names are hashed to 16-bit ids on the wire. Two different names can in principle get the same id; if two of the names your node listens on do, a warning is logged when the second handler is registered.

When you send a lot

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm librats

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Vulnerability Insights

OpenSSH Password Authentication Bypass on Alpine Linux (*sshole) – CVE-2026-123158

PolinRider Returns
Research

PolinRider Returns: Hijacked npm Packages Use Ethereum Blockchain to Conceal Malware Infrastructure

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Frame 2085668439 (1)
Group 1261154229