From 8c13f4582344fb70c7356a0ec98c20f8652dec61 Mon Sep 17 00:00:00 2001 From: Yethe Samartaka Date: Tue, 1 Dec 2026 23:21:11 +0100 Subject: [PATCH 1/3] fix(recorder): mask the admin password in #login chat commands A #login chat command carries the server admin password, which reached the extension and from there the recording, its database and spool. The chat handler now keeps the command and replaces everything after it with a fixed mask ("#login ********") that does not reveal the length. Matching ignores case and surrounding whitespace, like the web server. Adds tests/chat_redaction_regressions.sqf, which needs no players. Co-Authored-By: Claude Opus 5.5 --- addons/recorder/XEH_prep.sqf | 1 + addons/recorder/fnc_handleChatMessage.sqf | 3 ++ addons/recorder/fnc_redactLoginCommand.sqf | 39 ++++++++++++++ tests/README.md | 12 +++++ tests/chat_redaction_regressions.sqf | 59 ++++++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 addons/recorder/fnc_redactLoginCommand.sqf create mode 100644 tests/chat_redaction_regressions.sqf diff --git a/addons/recorder/XEH_prep.sqf b/addons/recorder/XEH_prep.sqf index 86848a7..01ddd59 100644 --- a/addons/recorder/XEH_prep.sqf +++ b/addons/recorder/XEH_prep.sqf @@ -56,6 +56,7 @@ PREP(addEventIntegrations); PREP(getStaticObjects); PREP(trackSectors); PREP(handleChatMessage); +PREP(redactLoginCommand); PREP(radioEvent); PREP(installPlayerTrackingClients); diff --git a/addons/recorder/fnc_handleChatMessage.sqf b/addons/recorder/fnc_handleChatMessage.sqf index db49f80..f6e06f2 100644 --- a/addons/recorder/fnc_handleChatMessage.sqf +++ b/addons/recorder/fnc_handleChatMessage.sqf @@ -12,6 +12,9 @@ if (parseNumber _strID > 1) then { private _senderOcapId = _person getVariable [QGVARMAIN(id), -1]; +// A #login command carries the server admin password: record the command only. +_text = [_text] call FUNC(redactLoginCommand); + [":EVENT:CHAT:", [ GVAR(captureFrameNo), _senderOcapId, diff --git a/addons/recorder/fnc_redactLoginCommand.sqf b/addons/recorder/fnc_redactLoginCommand.sqf new file mode 100644 index 0000000..0b3378b --- /dev/null +++ b/addons/recorder/fnc_redactLoginCommand.sqf @@ -0,0 +1,39 @@ +/* ---------------------------------------------------------------------------- +FILE: fnc_redactLoginCommand.sqf + +FUNCTION: OCAP_recorder_fnc_redactLoginCommand + +Description: + Masks the server admin password in a `#login` chat command before + records it. The recording keeps the + command, so playback still shows that someone logged in, but everything + typed after `#login` becomes a fixed mask that does not reveal its length. + + Matches the command in any case, ignoring surrounding whitespace, like the + OCAP web server, which masks the same way for recordings from older addons. + +Parameters: + _text - The chat message [String] + +Returns: + [String] - The message, unchanged unless it is a `#login` command + +Examples: + > ["#login hunter2"] call FUNC(redactLoginCommand); // "#login ********" + > ["radio check"] call FUNC(redactLoginCommand); // "radio check" + +Public: + No + +Author: + OCAP contributors +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params [["_text", "", [""]]]; + +private _message = trim _text; +private _command = _message select [0, 6]; +if (toLower _command isNotEqualTo "#login") exitWith {_text}; +if (trim (_message select [6]) isEqualTo "") exitWith {_command}; +_command + " ********" diff --git a/tests/README.md b/tests/README.md index 0c7ff3b..98b4279 100644 --- a/tests/README.md +++ b/tests/README.md @@ -94,3 +94,15 @@ or saved. The suite replaces recording state and resets per-unit recording variables, and a recording start it simulates also satisfies the auto-start waiter; restart the mission afterwards. It is an opt-in test artifact, not included in the release PBOs. + +`chat_redaction_regressions.sqf` checks that a `#login` chat command reaches the +extension with everything after `#login` masked, in any case and spacing, while +ordinary chat and `#login` inside a sentence are recorded as typed. It needs no +players and runs in a moment. Execute it on the server of the test build: + +```sqf +execVM "tests\chat_redaction_regressions.sqf"; +``` + +The RPT must end with `[OCAP chat redaction] ALL TESTS PASSED`. Extension writes +are intercepted and restored afterwards. diff --git a/tests/chat_redaction_regressions.sqf b/tests/chat_redaction_regressions.sqf new file mode 100644 index 0000000..e4b6f6c --- /dev/null +++ b/tests/chat_redaction_regressions.sqf @@ -0,0 +1,59 @@ +/* Run on the server in a disposable mission; see tests/README.md. */ +if (!isServer) exitWith {throw "Run the tests on the server"}; + +private _assert = { + params ["_condition", "_description"]; + if (!_condition) then {throw _description}; + diag_log format ["[OCAP chat redaction] PASS: %1", _description]; +}; +private _savedSendData = missionNamespace getVariable "OCAP_extension_fnc_sendData"; +private _savedFrame = missionNamespace getVariable "OCAP_recorder_captureFrameNo"; +private _error = ""; + +// Intercept extension output, never upload a test recording. +OCAP_test_commands = []; +OCAP_extension_fnc_sendData = { + params ["_command", ["_args", []]]; + if (_command isEqualTo ":EVENT:CHAT:") then {OCAP_test_commands pushBack +_this}; + "" +}; +OCAP_recorder_captureFrameNo = 7; + +try { + { + _x params ["_text", "_expected", "_description"]; + [([_text] call OCAP_recorder_fnc_redactLoginCommand) isEqualTo _expected, _description] call _assert; + } forEach [ + ["#login hunter2", "#login ********", "the password after #login is masked"], + [" #LOGIN Hunter2 ", "#LOGIN ********", "the command matches in any case and around whitespace"], + ["#loginhunter2", "#login ********", "a password typed without a space is masked too"], + ["#login", "#login", "a bare #login has nothing to mask"], + ["#login ", "#login", "trailing whitespace alone is not a password"], + ["#login ********", "#login ********", "masking an already masked command changes nothing"], + ["#logout", "#logout", "#logout carries no password"], + ["radio check", "radio check", "ordinary chat is unchanged"], + ["say #login hunter2", "say #login hunter2", "#login inside a sentence is not a command"], + ["", "", "an empty message stays empty"] + ]; + + [0, 3, "Synthetic Admin", " #login hunter2", objNull, "Synthetic Admin", "0", false, true, 0, 0] call OCAP_recorder_fnc_handleChatMessage; + [1, 3, "Synthetic Player", "radio check", objNull, "Synthetic Player", "0", false, true, 0, 0] call OCAP_recorder_fnc_handleChatMessage; + [count OCAP_test_commands == 2, "both chat messages reach the extension"] call _assert; + private _login = (OCAP_test_commands select 0) select 1; + [(_login select 5) isEqualTo "#login ********", "the recorded #login command carries no password"] call _assert; + [(str OCAP_test_commands) find "hunter2" == -1, "the password reaches the extension nowhere"] call _assert; + [(_login select 0) == 7 && {(_login select 2) == 0} && {(_login select 3) isEqualTo "Synthetic Admin"}, "the masked message keeps its frame, channel and sender"] call _assert; + [((OCAP_test_commands select 1) select 1 select 5) isEqualTo "radio check", "ordinary chat is recorded as typed"] call _assert; +} catch { + _error = str _exception; +}; + +OCAP_extension_fnc_sendData = _savedSendData; +OCAP_recorder_captureFrameNo = _savedFrame; +OCAP_test_commands = nil; + +if (_error != "") then { + diag_log format ["[OCAP chat redaction] FAIL: %1", _error]; + throw _error; +}; +diag_log "[OCAP chat redaction] ALL TESTS PASSED"; From 5cd11fb2d0410c192a93194cfc4af6d6594d9505 Mon Sep 17 00:00:00 2001 From: Yethe Samartaka Date: Tue, 1 Dec 2026 23:49:55 +0100 Subject: [PATCH 2/3] fix(recorder): skip leading Unicode whitespace before #login SQF trim removes only spaces, tabs and line breaks, so a #login behind a non-breaking space kept its password in the :EVENT:CHAT: payload and the extension's debug log. The command is now found after any Unicode White_Space character or U+FEFF, the set the web server trims, matched on code points from toArray. The regression suite covers the extension boundary with a leading non-breaking space and other Unicode whitespace. Co-Authored-By: Claude Opus 5.5 --- addons/recorder/fnc_redactLoginCommand.sqf | 20 +++++++++++++++++--- tests/README.md | 5 +++-- tests/chat_redaction_regressions.sqf | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/addons/recorder/fnc_redactLoginCommand.sqf b/addons/recorder/fnc_redactLoginCommand.sqf index 0b3378b..ed26b98 100644 --- a/addons/recorder/fnc_redactLoginCommand.sqf +++ b/addons/recorder/fnc_redactLoginCommand.sqf @@ -11,6 +11,9 @@ Description: Matches the command in any case, ignoring surrounding whitespace, like the OCAP web server, which masks the same way for recordings from older addons. + Whitespace is every Unicode White_Space character plus U+FEFF, the set the + web server trims, so a leading non-breaking space cannot hide the command. + `trim` alone would not do: it removes only spaces, tabs and line breaks. Parameters: _text - The chat message [String] @@ -32,8 +35,19 @@ Author: params [["_text", "", [""]]]; -private _message = trim _text; -private _command = _message select [0, 6]; +// Unicode code points of Go's unicode.IsSpace, and U+FEFF, which JavaScript's +// trim removes as well. +private _spaces = [ + 9, 10, 11, 12, 13, 32, 133, 160, 5760, + 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, + 8232, 8233, 8239, 8287, 12288, 65279 +]; + +private _chars = toArray _text; +private _start = _chars findIf {!(_x in _spaces)}; +if (_start < 0) exitWith {_text}; + +private _command = toString (_chars select [_start, 6]); if (toLower _command isNotEqualTo "#login") exitWith {_text}; -if (trim (_message select [6]) isEqualTo "") exitWith {_command}; +if ((_chars select [_start + 6]) findIf {!(_x in _spaces)} < 0) exitWith {_command}; _command + " ********" diff --git a/tests/README.md b/tests/README.md index 98b4279..7778c05 100644 --- a/tests/README.md +++ b/tests/README.md @@ -96,8 +96,9 @@ waiter; restart the mission afterwards. It is an opt-in test artifact, not included in the release PBOs. `chat_redaction_regressions.sqf` checks that a `#login` chat command reaches the -extension with everything after `#login` masked, in any case and spacing, while -ordinary chat and `#login` inside a sentence are recorded as typed. It needs no +extension with everything after `#login` masked, in any case and behind any +Unicode whitespace, a non-breaking space included, while ordinary chat and +`#login` inside a sentence are recorded as typed. It needs no players and runs in a moment. Execute it on the server of the test build: ```sqf diff --git a/tests/chat_redaction_regressions.sqf b/tests/chat_redaction_regressions.sqf index e4b6f6c..7ee6f08 100644 --- a/tests/chat_redaction_regressions.sqf +++ b/tests/chat_redaction_regressions.sqf @@ -19,6 +19,12 @@ OCAP_extension_fnc_sendData = { }; OCAP_recorder_captureFrameNo = 7; +// Characters the tests cannot type literally. +private _nbsp = toString [160]; +private _ideographicSpace = toString [12288]; +private _bom = toString [65279]; +private _nel = toString [133]; + try { { _x params ["_text", "_expected", "_description"]; @@ -33,17 +39,25 @@ try { ["#logout", "#logout", "#logout carries no password"], ["radio check", "radio check", "ordinary chat is unchanged"], ["say #login hunter2", "say #login hunter2", "#login inside a sentence is not a command"], - ["", "", "an empty message stays empty"] + ["", "", "an empty message stays empty"], + [_nbsp + "#login hunter2", "#login ********", "a leading non-breaking space does not hide the command"], + [_bom + _ideographicSpace + _nel + "#LOGIN hunter2", "#LOGIN ********", "any leading Unicode whitespace is skipped"], + ["#login" + _nbsp + "hunter2", "#login ********", "a non-breaking space before the password still masks it"], + ["#login" + _nbsp + _ideographicSpace, "#login", "trailing Unicode whitespace alone is not a password"], + [_nbsp + "say #login hunter2", _nbsp + "say #login hunter2", "other messages keep their whitespace"], + [_nbsp, _nbsp, "a message of whitespace alone is unchanged"] ]; [0, 3, "Synthetic Admin", " #login hunter2", objNull, "Synthetic Admin", "0", false, true, 0, 0] call OCAP_recorder_fnc_handleChatMessage; [1, 3, "Synthetic Player", "radio check", objNull, "Synthetic Player", "0", false, true, 0, 0] call OCAP_recorder_fnc_handleChatMessage; - [count OCAP_test_commands == 2, "both chat messages reach the extension"] call _assert; + [0, 3, "Synthetic Admin", _nbsp + "#login hunter2", objNull, "Synthetic Admin", "0", false, true, 0, 0] call OCAP_recorder_fnc_handleChatMessage; + [count OCAP_test_commands == 3, "every chat message reaches the extension"] call _assert; private _login = (OCAP_test_commands select 0) select 1; [(_login select 5) isEqualTo "#login ********", "the recorded #login command carries no password"] call _assert; [(str OCAP_test_commands) find "hunter2" == -1, "the password reaches the extension nowhere"] call _assert; [(_login select 0) == 7 && {(_login select 2) == 0} && {(_login select 3) isEqualTo "Synthetic Admin"}, "the masked message keeps its frame, channel and sender"] call _assert; [((OCAP_test_commands select 1) select 1 select 5) isEqualTo "radio check", "ordinary chat is recorded as typed"] call _assert; + [((OCAP_test_commands select 2) select 1 select 5) isEqualTo "#login ********", "a #login behind a non-breaking space reaches the extension masked"] call _assert; } catch { _error = str _exception; }; From 7f5c0002d75ae99b8ec1b3a2901b86bf2c7fbdd7 Mon Sep 17 00:00:00 2001 From: Yethe Samartaka Date: Wed, 2 Dec 2026 17:30:08 +0100 Subject: [PATCH 3/3] fix(recorder): keep #login redaction compatible with Arma 2.10 The suffix slice omitted its count, which became optional only in Arma 2.14, while the recorder declares 2.10. Pass the count explicitly and cover a command at the very end of the message. Co-Authored-By: Claude Opus 5.5 --- addons/recorder/fnc_redactLoginCommand.sqf | 5 ++++- tests/chat_redaction_regressions.sqf | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/recorder/fnc_redactLoginCommand.sqf b/addons/recorder/fnc_redactLoginCommand.sqf index ed26b98..b234903 100644 --- a/addons/recorder/fnc_redactLoginCommand.sqf +++ b/addons/recorder/fnc_redactLoginCommand.sqf @@ -47,7 +47,10 @@ private _chars = toArray _text; private _start = _chars findIf {!(_x in _spaces)}; if (_start < 0) exitWith {_text}; +// Slices pass an explicit count: the count became optional only in Arma 2.14, +// and the recorder still supports 2.10. private _command = toString (_chars select [_start, 6]); if (toLower _command isNotEqualTo "#login") exitWith {_text}; -if ((_chars select [_start + 6]) findIf {!(_x in _spaces)} < 0) exitWith {_command}; +private _rest = _start + 6; +if ((_chars select [_rest, count _chars - _rest]) findIf {!(_x in _spaces)} < 0) exitWith {_command}; _command + " ********" diff --git a/tests/chat_redaction_regressions.sqf b/tests/chat_redaction_regressions.sqf index 7ee6f08..c62219f 100644 --- a/tests/chat_redaction_regressions.sqf +++ b/tests/chat_redaction_regressions.sqf @@ -44,6 +44,7 @@ try { [_bom + _ideographicSpace + _nel + "#LOGIN hunter2", "#LOGIN ********", "any leading Unicode whitespace is skipped"], ["#login" + _nbsp + "hunter2", "#login ********", "a non-breaking space before the password still masks it"], ["#login" + _nbsp + _ideographicSpace, "#login", "trailing Unicode whitespace alone is not a password"], + [_nbsp + "#LOGIN", "#LOGIN", "a command at the very end of the message has nothing after it to scan"], [_nbsp + "say #login hunter2", _nbsp + "say #login hunter2", "other messages keep their whitespace"], [_nbsp, _nbsp, "a message of whitespace alone is unchanged"] ];