Skip to content

The agent that grows with you

fix(security): allow emoji variation selectors

KoNit-Kfbc5df3c413f
diff --git a/tests/tools/test_tirith_security.py b/tests/tools/test_tirith_security.py
index 7efd02c1926..42f38bc1420 100644
--- a/tests/tools/test_tirith_security.py
+++ b/tests/tools/test_tirith_security.py
@@ -676,6 +676,49 @@ class TestAppTldSuppression:
assert result["action"] == "block"
+class TestEmojiVariationSelectorSuppression:
+ """Emoji presentation selectors must not require terminal approval."""
+
+ @patch("tools.tirith_security.subprocess.run")
+ @patch("tools.tirith_security._load_security_config")
+ def test_emoji_only_variation_selector_warn_is_downgraded(self, mock_cfg, mock_run):
+ mock_cfg.return_value = _CFG
+ findings = [{"rule_id": "variation_selector", "severity": "medium"}]
+ mock_run.return_value = _mock_run(2, _json_stdout(findings, "variation selector"))
+
+ result = check_command_security('ls "🗞️ Journal/"')
+
+ assert result == {"action": "allow", "findings": [], "summary": ""}
+
+ @pytest.mark.parametrize("command", ["printf 'a️'", "printf '0️'", "printf 'x󠄀'"])
+ @patch("tools.tirith_security.subprocess.run")
+ @patch("tools.tirith_security._load_security_config")
+ def test_non_emoji_or_non_fe0f_variation_selector_keeps_warn(self, mock_cfg, mock_run, command):
+ mock_cfg.return_value = _CFG
+ findings = [{"rule_id": "variation_selector", "severity": "medium"}]
+ mock_run.return_value = _mock_run(2, _json_stdout(findings, "variation selector"))
+
+ result = check_command_security(command)
+
+ assert result["action"] == "warn"
+ assert result["findings"] == findings
+
+ @patch("tools.tirith_security.subprocess.run")
+ @patch("tools.tirith_security._load_security_config")
+ def test_mixed_findings_keep_warn_for_emoji_path(self, mock_cfg, mock_run):
+ mock_cfg.return_value = _CFG
+ findings = [
+ {"rule_id": "variation_selector", "severity": "medium"},
+ {"rule_id": "shortened_url", "severity": "medium"},
+ ]
+ mock_run.return_value = _mock_run(2, _json_stdout(findings, "mixed"))
+
+ result = check_command_security('curl https://bit.ly/x --output "🗞️ Journal/file"')
+
+ assert result["action"] == "warn"
+ assert result["findings"] == findings
+
+
class TestIsAppTldFinding:
"""Unit tests for the _is_app_tld_finding helper."""
diff --git a/tools/tirith_security.py b/tools/tirith_security.py
index 8814e17f2d0..a1870999f7f 100644
--- a/tools/tirith_security.py
+++ b/tools/tirith_security.py
@@ -477,6 +477,8 @@ _EXIT_ACTIONS = {0: "allow", 1: "block", 2: "warn"}
_NO_DETAILS_SUMMARY = {
"block": "security issue detected (details unavailable)",
"warn": "security warning detected (details unavailable)"}
+_VARIATION_SELECTOR_16 = "\ufe0f"
+_EMOJI_PRESENTATION_BASE_RANGES = ((0x2600, 0x27BF), (0x1F000, 0x1FAFF))
def _verdict(action: str, summary: str = "", findings: list | None = None) -> dict:
@@ -548,6 +550,12 @@ def check_command_security(command: str) -> dict:
# known false positive and is downgraded to allow. Any other finding keeps the warn.
if action == "warn" and findings and all(_is_app_tld_finding(f) for f in findings):
return _verdict("allow")
+ # VS16 follows ordinary emoji-capable code points in standard emoji-presentation sequences.
+ # Preserve warnings for every other selector, including VS16 after text, because those can
+ # carry the steganographic payload that Tirith is intended to detect.
+ if action == "warn" and findings and all(_is_emoji_variation_selector_finding(f) for f in findings) \
+ and _has_only_emoji_presentation_selectors(command):
+ return _verdict("allow")
return _verdict(action, summary, findings)
@@ -558,3 +566,24 @@ def _is_app_tld_finding(finding: dict) -> bool:
return any(
val is not None and ".app" in str(val).lower()
for val in (finding.get(k) for k in ("value", "tld", "detail", "description", "message")))
+
+
+def _is_emoji_variation_selector_finding(finding: dict) -> bool:
+ """True only for the Tirith rule that reports variation selectors."""
+ return isinstance(finding, dict) and finding.get("rule_id") == "variation_selector"
+
+
+def _has_only_emoji_presentation_selectors(command: str) -> bool:
+ """Whether every variation selector is VS16 immediately after an emoji-capable base."""
+ selectors = ("\ufe00", "\U000e0100")
+ saw_selector = False
+ for idx, char in enumerate(command):
+ if not selectors[0] <= char <= "\ufe0f" and not selectors[1] <= char <= "\U000e01ef":
+ continue
+ saw_selector = True
+ if char != _VARIATION_SELECTOR_16 or idx == 0:
+ return False
+ base = ord(command[idx - 1])
+ if not any(start <= base <= end for start, end in _EMOJI_PRESENTATION_BASE_RANGES):
+ return False
+ return saw_selector