Skip to content

fix(cluster): validate MOVED slot to prevent Array.prototype pollution - #2151

Merged
PavelPashov merged 2 commits into
redis:mainfrom
nkaradzhov:fix/cluster-moved-slot-validation
Jul 29, 2026
Merged

PavelPashov merged 2 commits into
redis:mainfrom
nkaradzhov:fix/cluster-moved-slot-validation

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request fixes a prototype pollution vulnerability in the Cluster MOVED redirect handler.

The bug: Cluster#handleError splits the RESP error string and passes the slot token straight into the moved handler, which used it as an index into the internal slots array without validation:

if (_this.slots[slot]) {
  _this.slots[slot][0] = key;
} else {
  _this.slots[slot] = [key];
}

slots is initialized as []. A malicious or compromised cluster node — or an attacker in a MITM / DNS-poisoning position — replying with -MOVED __proto__ host:port makes _this.slots["__proto__"] resolve to Array.prototype (truthy), so _this.slots[slot][0] = key writes to Array.prototype[0], polluting every array in the process.

This is a variant of the previously fixed hgetall prototype pollution (#1267) that was never applied to the MOVED code path.

The fix: validate the slot is an integer in the cluster range [0, 16383] before using it as an index. Malformed redirects are rejected with the original error instead of being applied, so no attacker-controlled value can reach slots[...].

Behavior change: a MOVED reply with a non-numeric or out-of-range slot is now rejected rather than acted on. Well-behaved Redis Cluster servers always send an integer slot, so legitimate traffic is unaffected.

Ref: https://hackerone.com/reports/3761875


Note

High Risk
Security fix in cluster redirect handling that prevents global prototype pollution from untrusted MOVED replies; behavior change only for malformed/out-of-range slots.

Overview
Fixes a prototype pollution vulnerability when handling Redis Cluster MOVED redirects. A malicious node (or MITM) could reply with MOVED __proto__ host:port; the client used the slot token as an array index on the internal slots table ([]), which made slots["__proto__"] resolve to Array.prototype and allowed writes like Array.prototype[0].

Cluster#handleError now parses the slot with Number(), requires an integer in [0, 16383], and calls handlers.defaults() (surface the original error) when validation fails. Valid slots are passed as a number into moved handlers instead of the raw string token.

Pipeline’s inline moved callback is updated to use that numeric slot when updating cluster.slots and _groupsBySlot (replacing incorrect errv[1] references).

Functional tests cover crafted MOVED __proto__ for single commands and pipelines, asserting Array.prototype is not polluted.

Reviewed by Cursor Bugbot for commit b7a01d9. Bugbot is set up for automated code reviews on this repo. Configure here.

The Cluster MOVED handler used the slot token from the redirect error
message directly as an index into the internal `slots` array without
validating it. A malicious or compromised node (or a MITM/DNS-poisoning
position) replying with `-MOVED __proto__ host:port` caused
`this.slots["__proto__"]` to resolve to `Array.prototype`, and the
subsequent `this.slots[slot][0] = key` wrote to `Array.prototype[0]`,
polluting every array in the process.

Validate that the slot is an integer in the cluster range [0, 16383]
before using it. Malformed redirects are rejected with the original
error instead of being applied.

This is a variant of the previously fixed hgetall prototype pollution
(redis#1267) that was never applied to the MOVED code path.

Ref: https://hackerone.com/reports/3761875

Co-Authored-By: Claude Fable 5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4bd22aae08

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/cluster/index.ts Resolved
Move the slot validation into the shared `handleError` boundary so both
the single-command and pipeline MOVED handlers are protected, and pass
the parsed numeric slot to the handlers. The pipeline retry path had its
own MOVED handler that indexed `cluster.slots[errv[1]]` with the raw
token, bypassing the earlier fix (a "__proto__" token polluted
Array.prototype and a "length" token threw RangeError).

Add a pipeline regression test alongside the single-command one.

Ref: https://hackerone.com/reports/3761875
Addresses Codex review feedback on redis#2151.

Co-Authored-By: Claude Fable 5 <[email protected]>
@nkaradzhov
nkaradzhov requested a review from PavelPashov July 27, 2026 14:57
@PavelPashov
PavelPashov merged commit 9618206 into redis:main Jul 29, 2026
22 checks passed
github-actions Bot pushed a commit that referenced this pull request Jul 29, 2026
# [6.0.0-beta.1](v5.11.1...v6.0.0-beta.1) (2026-07-29)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions Bot pushed a commit that referenced this pull request Jul 31, 2026
# [6.0.0](v5.11.1...v6.0.0) (2026-07-31)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))
* **types:** export ScanStreamOptions, RedisStatus and ClusterStatus ([#2158](#2158)) ([cf3bf71](cf3bf71))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* himport managed fieldsets ([#2159](#2159)) ([729f174](729f174))
* improve default connection resilience ([#2160](#2160)) ([6d0716e](6d0716e))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

stxkxs added a commit to nanohype/slack-knowledge-bot that referenced this pull request Aug 18, 2026
ioredis 5.10.1 → 6.0.0. Two breaking changes in the release, both checked
against what this service actually does rather than accepted on faith.

─── Node floor ───

6.0 requires Node >= 20. This repo declares `engines.node: ">=24"`, runs
`node:24-alpine` in the Dockerfile and Node 24 in CI. Clear.

─── RESP3 by default ───

The real change: 6.0 negotiates RESP3 unless `protocol: 2` is set. RESP3
reshapes some replies from flat arrays into maps, which would silently break
parsing rather than fail loudly, so the question is which commands this
service issues.

All of them, and only these: ZREMRANGEBYSCORE, ZCARD, ZADD and EXPIRE — the
sliding-window rate limiter's pipeline, the complete Redis surface behind
`RedisPipelinePort` in `src/ratelimit/redis-limiter.ts`. Every one replies
with an integer under both protocols, and `pipeline().exec()` keeps its
`[err, result]` tuple shape. The commands RESP3 actually reshapes — CONFIG
GET, HGETALL, XPENDING and friends — are not ones this service issues, and the
narrow port is what makes that a bounded claim rather than a hopeful one:
nothing can reach the client except through those four methods.

So the default is kept rather than pinned back to `protocol: 2`. Taking a
major and immediately disabling its headline change would be adopting the
version number without the version. The reasoning is recorded in `src/redis.ts`
next to the client options, along with the escape hatch, for whoever meets a
cache that cannot speak RESP3.

Also picks up an Array.prototype pollution fix in the cluster MOVED handler
(redis/ioredis#2151) and a stale-socket-timeout fix on reconnect (#2148),
neither of which this service was exposed to — single-node client, no cluster.

Gate: 212 tests pass, typecheck / lint / format clean, `npm audit
--audit-level=high --omit=dev` reports 0 vulnerabilities.

Co-authored-by: stxkxsbot <[email protected]>
stxkxs added a commit to nanohype/slack-knowledge-bot that referenced this pull request Aug 18, 2026
ioredis 5.10.1 → 6.0.0. Two breaking changes in the release, both checked
against what this service actually does rather than accepted on faith.

─── Node floor ───

6.0 requires Node >= 20. This repo declares `engines.node: ">=24"`, runs
`node:24-alpine` in the Dockerfile and Node 24 in CI. Clear.

─── RESP3 by default ───

The real change: 6.0 negotiates RESP3 unless `protocol: 2` is set. RESP3
reshapes some replies from flat arrays into maps, which would silently break
parsing rather than fail loudly, so the question is which commands this
service issues.

All of them, and only these: ZREMRANGEBYSCORE, ZCARD, ZADD and EXPIRE — the
sliding-window rate limiter's pipeline, the complete Redis surface behind
`RedisPipelinePort` in `src/ratelimit/redis-limiter.ts`. Every one replies
with an integer under both protocols, and `pipeline().exec()` keeps its
`[err, result]` tuple shape. The commands RESP3 actually reshapes — CONFIG
GET, HGETALL, XPENDING and friends — are not ones this service issues, and the
narrow port is what makes that a bounded claim rather than a hopeful one:
nothing can reach the client except through those four methods.

So the default is kept rather than pinned back to `protocol: 2`. Taking a
major and immediately disabling its headline change would be adopting the
version number without the version. The reasoning is recorded in `src/redis.ts`
next to the client options, along with the escape hatch, for whoever meets a
cache that cannot speak RESP3.

Also picks up an Array.prototype pollution fix in the cluster MOVED handler
(redis/ioredis#2151) and a stale-socket-timeout fix on reconnect (#2148),
neither of which this service was exposed to — single-node client, no cluster.

Gate: 212 tests pass, typecheck / lint / format clean, `npm audit
--audit-level=high --omit=dev` reports 0 vulnerabilities.

Co-authored-by: stxkxsbot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants