node2shell

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 8 Imported by: 1 module, 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.

Documentation

Overview

Package node2shell holds what the Brotli request-decoding exposure probe and the node2shell decoder-version probe share about CVE-2026-111497: the tiny Brotli control streams both send, the advisory references, and the heuristic that names the component which probably decoded the body.

The two modules ask different halves of one question. The exposure probe asks whether anything on the request path decodes a Brotli request body at all — surface, no version. The node2shell probe asks whether that decoder predates the fix, and pays 22 MiB of upload to find out. They must agree on where the decoder is, so the differential's streams live here rather than in either module.

Index

Constants

View Source
const (
	// UnknownEncoding is the control encoding. A server that drops or ignores
	// the body of any encoded request answers it like the decoded Brotli probe.
	UnknownEncoding = "x-vigolium"
	// DecoyHeader is a header no server reads. It carries a random value to show
	// odd headers alone do not move the answer, and the encoding name to show
	// decoding is tied to Content-Encoding rather than to any header.
	DecoyHeader = "X-Vigolium-Encoding"
	// ConfirmRounds is how many times the encoded pair must be answered like the
	// plain pair before the gate opens.
	ConfirmRounds = 2
	// ContentEncoding is the header the gate varies.
	ContentEncoding = "Content-Encoding"
)
View Source
const (
	LaneHost  = "app-wide parser or proxy"
	LaneRoute = "route body parser"
)

Lane names where a decoder was found, for the reader and for Metadata.

View Source
const (
	// BrotliEncoding is the plain Brotli coding, and the only one the
	// node2shell probe can be delivered under. Declared once here so the
	// string is not spelled independently by Encodings, BrotliOnly and the
	// module that checks it.
	BrotliEncoding = "br"
	// StackedEncoding is tried when plain br is refused: a guard that checks
	// only the first token lets it through to a decoder that handles both.
	StackedEncoding = "gzip, " + BrotliEncoding
)
View Source
const (

	// ProbeReps is the repetition count the oracle depends on.
	ProbeReps = (1 << 21) - 1
	// TwinReps is one repetition past the wrap. The resulting stream is
	// malformed for EVERY decoder, affected or fixed — see TwinStream.
	TwinReps = 1 << 21
)

The streams below are the Assetnote node2shell-scanner's probe, byte for byte (scanner.py: PROBE_PREFIX / PROBE_UNIT / PROBE_SUFFIX).

The stream is a Brotli document that repeats an 11-byte block-switch unit exactly 2^21-1 times. That count is the whole trick: it drives a counter in an affected decoder to the point where it wraps, and the stream is built so that a decoder which wraps lands back on a valid state and emits "{}" followed by 64 spaces — a 66-byte valid JSON document. A decoder with the fix refuses the same bytes.

So the probe is a VERSION oracle, not a crash: on an affected decoder the route answers as it would for a normal {} body, and on a patched one it answers as it would for a malformed body. Decoded output is 66 bytes, so there is no decompression bomb behind it, and no command is executed.

Verified against real libbrotli: 1.2.0 (pre-fix) decodes it to those 66 bytes, and one repetition fewer or more fails to decode at all. There is therefore no smaller probe — the 22 MiB is inherent to the oracle, not padding — which is why the module that sends it is tagged `intrusive` and spends it once per origin.

OPEN QUESTION, unresolved: whether an affected decoder performs the out-of-bounds WRITE while consuming this stream, or merely reaches the condition the fix now rejects. The Assetnote scanner's README says only that it "does not execute a command", which is a weaker claim than "writes nothing out of bounds", and a clean local decode does not settle it either. If it turns out the wrap IS the write, this probe corrupts memory in the target process on every run and the module should move behind risk:high (--intensity deep / --allow-risky-payloads) rather than shipping at the default intensity.

View Source
const (
	ProbeBytes = 33 + 11*ProbeReps + 70 // 23,068,764
	TwinBytes  = 33 + 11*TwinReps + 70  // 23,068,775
)

ProbeBytes and TwinBytes are the exact Content-Length of each stream. They are asserted against the built bytes in TestStreamSizes.

View Source
const CVE = "CVE-2026-111497"

CVE is the identifier the advisory assigns to the Brotli decoder bug.

View Source
const FixedReleases = "Node.js 22.23.4/24.22.1/26.12.1, Bun 1.4.4, Envoy 1.37.8+, Istio 1.29.9+, libbrotli 1.0.10/1.1.1/1.2.1"

FixedReleases names the first patched build of each affected decoder.

View Source
const MaxRoutesPerOrigin = 3

MaxRoutesPerOrigin caps how many recorded routes the differential is run against per origin once the unrouted path has shown nothing.

View Source
const ProbePath = "/vigolium-brotli-decoder-check"

ProbePath is a route no app defines. An app-wide parser (NestJS, a global app.use(express.json())) or a decoding proxy runs before routing, so a probe sent here is decoded without reaching any handler — which separates a parser mounted on the whole app from one mounted on a single route.

Variables

View Source
var (
	// EmptyJSON is valid JSON a handler can only refuse or accept as empty;
	// MalformedJSON is what every JSON parser refuses. A route that answers both
	// the same does not read its body and carries no signal.
	//
	// EmptyJSON is "{}" rather than the empty string on purpose: the 22 MiB probe
	// decodes to "{}" followed by spaces, so the control that stands for "the
	// decode succeeded" must decode to the same document. The Assetnote scanner's
	// valid control is a one-byte stream that decodes to "", which an app that
	// refuses an empty body but accepts {} puts in the MALFORMED class — on a
	// genuinely vulnerable target that reads as no signal.
	EmptyJSON     = []byte("{}")
	MalformedJSON = []byte("{")

	// BadStream is one byte that is not a valid Brotli document (and not a
	// valid gzip one either, so it fails under StackedEncoding too). Sent under
	// the encoding the gate proved is decoded, it learns a THIRD response class:
	// what the path answers when the decode itself fails, as opposed to when it
	// succeeds and the JSON parser then refuses the result.
	//
	// Servers distinguish the two — "Decompression failed" is not "Unexpected
	// end of JSON input" — and the node2shell probe needs the distinction: its
	// size-matched twin is a stream no decoder accepts, so it belongs in this
	// class, not in the malformed-JSON one.
	BadStream = []byte{0xff}
)
View Source
var DecodedProbe = append([]byte("{}"), bytes.Repeat([]byte(" "), 64)...)

DecodedProbe is what an affected decoder produces from ProbeStream: valid JSON, so the route answers it exactly as it answers a plain {} body.

View Source
var Encodings = []EncodedBodies{
	{
		Encoding:  BrotliEncoding,
		Empty:     []byte{0x8b, 0x00, 0x80, 0x7b, 0x7d, 0x03},
		Malformed: []byte{0x0b, 0x00, 0x80, 0x7b, 0x03},
	},
	{
		Encoding: StackedEncoding,
		Empty: []byte{
			0x0b, 0x0d, 0x80, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x02, 0x00,
			0xfd, 0xff, 0x7b, 0x7d, 0x03, 0x00, 0x43, 0xbf, 0xa6, 0xa3, 0x02, 0x00, 0x00, 0x00, 0x03,
		},
		Malformed: []byte{
			0x8b, 0x0c, 0x80, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x01, 0x00,
			0xfe, 0xff, 0x7b, 0x03, 0x00, 0x39, 0x47, 0xd5, 0x15, 0x01, 0x00, 0x00, 0x00, 0x03,
		},
	},
}

Encodings are EmptyJSON and MalformedJSON encoded as br and as "gzip, br" (gzip applied first), precomputed so no encoder runs at startup (TestEncodedControlsRoundTrip decodes them back). Tiny well-formed streams: ordinary decoder use, nowhere near the CVE-2026-111497 trigger.

View Source
var References = []string{
	"https://patchtheplanet.org/brotli",
	"https://nodejs.org/en/blog/vulnerability/october-2026-security-releases",
	"https://istio.io/latest/news/security/istio-security-2026-007/",
	"https://github.com/google/brotli/releases/tag/v1.2.1",
	"https://github.com/assetnote/node2shell-scanner",
}

References are attached to every CVE-2026-111497 result. The Assetnote scanner is the source of the 22 MiB probe stream the node2shell module sends.

Functions

func CarriesJSONBody

func CarriesJSONBody(method, contentType string) bool

CarriesJSONBody reports whether a recorded request is one the differential can probe: a POST or PATCH with a JSON body. PUT is skipped because PUT {} can replace a resource; the oracle needs a malformed JSON body, so form and text bodies are not probed.

func LikelyDecoder

func LikelyDecoder(scanCtx *modkit.ScanContext, host string, header nethttp.Header) string

LikelyDecoder names the component that probably decoded the body. A proxy in the path is named first: it decodes before the app, and a Python or Go app behind it is exposed only through it. Envoy and Bun have no fingerprint tag, so their headers are read here; app stacks come from the tech registry. The label is a hint for the reader, never a gate.

func OriginOf

