fix: harden native store handoffs

This commit is contained in:
Kurt Himebauch committed 2026-10-28 19:04:31 -04:00
1 parent ab7390e844
commit 090b87c37c
16 files changed
+161 -68

No files matched your search

@@ -1074,8 +1074,8 @@ def handle(agent_dir, req):
return steam_selection(agent_dir, request_timeout(req, 5))
if kind == "steam-url":
url = req.get("url")
if not isinstance(url, str) or not re.fullmatch(
r"steam://(?:open/downloads|uninstall/[1-9][0-9]{0,9})", url):
match = re.fullmatch(r"steam://(?:open/downloads|uninstall/([1-9][0-9]{0,9}))", url) if isinstance(url, str) else None
if match is None or (match.group(1) is not None and int(match.group(1)) > 0xFFFFFFFF):
raise AgentError("INVALID_REQUEST", "Steam navigation URL is not supported")
wait_for_steam_ui(agent_dir, req.get("timeout", 120))
try:
@@ -125,6 +125,9 @@ nap() {
[ -n "${bl_nap_fd:-}" ] || exec {bl_nap_fd}<> <(:)
read -r -t "$1" -u "$bl_nap_fd" _ 2>/dev/null || :
}
steam_uninstall_id_valid() {
[[ ${1:-} =~ ^[1-9][0-9]{0,9}$ ]] && [ "$1" -le 4294967295 ]
}
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
@@ -1176,13 +1179,12 @@ BUSCONF
if [ -f "$BL_LAUNCH_DIR/steam-uninstall" ]; then
uninstall_id=$(cat "$BL_LAUNCH_DIR/steam-uninstall" 2>/dev/null)
rm -f "$BL_LAUNCH_DIR/steam-uninstall"
case $uninstall_id in
''|0*|*[!0-9]*|???????????*) echo "== steam: ignored invalid uninstall request" ;;
*)
echo "== steam: opening the uninstall dialog for $uninstall_id"
"${steam_client[@]}" "steam://uninstall/$uninstall_id" >/dev/null 2>&1 &
;;
esac
if steam_uninstall_id_valid "$uninstall_id"; then
echo "== steam: opening the uninstall dialog for $uninstall_id"
"${steam_client[@]}" "steam://uninstall/$uninstall_id" >/dev/null 2>&1 &
else
echo "== steam: ignored invalid uninstall request"
fi
fi
if [ -f "$BL_LAUNCH_DIR/steam-game" ]; then
game_id=$(cat "$BL_LAUNCH_DIR/steam-game" 2>/dev/null)
+8 -1
View File
@@ -205,6 +205,12 @@ class AgentTest(unittest.TestCase):
self.assertEqual(["steam", "steam://open/downloads"], popen.call_args.args[0])
self.assertTrue(popen.call_args.kwargs["start_new_session"])
def test_steam_url_accepts_maximum_uint32_uninstall_id(self):
with patch.object(agent, "wait_for_steam_ui"), patch.object(agent.subprocess, "Popen") as popen:
answer = self.ask({"kind": "steam-url", "url": "steam://uninstall/4294967295"})
self.assertTrue(answer["ok"])
self.assertEqual(["steam", "steam://uninstall/4294967295"], popen.call_args.args[0])
def test_steam_url_waits_for_initialized_ui_router(self):
with patch.object(agent, "cdp_eval", side_effect=[OSError("DevTools restarted"),
{"value": False}, {"value": True}]) as evaluate, \
@@ -222,7 +228,8 @@ class AgentTest(unittest.TestCase):
popen.assert_not_called()
def test_steam_url_rejects_untrusted_routes_and_argument_injection(self):
for url in ("steam://open/settings", "steam://nav/library", "steam://open/downloads\n--exec", "https://example.com"):
for url in ("steam://open/settings", "steam://nav/library", "steam://uninstall/4294967296",
"steam://open/downloads\n--exec", "https://example.com"):
with self.subTest(url=url), patch.object(agent.subprocess, "Popen") as popen:
answer = self.ask({"kind": "steam-url", "url": url})
self.assertFalse(answer["ok"])
+13
View File
@@ -1,6 +1,7 @@
"""Retry a dropped shortcut without duplicating a launch that is still preparing its first window."""
import os
from pathlib import Path
import re
import subprocess
import tempfile
import textwrap
@@ -16,6 +17,18 @@ SHORTCUT = str((3551182975 << 32) | 0x02000000)
class SteamColdLaunchTest(unittest.TestCase):
def test_uninstall_id_uses_the_steam_app_id_range(self):
match = re.search(r"^steam_uninstall_id_valid\(\) \{.*?^}", SOURCE, re.M | re.S)
self.assertIsNotNone(match)
for app_id, expected in (("1", True), ("4294967295", True), ("4294967296", False),
("0", False), ("01", False), ("10000000000", False)):
with self.subTest(app_id=app_id):
result = subprocess.run(
["bash", "-c", f'{match.group(0)}\nsteam_uninstall_id_valid "$1"', "test", app_id],
capture_output=True,
)
self.assertEqual(expected, result.returncode == 0)
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)