Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/security/screenshot-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Screenshot hook filename boundary

The optional Unix screenshot hook invokes a trusted configured program through a
shell. Double quotes around its filename argument do not prevent command
substitution. Before this fix, a player name containing `$()` or backticks could
survive screenshot basename validation and execute shell syntax when an operator
requested a screenshot and `sv_screenshotArrivedCmd` was configured. The default
hook is empty. No production hook or exploit was invoked during verification.

Portable ASCII letters, digits, underscore and hyphen now survive basename
validation; other bytes become underscores. Normal player names and screenshot
numbering remain intact. The optional hook's configured program/path remains
trusted operator input; this change does not turn general process launch into a
sandbox. Replacing shell-based hooks with argument-vector process launch remains
a broader follow-up.

`tests/test_screenshot_security.py` executes the real sanitizer and evaluates only
a harmless printf through the same double-quoted Unix argument boundary. It covers
command substitution, backticks, Windows expansion tokens, quote delimiters,
separators and path/control characters. No game client or remote endpoint is used.
Rollback is a reviewed revert; do not restore the vulnerable sanitizer while the
optional hook is in use. Deployment and any hook configuration require separate
operator approval.
5 changes: 4 additions & 1 deletion src/sv_screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ void SV_SSFilename( int number, const char* basename, char *fileName ) {

char FilenameCharValidate(char k)
{
if(k <= ' ' || k == 0xff || k == '.' || k == '/' || k == '\\' || k == ':' || k == '*' || k == '?' || k == '\"' || k == '<' || k == '>' || k == '|')
/* Player-controlled basenames also reach the optional shell hook. Keep
* only portable literal filename bytes; quoting does not stop $()/backticks. */
if(!((k >= 'a' && k <= 'z') || (k >= 'A' && k <= 'Z') ||
(k >= '0' && k <= '9') || k == '_' || k == '-'))
{
return '_';
}
Expand Down
33 changes: 33 additions & 0 deletions tests/test_screenshot_security.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Execute real filename sanitizers and the optional Unix hook quoting boundary."""
from pathlib import Path
import subprocess
import tempfile
import unittest

ROOT = Path(__file__).resolve().parents[1]


class ScreenshotSecurity(unittest.TestCase):
def test_player_names_remain_literal_shell_arguments(self):
source = (ROOT / 'src/sv_screenshot.c').read_text()
functions = source[source.index('char FilenameCharValidate('):source.index('void SV_ScreenshotBuildName(')]
with tempfile.TemporaryDirectory() as directory:
fixture = Path(directory) / 'filename.c'
binary = Path(directory) / 'filename'
fixture.write_text('#include <stdio.h>\n' + functions +
'\nint main(int argc,char **argv) { if(argc!=2)return 1; ValidateFilename(argv[1]); puts(argv[1]); return 0; }\n')
subprocess.run(['cc', '-Wall', '-Wextra', '-Werror', str(fixture), '-o', str(binary)], check=True)
for name in ('Player-One_123', '$(printf${IFS}EXPANDED)', '`printf${IFS}EXPANDED`',
'%COMSPEC%!PATH!', '";printf EXPANDED;', 'a\\b/c\nname', '<svg/onload=x>'):
with self.subTest(name=name):
safe = subprocess.check_output([str(binary), name], text=True).strip()
# Same double-quoted filename argument as SV_ScreenshotArrived;
# only harmless printf runs, with no game/network/file effects.
result = subprocess.check_output(['/bin/sh', '-c', 'printf "%s" "' + safe + '"'], text=True)
self.assertEqual(result, safe)
self.assertRegex(safe, r'^[A-Za-z0-9_-]+$')
if name == 'Player-One_123': self.assertEqual(safe, name)


if __name__ == '__main__':
unittest.main()
Loading