func OriginOf(ctx *httpmsg.HttpRequestResponse) string

OriginOf returns the record's normalized origin, the key both modules budget by. Normalization matters here precisely because it IS the budget key: an explicit :443 and an uppercase host must not each buy their own 22 MiB probe of the same server.

func ProbeStream

func ProbeStream() []byte

ProbeStream builds the 23,068,764-byte version oracle. It allocates ~22 MiB and is deliberately NOT cached: a scan that never reaches an affected-looking host should not carry the buffer, and the caller already serializes probes behind a semaphore.

func Reverify

func Reverify(send SendFunc, g Gate) bool

Reverify re-sends the three tiny bodies the gate learned its classes from and reports whether all three still land where they did.

A gate's classes are a snapshot. Anything that runs a further stage against them — the node2shell probe takes tens of MiB and several seconds — is scoring that stage against a picture of the endpoint taken earlier, and the picture goes stale in exactly the cases that produce a wrong answer: a load balancer rotating to a backend that never decoded, a worker restarting into a different configuration, a route whose answer depends on state the earlier probes themselves changed.

Three sub-32-byte requests, so a caller can afford to run it between every expensive round rather than once at the end.

func Same

func Same(a, b Exchange) bool

Same reports whether two answers are the same page: equal status and a similar body.

func TwinStream

func TwinStream() []byte

TwinStream builds the size-matched negative control: the same stream with one extra repetition, 11 bytes longer and malformed for every decoder.

The Assetnote scanner has no equivalent. Its controls are all ONE BYTE while its probe is 22 MiB, so anything that reacts to the size of a body rather than to its content — a body silently dropped past a threshold, a proxy that stops buffering and forwards an empty body, a streaming cap — is read as the decoder's verdict. The twin removes that: it is the same size and the same shape, and no decoder in existence accepts it. If the twin and the probe are answered alike, size is driving the answer and nothing is reported; only a divergence between them is attributable to the decode.

func Unreliable

func Unreliable(e Exchange) bool

Unreliable reports a baseline that cannot anchor the differential: a server error or a throttle answers every probe alike.

Types

type Budget

type Budget struct {
	// contains filtered or unexported fields
}

Budget rations the differential across an origin: it runs on the unrouted path once, then on at most MaxRoutesPerOrigin recorded routes, and stops entirely once the origin has produced its answer.

It lives here rather than in either module because the two modules have to agree on WHERE they look for a decoder — the cheap exposure record and the expensive version record describing different paths of the same origin is the failure this shared package exists to prevent. Leaving the policy copy-maintained in both scanners made that agreement a matter of keeping two identical blocks in sync. Each module still owns its own DiskSet, so the keys below never collide between them.

func NewBudget

func NewBudget(ds *dedup.DiskSet) Budget

NewBudget wraps a module's DiskSet. A nil set (stateless scans, bare-context tests) yields a Budget that permits everything.

func (Budget) Settle

func (b Budget) Settle(origin string) bool

Settle marks the origin answered. It returns false if another record settled it first, which is how two lanes racing through the differential avoid both paying for the expensive stage.

func (Budget) Settled

func (b Budget) Settled(origin string) bool

Settled reports whether this origin already produced its answer, so no further lane should spend anything on it.

func (Budget) TakeRoute

func (b Budget) TakeRoute(origin, method, path string) bool

TakeRoute claims one of the origin's route-lane slots for method+path. It returns false when the origin is settled, when this route was already tried, or when the slots are used up (which also settles the origin).

type EncodedBodies

type EncodedBodies struct {
	Encoding         string
	Empty, Malformed []byte
}

EncodedBodies is one Content-Encoding with EmptyJSON and MalformedJSON encoded under it.

func BrotliOnly

func BrotliOnly() []EncodedBodies

BrotliOnly restricts a gate to plain br.

The node2shell probe needs it. Its stream is a bare Brotli document whose output is fixed at 66 bytes of JSON by the construction that drives the counter to the wrap — so under "gzip, br" a server un-brs it to those 66 bytes and then tries to gunzip them, which fails on every build, affected or not. There is no stacked form of the probe to send, and a gate that opened on StackedEncoding would hand the version stage 22 MiB that can only come back negative. Such a host is still real exposure; it is just not testable this way, and the exposure module reports it.

type Exchange

type Exchange struct {
	Sig      modkit.ResponseSignature
	Header   nethttp.Header
	Request  string
	Response string
}

Exchange is one sent probe's outcome. Request and Response are evidence strings the caller has already truncated or elided as it sees fit.

type Gate

