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

@zukhruf/election

Latest version: v0.8.266

Overview

Last scanned
30 Nov 2026
Published
30 Nov 2026
npm package Publisher: ezzabuzaid
2 Stars
0 Forks
326 Versions
62.0K Downloads
TypeScript Repo language

Scan summary

@zukhruf/election was last scanned on 30 Nov 2026 at version 0.8.266. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 326 versions; the latest 5 were published on 30 Nov 2026.
  • Findings: No rules fired in version 0.8.266.
  • Downloads: 62,038 downloads.

Versions

326 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.8.266 LATEST 30 Nov 2026 No rules fired
0.8.265 30 Nov 2026 No rules fired
0.8.264 30 Nov 2026 No rules fired
0.8.263 30 Nov 2026 Not shown
0.8.262 30 Nov 2026 Not shown

No rules fired in 0.8.266

Findings

Findings for v0.8.266. 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.

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

README

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

@zukhruf/election

Candidates campaign for one claim, and the candidate that wins it leads for one term. Each term has an epoch that is higher than the epoch of each earlier term, so a newer leader always outranks an older one. A term is a lease on leadership. It ends when the leader resigns or its process dies. With a backend that can take the claim away, a term can also be lost while the leader still runs, and the signal of the term tells its leader so.

The words in these documents have one meaning each. See the glossary in CONTEXT.md.

Use it

This project is an experiment.

npm install @zukhruf/election

Elect a leader of one host

SqliteElection elects one leader among the processes of one host that use the same directory. The claim is the FileLock of @zukhruf/fs on claimFile: an exclusive SQLite transaction. The operating system holds that lock until the leader's process dies, so a dead leader frees the claim at once, and a living leader never loses it.

import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

import { SqliteElection } from '@zukhruf/election';

const directory = await mkdtemp(join(tmpdir(), 'jobs-'));
const election = new SqliteElection({
  clock: globalThis,
  directory,
  claimFile: 'jobs.lock',
  epochFile: 'jobs.epoch',
});

const first = await election.campaign();
console.log('first term:', first?.epoch);
console.log('a second candidate wins:', await election.campaign());

await first?.resign();
await using second = await election.campaign({ timeout: 1000 });
console.log('next term:', second?.epoch);
await rm(directory, { recursive: true, force: true });

Output:

first term: 1n
a second candidate wins: undefined
next term: 2n
  • campaign({ timeout, signal }) resolves with a Term, or with undefined when another candidate still leads after timeout milliseconds. Without a timeout, it tries once. With timeout: Infinity, it waits until it wins or signal aborts. When signal aborts, it rejects with signal.reason, and a claim that it won meanwhile is given up.
  • claimFile and epochFile are files in directory. Candidates with the same directory and the same file names are one group. Never delete claimFile while candidates run: a new file lets a second leader win.
  • election.name is the path of claimFile: join(directory, claimFile). Two elections with the same name are one election. A warning names the election by its name (ADR 0010).
  • Each epoch of a SqliteElection is below 2^31, so EpochTokenSource of @zukhruf/fencing takes it. When epochFile holds 2^31 - 1, the next epoch would be 2^31: then campaign rejects with a RangeError that names the file, gives the claim up, and does not change the file (ADR 0011).
  • epochFile holds the epoch of the last term as decimal digits. When it holds other text, campaign rejects with a SyntaxError that names the file, gives the claim up, and does not change the file. An example is the empty file that @zukhruf/mutex 0.2.0 or earlier can leave after a power loss, because those versions did not sync the file to the disk. Thus the epochs never start again at 1, and each new term has a higher epoch than each earlier term.
  • lastEpoch() resolves with the epoch of the last term in epochFile, or with 0n when no term was won yet. It only reads the file. It does not campaign, it does not take the claim, and it does not create a file or the directory. Use it to find out if a value from an earlier term is stale, for example a fencing token that an old leader made with EpochTokenSource. A new term can start immediately after the read, so the answer can be old when you get it. When epochFile holds text that is not decimal digits, lastEpoch() rejects with the same SyntaxError as campaign. When it cannot read the file for another reason, it rejects with that error. It never answers 0n for a file that it cannot read.
  • A term that resigns clean writes a third file, <claimFile>.clean, beside claimFile. It holds the epoch of that term. The next term reads it and removes it.
  • The directory must be on a local file system. On a network file system, campaign rejects with NetworkDirectoryError.
  • A try never blocks the process. Between two tries, a candidate waits on pushes from the leader, not on a period (A leader that hangs).
  • clock is the clock that the campaign waits on, and that measures its timeout, the heartbeats of a leader and the deadline of a reader. It is required. Give globalThis in production. A test gives a fake clock, for example createClock() of @sinonjs/fake-timers, and moves the time of the campaign without a real wait (@zukhruf/async).
  • To run a job each time this process leads, and to campaign again after each term, use a LeaderSelector. It resigns the term when the job ends, and its dispose waits for the job (Run a task each time this process leads).

