Scan your whole stack
From OX Research Newsroom
Are you using librats?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v3.0.7
librats was last scanned on 29 Nov 2026 at version 3.0.7. Risk score 0 of 100. High-severity rules fired.
| Version | Published | Status |
|---|---|---|
| 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 |
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 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.
HIGHThe score describes 3.0.7; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
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:
Things to know before you pick it:
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.On this page:
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:
build-essential on Linux, Xcode Command
Line Tools on macOSIf 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
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.
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:
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.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.destroy(). See lifecycle.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:
/connect <host> <port> dials directly; the port is the
one the script prints at start.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.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.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 |
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.
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:
send() still returns, and a warning in the log says it was refused. Split
big data into pieces, or use file transfer.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.
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.
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).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.