type Gate struct {
	// Bodies are the control streams that were decoded, so a caller that runs
	// a further stage can re-send the same valid control afterwards. Their
	// Encoding is the coding the path decoded — see Gate.Encoding.
	Bodies EncodedBodies
	// Empty and Malformed are the plain {} and plain { response classes.
	Empty, Malformed Exchange
	// Decoded and DecodedMalformed are the encoded {} and { answered like them.
	Decoded, DecodedMalformed Exchange
	// Unknown, Noise and Misplaced are the three controls that must NOT be
	// answered like the route's {} class (Noise must be).
	Unknown, Noise, Misplaced Exchange
	// Failed is the decode-failure class: what the path answers for bytes the
	// decoder itself refuses, as opposed to bytes it decodes into malformed
	// JSON. See BadStream.
	Failed Exchange
}

Gate is a completed decode differential: the two plain response classes the path answers with, and the encoded probes that proved the answer follows the decoded content rather than the header.

func RunGate

func RunGate(send SendFunc) (Gate, bool)

RunGate runs the differential over every known encoding. See RunGateFor.

func RunGateFor

func RunGateFor(send SendFunc, candidates []EncodedBodies) (Gate, bool)

RunGateFor runs the decode differential against one method+path. It opens only when the answer follows the decoded content, not the header:

  • the path reads its body: plain {} and plain { are answered differently, and plain {} is not a 5xx or 429 (an erroring or throttled baseline matches anything);
  • encoded {} is answered like plain {} and encoded { like plain {, for ConfirmRounds rounds. A server that reacts to the header alone (a WAF block, a 4xx/5xx with odd headers, a dropped body) answers both encoded bodies alike, and a flaky one breaks on the repeat;
  • the same bytes under an unknown encoding are not answered like plain {};
  • header decoys: plain {} with a random DecoyHeader is answered like plain {}, and the encoded bytes with DecoyHeader naming the encoding (no Content-Encoding) are not;
  • a stream the decoder refuses outright is not answered like plain {} either, which is what makes the decode-failure class observable.

A server that ignores Content-Encoding sees the Brotli bytes as malformed JSON and stops at the first encoded probe.

Ten round-trips on the happy path, all with bodies under 32 bytes. It is the precondition for the node2shell probe, which costs tens of MiB: spending ten tiny requests to learn there is no decoder here is what makes that affordable.

candidates are the encodings to try, in order. A caller whose follow-up stage only works under one of them passes just that one rather than opening a gate it cannot use — see BrotliOnly.

func (Gate) Encoding

func (g Gate) Encoding() string

Encoding is the Content-Encoding the path decoded (BrotliEncoding, or StackedEncoding when a guard refused plain br). It is derived from Bodies rather than stored, so a Gate cannot describe one coding and carry the control streams of another.

type Prober

type Prober struct {
	// contains filtered or unexported fields
}

Prober replays one method+path against a record's origin with a varying body and headers. The request is rebuilt once; each probe swaps only the body and at most one header, so both modules send byte-identical framing and their response classes are comparable.

func NewProber

func NewProber(ctx *httpmsg.HttpRequestResponse, client *http.Requester, method, path, contentType string) (*Prober, bool)

NewProber rewrites the record's request into a method+path+Content-Type probe. The record's own headers (cookies, auth) are kept so an authenticated route is probed as the operator sees it; framing headers are replaced.

func (*Prober) Send

func (p *Prober) Send(name, value string, body []byte) (Exchange, bool)

Send is a SendFunc: it fires the base request with body and one extra header (none when value is empty). Intended for the gate's sub-32-byte bodies, which are kept verbatim as evidence.

func (*Prober) SendStream

func (p *Prober) SendStream(encoding string, body []byte) (Exchange, bool)

SendStream fires a multi-MiB body under the given Content-Encoding.

Two headers differ from Send. "Expect: 100-continue" gives an edge with a body-size limit the chance to answer 413 off the advertised Content-Length before 22 MiB goes up the wire — the transport waits for the 100 because ExpectContinueTimeout is set on it. "Connection: close" retires the connection afterwards rather than returning a socket that just carried a probe to the pool.

The body is elided from the evidence: a finding travels through the database, the JSON envelope and the report, and must not carry 22 MiB through any of them.

type SendFunc

type SendFunc func(headerName, headerValue string, body []byte) (Exchange, bool)

SendFunc fires one probe: the caller's base request with body as its body and one extra header (none when value is empty). It reports false when the exchange could not be completed, which aborts the gate.

Jump to

Keyboard shortcuts

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