A leader that hangs

A hung leader keeps the claim of SqliteElection: a leader that SIGSTOP stopped, or a leader whose event loop is blocked. The kernel frees the claim only when the process ends. Thus the leader pushes a heartbeat on a pipe, a candidate waits on that pipe, and a candidate ends a leader that is silent for too long. A candidate waits as etcd's Campaign and ZooKeeper's leader election recipe wait: on a push, not on a period (ADR 0007).

const election = new SqliteElection({
  clock: globalThis,
  directory,
  claimFile: 'jobs.lock',
  epochFile: 'jobs.epoch',
  leaseDuration: 15_000, // the default
  heartbeatInterval: 5_000, // the default: a third of leaseDuration
});

await using term = await election.campaign({ timeout: Infinity, signal });
  • The pipe. The winner of a claim serves a pipe of @zukhruf/pipes for its term. It sends a heartbeat on each connection when it accepts it, and then every heartbeatInterval until the term closes, also when a subclass overrides watch (ADR 0004).
  • The leader record. The winner writes <claimFile>.leader beside claimFile, before its term begins. It holds the epoch of the term, the process id of the leader, the address of its pipe, and its leaseDuration. The winner first removes the socket file of the pipe that the old record names, which a killed leader leaves (ADR 0005).
  • The wait. A candidate tries the claim. When another candidate holds it, the candidate reads the record, connects to the pipe, and waits. The close of the pipe tells it that the leader left, and it tries at once. A candidate under a healthy leader makes no try (ADR 0007).
  • A hung leader. A candidate that hears no heartbeat for the leaseDuration of the record sends SIGKILL to the process of the record, but only while it holds that process's pipe open. The kernel frees the claim and closes the pipe, and the candidate tries. The kernel refuses the kill for a process of another user: then the candidate ends nothing, and it waits for the close until its timeout. A reader never ends its own process, in the same way (ADR 0006).
  • A pipe that a candidate cannot connect to. A connect that rejects with NoServerError of @zukhruf/pipes comes while a new leader starts, or under a published leader. On Linux it also comes when the leader closes its pipe during the connect (#5317). A connect that rejects with EAGAIN, on Linux when the listen queue of a hung leader's pipe is full, and one that rejects with EACCES, for a pipe of another user, come while a leader serves, but the candidate cannot hold a connection to its pipe (#5425). After each of them, the candidate waits a back-off and tries again: 25 ms first, then 1.6 times longer each time, with a jitter of ±20 %, at most 1000 ms.
  • An observer. election.observe() returns a LeaderObserver for a process that does not campaign. It holds a connection to the leader's pipe and ends a silent leader as a candidate does. observer.left resolves 'closed' when the leader left, 'ended' when the observer ended it, and 'absent' when it held no connection to a leader's pipe: no leader served one, the pipe was another user's, or its listen queue was full. It rejects with any other error. Dispose it to close the connection; then left does not settle. Its connection and its deadline do not keep the process alive. One observer reads one term (ADR 0009).
  • leaseDuration is the longest silence, in milliseconds, that a candidate or an observer accepts from the leader. It defaults to 15000, as the LeaseDuration of Kubernetes. A reader uses the value in the record, so the leader decides it.
  • heartbeatInterval is the time between two heartbeats, in milliseconds. It defaults to a third of leaseDuration, as etcd's client sends a keepalive every TTL / 3. The name is etcd's heartbeat-interval.
  • The constructor throws a RangeError unless 0 < heartbeatInterval < leaseDuration.
  • The pipe, its connections and the heartbeat timer of a leader do not keep its process alive. A waiting candidate keeps its process alive until the campaign ends.
  • Run the candidates of one group as one user, in one PID namespace, with one /tmp. A candidate that runs as root can end a leader of any user.
  • With SqliteElection, a hung leader never runs again after a takeover: a new term starts only after the old process ended. A leader that runs again before its deadline still leads, and its term.signal does not abort.

The term

A term is a lease on leadership. Term implements the Lease interface of @zukhruf/lease, so a function that takes a Lease also takes a term. See the glossary of leases.

  • term.epoch is the number of the term. It is higher than the epoch of each earlier term of the election. The epoch of a SqliteElection is below 2^31.
  • term.resign() ends the term and gives the claim up. A second call waits for the first, and its options do nothing. await using resigns at the end of its scope. When the release fails, the claim is still freed, and resign rejects with the release's error. When the release or the record of clean fails and freeing the claim fails too, resign rejects with a SuppressedError: its suppressed is that step's error, and its error is the failure to free. When both fail with one error, resign rejects with that error (ADR 0013). After a loss, resign never rejects, and the term still ends: a failure to stop watching the claim or to free it has no caller to go to, so it is a TermWarning (see Errors). When both fail, the warning's cause is a SuppressedError: its suppressed is the failure to stop watching, and its error is the failure to free. When both fail with one error, the cause is that error.
  • term.resign({ clean: true }) records a clean shutdown for the next term, and then ends the term. Use it only when the leader leaves nothing for the next term to recover, for example no work in progress. A lost term records nothing, also with clean. When the record fails, the claim is freed, and resign rejects with that error. The socket lock store of @zukhruf/mutex resigns clean when no process holds a key (its ADR 0018). @zukhruf/single-flight no longer records a clean shutdown, because its coordinator has no grace window to skip (its ADR 0010).
  • term.afterCleanShutdown is true only when the term just before this one resigned clean. Then the new leader knows that it has nothing to recover. It is false after a crash, after a lost term, after a resign without clean, and for the first term.
  • term.signal aborts with LeaseLostError when the term is lost while its leader still runs. The subject of the error is 'leadership', and its cause is the reason of the backend. The signal does not abort when the leader resigns.

A leader that acts for the group must stop when term.signal aborts, because another candidate can lead then. SqliteElection never loses a living term, so its signal never aborts. A backend that can take the claim away can lose one.

A term has no fencing token. The signal warns the leader, but it does not protect a resource: a leader can write after another candidate won. To protect a resource, make fencing tokens from the epoch with EpochTokenSource of @zukhruf/fencing. It takes an epoch below 2^31, as each epoch of SqliteElection is, and throws a RangeError for a higher one. Then a resource can refuse the writes of an older leader:

import { EpochTokenSource } from '@zukhruf/fencing';

const tokens = new EpochTokenSource(term.epoch);
const token = await tokens.next('orders');

ADR 0002 tells why.

Run a task each time this process leads

Some work must run in only one process of a group, for the whole life of each process: a writer of a warehouse, a cleanup, a poll of a queue. LeaderSelector.start(election, listener, options) campaigns with no time limit, runs listener.takeLeadership(term, signal) while the term lasts, and resigns the term when the task ends. With autoRequeue, it campaigns again, until its dispose. It is Apache Curator's LeaderSelector, over a LeaderElection as client-go's LeaderElector is over a resourcelock.Interface (ADR 0011).

import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { setTimeout as delay } from 'node:timers/promises';

import { Backoff } from '@zukhruf/async';
import {
  LeaderSelector,
  type LeaderSelectorListener,
  SqliteElection,
} from '@zukhruf/election';

const directory = await mkdtemp(join(tmpdir(), 'writer-'));
const election = () =>
  new SqliteElection({
    clock: globalThis,
    directory,
    claimFile: 'writer.lock',
    epochFile: 'writer.epoch',
  });
const autoRequeue = {
  backoff: new Backoff({
    initial: 1_000,
    multiplier: 2,
    max: 60_000,
    jitter: { kind: 'full' },
  }),
  clock: globalThis,
};
const writer = (name: string): LeaderSelectorListener => ({
  takeLeadership: async (term, signal) => {
    console.log(`${name} leads in term ${term.epoch}`);
    // Write until the selector stops the task: a dispose, an interrupt or a loss.
    while (!signal.aborted) await delay(100);
    console.log(`${name} resigns`);
  },
});

const first = LeaderSelector.start(election(), writer('first'), {
  autoRequeue,
});
await delay(150);
const second = LeaderSelector.start(election(), writer('second'), {
  autoRequeue,
});
await delay(150);
await first[Symbol.asyncDispose](); // The standby leads at once.
await delay(150);
await second[Symbol.asyncDispose]();
await rm(directory, { recursive: true, force: true });

Output:

first leads in term 1
first resigns
second leads in term 2
second resigns

The signal of the task aborts at the dispose, at interruptLeadership(), and when the term is lost. Return, or reject with signal.reason, to give the leadership up. After each round:

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 @zukhruf/election

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

Copy of Template Design OX Blog (3)
Research

Ruby2Shell: Ruby Memory Corruption Flaws Expose Applications to Remote Code Execution, But is it an Actual Risk?

Vulnerability Insights

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

Copy of Template Design OX Blog (1)
Research

Thousands Of GitHub Accounts Hijacked With wfx-loot CI Secret Stealing Malware Via GitHub Actions & npm

Frame 2085668439 (1)
Group 1261154229