Add server-side RESP protocol restrictions#1875
Conversation
|
@Haihan-Jiang please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds server configuration to restrict accepted RESP protocol versions and enforces that policy during command handling/HELLO negotiation.
Changes:
- Introduces
RespProtocolModeand plumbsAllowedProtocolsthrough server options/config/CLI. - Enforces protocol policy in
HELLOand command processing paths. - Adds tests validating config parsing and runtime behavior for RESP2-only / RESP3-only modes.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/standalone/Garnet.test/TestUtils.cs | Extends test server factory to accept allowedProtocols. |
| test/standalone/Garnet.test/RespTests.cs | Adds runtime tests for HELLO + command behavior under protocol restrictions. |
| test/standalone/Garnet.test/GarnetServerConfigTests.cs | Adds config/CLI parsing tests for AllowedProtocols. |
| libs/server/Servers/RespProtocolMode.cs | New enum defining allowed protocol modes. |
| libs/server/Servers/GarnetServerOptions.cs | Adds AllowedProtocols and helper to validate protocol version. |
| libs/server/Resp/RespServerSession.cs | Enforces protocol policy during command execution. |
| libs/server/Resp/CmdStrings.cs | Adds new error message for disallowed protocol. |
| libs/server/Resp/BasicCommands.cs | Rejects HELLO protocol changes that violate server policy. |
| libs/host/defaults.conf | Documents and sets default config value for AllowedProtocols. |
| libs/host/Configuration/Options.cs | Adds CLI option and plumbs into server options. |
| bool useAcl = false, // NOTE: Temporary until ACL is enforced as default | ||
| string aclFile = null, | ||
| bool aclStrictCustomCommands = true, | ||
| RespProtocolMode allowedProtocols = RespProtocolMode.Both, | ||
| string indexSize = "1m", | ||
| string indexMaxSize = default, | ||
| string[] extensionBinPaths = null, |
| [Option("allowed-protocols", Required = false, HelpText = "RESP protocol versions accepted by client sessions. Value options: Both, Resp2, Resp3")] | ||
| public RespProtocolMode AllowedProtocols { get; set; } |
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| private bool IsCommandAllowedByRespProtocolPolicy(RespCommand cmd) | ||
| { | ||
| if (storeWrapper.serverOptions.AllowedProtocols != RespProtocolMode.Resp3) | ||
| return true; | ||
|
|
||
| return respProtocolVersion == 3 || cmd == RespCommand.HELLO; | ||
| } |
Summary
--allowed-protocolswithBoth,Resp2, andResp3modesHELLOprotocol switches that are disallowed by server configurationHELLO 3Details
Bothremains the default behavior.Resp2keeps existing RESP2 clients workingand rejects
HELLO 3.Resp3allowsHELLO 3as the negotiation entry point,then permits normal commands after the session protocol switches to RESP3. A
client in RESP3-only mode that sends ordinary commands before
HELLO 3receives:For authenticated deployments, clients should use
HELLO 3 AUTH <user> <pass>as the first command.
Tests
Latest local validation result, 2026-06-13 07:24 PDT / 14:24 UTC: all four
targeted
dotnet testinvocations passed, covering 7 tests total. Bothtracked-file
git diff --checkand the untrackedRespProtocolMode.csno-index whitespace check passed.
Addresses #1755.