Preserve ACL operand bytes across SAVE and reload

perfloop-oss/dragonfly · Uncatalogued correctness

https://perfloop.ai/t/oss/case_pwmx7169j0

Verdict

VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-02 · pull request opened as dragonflydb/dragonfly#8750

What happened: The check fails before this change and passes with it.

Hypothesis

An accepted key pattern containing a newline is saved successfully but cannot be loaded back. ACL SAVE writes operand bytes into the same text that uses spaces and newlines as separators. The saved file is therefore not a reversible record of supported ACL arguments. How often deployed policies contain these values remains unknown.

The broader defect is the file representation, not one character-specific check in KeysToString. At revision 583b1a67ef1297e681c6482efbee096400634eca, KeysToString joins raw patterns and their mode prefixes with spaces. UserToString also writes the username and the channel-pattern serialization without an operand codec. RegistryToString separates users with newlines. MaterializeFileContents splits on newlines and then spaces, with no matching quotation or escape decoder. ParseKeyRule and ParseChannelRule accept nonempty pattern payloads containing these bytes; SetUser also accepts an empty username.

The compiled checkProperty run for prop_h3751bdq0h, using bash tests/acl_saved_operands_property/run.sh 'AclSavedOperandsProperty.*', exited 1 with three reduced counterexamples. A single LF byte, hexadecimal 0a, in either a key or channel pattern was accepted by SETUSER and SAVE, but LOAD rejected the saved file. An empty username was accepted and saved, and LOAD returned OK while the original user identity was not preserved. The run returned replay_key.txt containing '0 0 0a', replay_channel.txt containing '1 0 0a', and replay_username.txt containing '2 0 -'. Empty key/channel patterns are rejected, so the one-byte pattern witnesses cannot be shortened within their supported domain.

The independent KeyModeTransitions test completed all 156 sequences of length zero through three over five modifiers, comparing GET/SET authorization on a, b, and outside before and after persistence. It found no mismatch within that finite bound. The operand searches stopped at their first failures; later byte values, two-byte combinations, and every key-prefix variant were not exhaustively exercised. This is not a claim that ordinary delimiter-free modes are already broken.

Merged https://github.com/dragonflydb/dragonfly/pull/8681 deliberately preserves literal values and adds tab coverage, but its actual implementation still uses separator splitting. Merged https://github.com/dragonflydb/dragonfly/pull/8686 introduces the shared UserToString present at this accepted revision and retains that format. The freshly inspected https://github.com/dragonflydb/dragonfly/pull/8721 merges duplicate key-pattern permissions and changes authorization checks; it does not repair persistence encoding. The registry changes in https://github.com/dragonflydb/dragonfly/pull/8678 concern HTTP authentication, not these operands. Targeted prior-repair searches found no matching format repair.

The smallest useful Case check is to replay the retained native inputs, then verify exact operands and read/write authorization after runtime LOAD and fresh startup. Legacy files with literal tabs, quotes, and backslashes need compatibility controls. Startup rejection of a malformed saved file is a source-derived consequence of the shared loader and its fail-closed initialization, not something this native LOAD run measured. A shared codec can remove this class of loss across operand positions, but its format compatibility, documentation, and parser-maintenance cost must be justified rather than treating quoting as a local string substitution.

Change to test: Make the persisted ACL representation lossless for user names and key/channel pattern operands, with matching encoding and decoding that preserves key modes and allkeys/resetkeys state. Continue reading legacy files without reinterpreting their literal tabs, quotes, or backslashes, and document any new file convention separately from display formatting.

Where it lives

perfloop-oss/dragonfly · src/server/acl/acl_family.cc

Evidence

The check fails before this change and passes with it: `ACL SETUSER rejects empty usernames and space, LF, CR or NUL inside usernames or nonempty key/channel patterns, without creating a user or changing existing rules.`

The check fails before this change and passes with it: `ACL LOAD rejects CR or NUL inside parsed username and key/channel-pattern tokens, and malformed LF-split or incomplete USER records, before changing live users.`

The check fails before this change and passes with it: `Startup with an ACL file containing a CR inside a key-pattern token reports an ACL parse error and exits with status 1 rather than starting the server.`

Checks: 3 of 3 passed. Verification: no defect found.

Timeline