The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): ignore traversal in markdown links
Puvaan Raajb259f2401da7
diff --git a/tests/tools/test_skills_guard.py b/tests/tools/test_skills_guard.pyindex c038d571ad4..0a70bb2bb4e 100644--- a/tests/tools/test_skills_guard.py+++ b/tests/tools/test_skills_guard.py@@ -407,6 +407,31 @@ class TestUnicodeCharName:class TestFalsePositiveReductions:"""Patterns that previously flagged benign, intrinsic skill content."""+ def test_markdown_link_destination_is_not_path_traversal(self, tmp_path):+ skill_dir = tmp_path / "linked-skill"+ skill_dir.mkdir()+ (skill_dir / "SKILL.md").write_text("# Linked skill\n", encoding="utf-8")+ readme = skill_dir / "README.md"+ readme.write_text(+ "See the [repository guide](../../../docs/guide.md).\n",+ encoding="utf-8",+ )+ result = scan_skill(skill_dir, source="community")++ assert result.verdict == "safe"+ assert should_allow_install(result)[0] is True+ assert not any(finding.category == "traversal" for finding in result.findings)++ script = skill_dir / "read.py"+ script.write_text(+ "data = Path('../../../outside.txt').read_text()\n",+ encoding="utf-8",+ )++ assert any(+ finding.pattern_id == "path_traversal_deep" for finding in scan_file(script, "read.py")+ )+def test_cat_write_heredoc_is_not_a_secrets_read(self, tmp_path):# Setup doc telling the user to write their OWN keys into their OWN# local .env via a heredoc — writes in, does not exfiltrate out.diff --git a/tools/skills_guard.py b/tools/skills_guard.pyindex 380ac4f0790..2cb873b7d47 100644--- a/tools/skills_guard.py+++ b/tools/skills_guard.py@@ -458,6 +458,7 @@ _INVISIBLE_CHAR_NAMES = {'\u202d': "LTR override", '\u202e': "RTL override", '\u2066': "LTR isolate", '\u2067': "RTL isolate",'\u2068': "first strong isolate", '\u2069': "pop directional isolate"}INVISIBLE_CHARS = set(_INVISIBLE_CHAR_NAMES)+_PATH_TRAVERSAL_PATTERN_IDS = {"path_traversal", "path_traversal_deep"}def _unicode_char_name(char: str) -> str:@@ -478,6 +479,39 @@ def _compute_docstring_lines(lines: list) -> set:return doc_lines+def _mask_markdown_link_destinations(line: str) -> str:+ """Blank balanced inline-link destinations while preserving line offsets.++ A relative Markdown destination describes documentation structure; it does+ not cause filesystem access. Nested parentheses and escaped characters are+ handled so a later, non-link traversal on the same line remains scannable.+ """+ masked = list(line)+ search_from = 0+ while (start := line.find("](", search_from)) != -1:+ depth = 1+ escaped = False+ cursor = start + 2+ while cursor < len(line):+ char = line[cursor]+ if escaped:+ escaped = False+ elif char == "\\":+ escaped = True+ elif char == "(":+ depth += 1+ elif char == ")":+ depth -= 1+ if depth == 0:+ masked[start + 2:cursor] = " " * (cursor - start - 2)+ search_from = cursor + 1+ break+ cursor += 1+ else:+ break+ return "".join(masked)++def scan_file(file_path: Path, rel_path: str = "") -> List[Finding]:"""Threat-pattern + invisible-unicode scan of one file; *rel_path* is the display path (default: filename). Regex findings dedupe per pattern per line; invisible chars yield one per line."""@@ -490,10 +524,13 @@ def scan_file(file_path: Path, rel_path: str = "") -> List[Finding]:return []findings = []docstring_lines = _compute_docstring_lines(lines) # so code patterns don't fire on prose+ traversal_lines = ([_mask_markdown_link_destinations(line) for line in lines]+ if file_path.suffix.lower() == ".md" else lines)suffix, owners = file_path.suffix.lower(), _statement_owners(lines) # per-file context for the demotionfor pattern, pid, severity, category, description in _COMPILED_THREAT_PATTERNS:for i, line in enumerate(lines, start=1):- if i not in docstring_lines and pattern.search(line):+ scan_line = traversal_lines[i - 1] if pid in _PATH_TRAVERSAL_PATTERN_IDS else line+ if i not in docstring_lines and pattern.search(scan_line):text = line.strip()line_severity, line_description = _demote_inert_path_reference(pid, severity, description, line, lines[owners[i - 1]], suffix)