Skip to content

The agent that grows with you

fix(plugins): allow read-only /proc/self/cgroup and mountinfo in plugin guard

Sahil Vishnalya1bb5b3d67bbe
diff --git a/tests/tools/test_plugin_guard.py b/tests/tools/test_plugin_guard.py
index 4afe49c71e7..773df66a88b 100644
--- a/tests/tools/test_plugin_guard.py
+++ b/tests/tools/test_plugin_guard.py
@@ -959,6 +959,52 @@ class TestCatalogSweepFalsePositives:
assert hit is not None and hit.severity in ("high", "critical"), format_scan_report(result)
assert result.verdict in ("caution", "dangerous")
+
+class TestBenignProcIntrospection:
+ """#144123: /proc/self/cgroup and /proc/self/mountinfo are read by container CPU-quota
+ detection (and by language runtimes), so a read-only mention is not process
+ introspection. Writes, other proc paths and a bare /proc/self keep the finding."""
+
+ def test_container_layout_read_is_safe(self, tmp_path):
+ files = dict(BASE_FILES)
+ files["capacity.py"] = (
+ "from pathlib import Path\n\n"
+ "def container_layout():\n"
+ " return (\n"
+ ' Path("/proc/self/cgroup").read_text(),\n'
+ ' Path("/proc/self/mountinfo").read_text(),\n'
+ " )\n"
+ )
+ result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")
+ assert [f for f in result.findings if f.pattern_id == "proc_access"] == []
+ assert result.verdict == "safe", format_scan_report(result)
+
+ def test_doc_mention_is_safe(self, tmp_path):
+ files = {**BASE_FILES, "README.md": "# x\n\nReads /proc/self/cgroup for the CPU quota.\n"}
+ result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")
+ assert result.verdict == "safe", format_scan_report(result)
+
+ @pytest.mark.parametrize("line", [
+ 'Path("/proc/self/status").read_text()\n',
+ 'Path("/proc/1/cmdline").read_text()\n',
+ 'print(Path("/proc/self").read_text())\n',
+ '(Path("/proc/self/cgroup"), Path("/proc/self/status"))\n',
+ ])
+ def test_other_proc_paths_still_flag(self, tmp_path, line):
+ files = {**BASE_FILES, "probe.py": line}
+ result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")
+ hit = next((f for f in result.findings if f.pattern_id == "proc_access"), None)
+ assert hit is not None and hit.severity == "high", format_scan_report(result)
+
+ @pytest.mark.parametrize("line", [
+ 'Path("/proc/self/cgroup").write_text("x")\n',
+ 'handle = open("/proc/self/mountinfo", "w")\n',
+ ])
+ def test_writes_still_flag(self, tmp_path, line):
+ files = {**BASE_FILES, "writer.py": line}
+ result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")
+ hit = next((f for f in result.findings if f.pattern_id == "proc_access"), None)
+ assert hit is not None and hit.severity == "high", format_scan_report(result)
def test_scanner_version_contract(self):
# A bump un-blocks previously-quarantined packages; assert the contract (changed), not a literal.
assert PLUGIN_SCANNER_VERSION != "plugin-guard-v10"
diff --git a/tools/plugin_guard.py b/tools/plugin_guard.py
index bb1a334d75d..74bf2cfb8f9 100644
--- a/tools/plugin_guard.py
+++ b/tools/plugin_guard.py
@@ -11,6 +11,7 @@ needs confirmation, ``dangerous`` is blocked and ``--force`` does NOT override.
from __future__ import annotations
import ast
+import re
from datetime import datetime, timezone, UTC
from pathlib import Path
from typing import Iterator, List, Optional, Tuple
@@ -27,7 +28,7 @@ from tools.skills_guard import (
Finding, ScanResult, SUSPICIOUS_BINARY_EXTENSIONS, _determine_verdict, format_scan_report,
scan_file)
-PLUGIN_SCANNER_VERSION = "plugin-guard-v11"
+PLUGIN_SCANNER_VERSION = "plugin-guard-v12"
# Never scanned: VCS internals, caches, vendored envs.
EXCLUDED_DIRS = {
@@ -181,6 +182,8 @@ def _filter_findings(findings: list[Finding], rel_path: str, file_path: Path) ->
f.severity = DOC_PROSE_DEMOTIONS[f.pattern_id]
line = lines[f.line - 1] if 0 < f.line <= len(lines) else f.match
joined = logical_line(lines, f.line - 1) if 0 < f.line <= len(lines) else line
+ if f.pattern_id == "proc_access" and _is_benign_proc_read(joined):
+ continue
f.severity = _context_severity(f, rel_path, line, joined, doc_prose or locale_catalog, is_code,
locale_catalog)
if _is_defensive_documentation(f, rel_path):
@@ -203,6 +206,20 @@ def _filter_findings(findings: list[Finding], rel_path: str, file_path: Path) ->
_SEVERITY_RANK = {"low": 0, "medium": 1, "high": 2, "critical": 3}
+# /proc files every process may read about itself: cgroup membership and mount layout.
+# Container CPU-quota detection needs them to find the controller hierarchy, and language
+# runtimes read them for container resource discovery, so a read-only mention is not
+# process introspection (#144123). A write or any other /proc path keeps the finding.
+_BENIGN_PROC_PATHS = frozenset({"/proc/self/cgroup", "/proc/self/mountinfo"})
+_PROC_PATH_RE = re.compile(r"/proc/(?:self|\d+)/[\w.\-/]*")
+_PROC_WRITE_RE = re.compile(r"write_text|write_bytes|\.write\s*\(|open\s*\([^)]*['\"][wa]|>\s*/proc/")
+
+
+def _is_benign_proc_read(text: str) -> bool:
+ """True when every /proc path on *text* is the cgroup/mountinfo pair and none is written."""
+ paths = [m.group(0).rstrip("/") for m in _PROC_PATH_RE.finditer(text)]
+ return bool(paths) and all(p in _BENIGN_PROC_PATHS for p in paths) and not _PROC_WRITE_RE.search(text)
+
def _at_most(severity: str, cap: str) -> str:
"""Lower *severity* to *cap*; never raise it."""