mcpscan-cli 0.21.0__tar.gz → 0.23.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/PKG-INFO +8 -3
  2. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/README.md +1 -1
  3. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/__init__.py +1 -1
  4. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/drift.py +1 -1
  5. mcpscan_cli-0.23.0/mcpscan/rules/path_traversal.py +187 -0
  6. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan_cli.egg-info/PKG-INFO +8 -3
  7. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan_cli.egg-info/SOURCES.txt +1 -0
  8. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/pyproject.toml +7 -2
  9. mcpscan_cli-0.23.0/tests/test_rule_mcp007.py +194 -0
  10. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_scanner.py +1 -1
  11. mcpscan_cli-0.21.0/mcpscan/rules/path_traversal.py +0 -57
  12. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/LICENSE +0 -0
  13. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/__main__.py +0 -0
  14. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/cli.py +0 -0
  15. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/discover.py +0 -0
  16. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/findings.py +0 -0
  17. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/fixer.py +0 -0
  18. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/loaders.py +0 -0
  19. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/mcp_server.py +0 -0
  20. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/owasp.py +0 -0
  21. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/report.py +0 -0
  22. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/__init__.py +0 -0
  23. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/auth_gaps.py +0 -0
  24. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/base.py +0 -0
  25. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/command_injection.py +0 -0
  26. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/debug_endpoint.py +0 -0
  27. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/dom_trust.py +0 -0
  28. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/hooks.py +0 -0
  29. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/insecure_deser.py +0 -0
  30. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/insecure_transport.py +0 -0
  31. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/origin_check.py +0 -0
  32. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/permissions.py +0 -0
  33. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/policy_override.py +0 -0
  34. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/sdk_versions.py +0 -0
  35. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/secrets.py +0 -0
  36. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/server_auth.py +0 -0
  37. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/ssrf.py +0 -0
  38. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/tool_annotations.py +0 -0
  39. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/tool_poisoning.py +0 -0
  40. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/webfetch_domain.py +0 -0
  41. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/rules/workflow_injection.py +0 -0
  42. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/runtime/__init__.py +0 -0
  43. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/runtime/guard.py +0 -0
  44. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/runtime/provenance.py +0 -0
  45. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/runtime/rugpull.py +0 -0
  46. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/runtime/sanitizer.py +0 -0
  47. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/scanner.py +0 -0
  48. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan/suppress.py +0 -0
  49. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan_cli.egg-info/dependency_links.txt +0 -0
  50. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan_cli.egg-info/entry_points.txt +0 -0
  51. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/mcpscan_cli.egg-info/top_level.txt +0 -0
  52. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/setup.cfg +0 -0
  53. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_debug_endpoint.py +0 -0
  54. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_discover.py +0 -0
  55. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_dom_trust.py +0 -0
  56. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_drift.py +0 -0
  57. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_mcp_server.py +0 -0
  58. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_origin_check.py +0 -0
  59. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_rule_mcp001.py +0 -0
  60. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_rule_mcp015.py +0 -0
  61. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_runtime_guard.py +0 -0
  62. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_runtime_provenance.py +0 -0
  63. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_runtime_rugpull.py +0 -0
  64. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_runtime_sanitizer.py +0 -0
  65. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_server_auth.py +0 -0
  66. {mcpscan_cli-0.21.0 → mcpscan_cli-0.23.0}/tests/test_workflow_injection.py +0 -0
@@ -1,15 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcpscan-cli
3
- Version: 0.21.0
3
+ Version: 0.23.0
4
4
  Summary: Supply-chain security scanner for MCP servers and Claude Code projects — catch tool-poisoning, command injection and risky permissions before you install.
5
- Author: glatinone
5
+ Author: Kiell Tampubolon
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/glatinone/mcpscan
8
8
  Project-URL: Issues, https://github.com/glatinone/mcpscan/issues
9
+ Project-URL: Changelog, https://github.com/glatinone/mcpscan/releases
10
+ Project-URL: Write-up, https://www.kielltampubolon.id/writing/mcp-security-guide/
9
11
  Keywords: mcp,security,scanner,supply-chain,claude,llm,prompt-injection,sast
10
12
  Classifier: Development Status :: 4 - Beta
11
13
  Classifier: Environment :: Console
12
14
  Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: License :: OSI Approved :: MIT License
13
17
  Classifier: Operating System :: OS Independent
14
18
  Classifier: Topic :: Security
15
19
  Classifier: Programming Language :: Python :: 3
@@ -17,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.9
17
21
  Classifier: Programming Language :: Python :: 3.10
18
22
  Classifier: Programming Language :: Python :: 3.11
19
23
  Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
20
25
  Requires-Python: >=3.9
21
26
  Description-Content-Type: text/markdown
22
27
  License-File: LICENSE
@@ -108,7 +113,7 @@ pip install -e .
108
113
  | **MCP004** | 🔓 Over-broad permissions | High–Critical | [MCP02:2025](#-owasp-mcp-top-10-mapping) | Wildcard grants (`Bash(*)`, `"*"`), `bypassPermissions`, auto-approve |
109
114
  | **MCP005** | 🔑 Leaked secrets | High–Critical | [MCP01:2025](#-owasp-mcp-top-10-mapping) | API keys / tokens committed into configs (auto-redacted in output) |
110
115
  | **MCP006** | 📦 Vulnerable SDK | High | [MCP04:2025](#-owasp-mcp-top-10-mapping) | Known-bad `@modelcontextprotocol/sdk` / `mcp` / `fastmcp` versions |
111
- | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input |
116
+ | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input; Python writes to a function parameter with no base-dir check |
112
117
  | **MCP008** | 🌐 SSRF | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | Outbound requests (`requests`, `fetch`, `axios`) to a URL built from input |
113
118
  | **MCP009** | 📦 Insecure deserialization | High–Critical | [MCP05:2025](#-owasp-mcp-top-10-mapping) | `pickle`/`marshal`/`yaml.load` (no SafeLoader), `node-serialize` on untrusted data |
114
119
  | **MCP010** | 🔐 Disabled TLS | High | [MCP07:2025](#-owasp-mcp-top-10-mapping) | `verify=False`, `rejectUnauthorized: false`, unverified SSL context |
@@ -84,7 +84,7 @@ pip install -e .
84
84
  | **MCP004** | 🔓 Over-broad permissions | High–Critical | [MCP02:2025](#-owasp-mcp-top-10-mapping) | Wildcard grants (`Bash(*)`, `"*"`), `bypassPermissions`, auto-approve |
85
85
  | **MCP005** | 🔑 Leaked secrets | High–Critical | [MCP01:2025](#-owasp-mcp-top-10-mapping) | API keys / tokens committed into configs (auto-redacted in output) |
86
86
  | **MCP006** | 📦 Vulnerable SDK | High | [MCP04:2025](#-owasp-mcp-top-10-mapping) | Known-bad `@modelcontextprotocol/sdk` / `mcp` / `fastmcp` versions |
87
- | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input |
87
+ | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input; Python writes to a function parameter with no base-dir check |
88
88
  | **MCP008** | 🌐 SSRF | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | Outbound requests (`requests`, `fetch`, `axios`) to a URL built from input |
89
89
  | **MCP009** | 📦 Insecure deserialization | High–Critical | [MCP05:2025](#-owasp-mcp-top-10-mapping) | `pickle`/`marshal`/`yaml.load` (no SafeLoader), `node-serialize` on untrusted data |
90
90
  | **MCP010** | 🔐 Disabled TLS | High | [MCP07:2025](#-owasp-mcp-top-10-mapping) | `verify=False`, `rejectUnauthorized: false`, unverified SSL context |
@@ -1,3 +1,3 @@
1
1
  """mcpscan — supply-chain security scanner for MCP servers and Claude Code projects."""
2
2
 
3
- __version__ = "0.21.0"
3
+ __version__ = "0.23.0"
@@ -100,7 +100,7 @@ def _save_baseline(path: str, servers: Dict[str, str]) -> None:
100
100
  parent = os.path.dirname(path)
101
101
  if parent:
102
102
  os.makedirs(parent, exist_ok=True)
103
- with open(path, "w", encoding="utf-8") as fh:
103
+ with open(path, "w", encoding="utf-8") as fh: # mcpscan: ignore[MCP007] baseline path is ours, not tool input
104
104
  json.dump({"version": 1, "servers": servers}, fh, indent=2, sort_keys=True)
105
105
 
106
106
 
@@ -0,0 +1,187 @@
1
+ """MCP007 — path traversal in file-reading tools.
2
+
3
+ A tool that opens a path built from its arguments lets a caller walk out of the
4
+ intended directory (``../../etc/passwd``) and read arbitrary files. We flag file
5
+ reads whose path is interpolated/concatenated rather than a constant literal.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import ast
11
+ import re
12
+ from typing import List, Tuple
13
+
14
+ from ..findings import Finding, Severity
15
+ from ..loaders import FileInfo, by_kind
16
+ from .base import Rule, register
17
+
18
+ # File-open sinks. `window.open(` is browser JS embedded in a Python string, not a file open.
19
+ PY_OPEN = re.compile(
20
+ r"(?<!window\.)\bopen\s*\(|\.read_text\s*\(|\.read_bytes\s*\(|send_file\s*\(|FileResponse\s*\(",
21
+ )
22
+ JS_OPEN = re.compile(
23
+ r"\bfs\.(?:readFile|readFileSync|createReadStream)\s*\(|\breadFile(?:Sync)?\s*\(",
24
+ )
25
+ # Path is dynamically built (concat / f-string / template / join with a var).
26
+ INTERP = re.compile(r"`[^`]*\$\{|\+\s*\w|f['\"]|\.format\(|os\.path\.join\([^)]*\b\w")
27
+ # Explicit traversal token sitting in a literal.
28
+ TRAVERSAL = re.compile(r"\.\./|\.\.\\")
29
+ # A function that does either of these is treated as confining its paths to a base dir.
30
+ BOUNDARY_CALL = re.compile(r"\w*(?:safe_path|validate_path)\w*\s*\(")
31
+ RESOLVE = re.compile(r"\b(?:realpath|resolve)\s*\(")
32
+ PREFIX_CHECK = re.compile(r"\b(?:startswith|is_relative_to|commonpath)\s*\(")
33
+ # Parameters that never carry caller input (pytest fixtures included).
34
+ NOT_CALLER_INPUT = {"self", "cls", "tmp_path", "tmpdir"}
35
+ TWO_PATH_SINKS = {("shutil", "copy"), ("shutil", "copy2"), ("shutil", "copyfile"),
36
+ ("shutil", "move"), ("os", "rename"), ("os", "replace")}
37
+
38
+
39
+ def _derived(value: ast.AST, tainted: set) -> bool:
40
+ """`p`, `p[k]`, `p.get(k)`, `base / p`, or Path/abspath/str/os.path.join over p, where p is tainted."""
41
+ if isinstance(value, ast.Name):
42
+ return value.id in tainted
43
+ if isinstance(value, ast.Subscript):
44
+ return _derived(value.value, tainted)
45
+ if isinstance(value, ast.BinOp) and isinstance(value.op, ast.Div):
46
+ return _derived(value.left, tainted) or _derived(value.right, tainted)
47
+ if isinstance(value, ast.Call):
48
+ fn = value.func
49
+ if isinstance(fn, ast.Attribute) and fn.attr == "get":
50
+ return _derived(fn.value, tainted)
51
+ name = fn.id if isinstance(fn, ast.Name) else fn.attr if isinstance(fn, ast.Attribute) else ""
52
+ return name in ("Path", "abspath", "str", "join") \
53
+ and any(_derived(a, tainted) for a in value.args)
54
+ return False
55
+
56
+
57
+ def _is_join(value: ast.AST) -> bool:
58
+ """`os.path.join(...)` or `base / name`: a path built onto a base directory."""
59
+ if isinstance(value, ast.BinOp):
60
+ return isinstance(value.op, ast.Div)
61
+ return isinstance(value, ast.Call) and isinstance(value.func, ast.Attribute) \
62
+ and value.func.attr == "join" and isinstance(value.func.value, ast.Attribute) \
63
+ and value.func.value.attr == "path"
64
+
65
+
66
+ def _write_targets(call: ast.Call) -> List[ast.AST]:
67
+ """Path arguments of a filesystem write sink, or [] if `call` is not one."""
68
+ fn = call.func
69
+ if isinstance(fn, ast.Name) and fn.id == "open" and call.args:
70
+ mode = call.args[1] if len(call.args) > 1 else next(
71
+ (k.value for k in call.keywords if k.arg == "mode"), None)
72
+ if isinstance(mode, ast.Constant) and isinstance(mode.value, str) \
73
+ and set(mode.value) & set("wax+"):
74
+ return [call.args[0]]
75
+ return []
76
+ if not isinstance(fn, ast.Attribute):
77
+ return []
78
+ if fn.attr in ("write_text", "write_bytes"):
79
+ return [fn.value]
80
+ if isinstance(fn.value, ast.Name) and (fn.value.id, fn.attr) in TWO_PATH_SINKS:
81
+ return list(call.args[:2])
82
+ return []
83
+
84
+
85
+ def _save_targets(call: ast.Call) -> List[ast.AST]:
86
+ """openpyxl/PIL-style `wb.save(path)`. One positional arg skips torch/np.save(obj, path).
87
+ Only a path joined in the same function counts: a helper handed a finished path
88
+ (`wb.save(filepath)`) is checked where that path is built."""
89
+ fn = call.func
90
+ if isinstance(fn, ast.Attribute) and fn.attr == "save" and len(call.args) == 1:
91
+ return [call.args[0]]
92
+ return []
93
+
94
+
95
+ def _param_write_lines(text: str) -> List[Tuple[int, bool]]:
96
+ """(line, is_builder) where a function writes to, or returns a path joined from, one of its
97
+ own parameters (or `arguments.get(...)`/`arguments[...]` of one) with no base-dir check."""
98
+ try:
99
+ tree = ast.parse(text)
100
+ except (SyntaxError, ValueError):
101
+ return []
102
+ hits = {}
103
+ for fn in ast.walk(tree):
104
+ if not isinstance(fn, (ast.FunctionDef, ast.AsyncFunctionDef)):
105
+ continue
106
+ src = ast.get_source_segment(text, fn) or ""
107
+ if BOUNDARY_CALL.search(src) or (RESOLVE.search(src) and PREFIX_CHECK.search(src)):
108
+ continue
109
+ a = fn.args
110
+ tainted = {p.arg for p in a.posonlyargs + a.args + a.kwonlyargs} - NOT_CALLER_INPUT
111
+ joined = set() # tainted names built with os.path.join or `/`
112
+ steps = sorted((n for n in ast.walk(fn) if isinstance(n, (ast.Assign, ast.For))),
113
+ key=lambda n: n.lineno)
114
+ for n in steps:
115
+ if isinstance(n, ast.For): # `for item in tainted_list` taints item
116
+ target, value = n.target, n.iter
117
+ else:
118
+ target, value = (n.targets[0] if len(n.targets) == 1 else None), n.value
119
+ if isinstance(target, ast.Name) and _derived(value, tainted):
120
+ tainted.add(target.id)
121
+ if _is_join(value) or _derived(value, joined):
122
+ joined.add(target.id)
123
+ for n in ast.walk(fn):
124
+ if isinstance(n, ast.Call) and (
125
+ any(_derived(t, tainted) for t in _write_targets(n))
126
+ or any(_derived(t, joined) or (_is_join(t) and _derived(t, tainted))
127
+ for t in _save_targets(n))):
128
+ hits[n.lineno] = False
129
+ elif isinstance(n, ast.Return) and n.value is not None and _is_join(n.value) \
130
+ and _derived(n.value, tainted):
131
+ hits.setdefault(n.lineno, True)
132
+ return sorted(hits.items())
133
+
134
+
135
+ @register
136
+ class PathTraversal(Rule):
137
+ id = "MCP007"
138
+ name = "Path traversal in file tool"
139
+ severity = Severity.MEDIUM
140
+ owasp = "MCP05:2025" # Command Injection & Execution (untrusted-input-driven action)
141
+
142
+ def check(self, files: List[FileInfo]) -> List[Finding]:
143
+ out: List[Finding] = []
144
+ for f in by_kind(files, "source"):
145
+ is_py = f.ext == ".py"
146
+ sink = PY_OPEN if is_py else JS_OPEN
147
+ for i, line in enumerate(f.lines, start=1):
148
+ s = line.strip()
149
+ if s.startswith("#") or s.startswith("//"):
150
+ continue
151
+ if not sink.search(line):
152
+ continue
153
+ if INTERP.search(line):
154
+ sev = Severity.HIGH if TRAVERSAL.search(line) else Severity.MEDIUM
155
+ out.append(self.finding(
156
+ f, i, line,
157
+ title="File path built from untrusted input",
158
+ detail="Resolve the path and confirm it stays within an allowed base "
159
+ "directory (e.g. os.path.realpath + prefix check) before opening.",
160
+ severity=sev,
161
+ ))
162
+ if is_py:
163
+ seen = {x.line for x in out if x.path == f.relpath}
164
+ for i, builder in _param_write_lines(f.text):
165
+ if i in seen:
166
+ continue
167
+ if builder:
168
+ out.append(self.finding(
169
+ f, i, f.lines[i - 1],
170
+ title="Path helper joins a caller-controlled name onto a base "
171
+ "directory with no containment check",
172
+ detail="os.path.join/`/` keep an absolute name and `../` walks out of "
173
+ "the base. Resolve the result and confirm it stays inside the "
174
+ "base (realpath + commonpath, or resolve() + is_relative_to) "
175
+ "before returning it (CVE-2026-40576 shape).",
176
+ severity=Severity.MEDIUM,
177
+ ))
178
+ continue
179
+ out.append(self.finding(
180
+ f, i, f.lines[i - 1],
181
+ title="Write to a caller-controlled path with no base-directory check",
182
+ detail="The written path is a function parameter. Resolve it and confirm it "
183
+ "stays inside an allowed base directory (Path.resolve() + "
184
+ "is_relative_to) before writing (CVE-2026-27825 shape).",
185
+ severity=Severity.HIGH,
186
+ ))
187
+ return out
@@ -1,15 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcpscan-cli
3
- Version: 0.21.0
3
+ Version: 0.23.0
4
4
  Summary: Supply-chain security scanner for MCP servers and Claude Code projects — catch tool-poisoning, command injection and risky permissions before you install.
5
- Author: glatinone
5
+ Author: Kiell Tampubolon
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/glatinone/mcpscan
8
8
  Project-URL: Issues, https://github.com/glatinone/mcpscan/issues
9
+ Project-URL: Changelog, https://github.com/glatinone/mcpscan/releases
10
+ Project-URL: Write-up, https://www.kielltampubolon.id/writing/mcp-security-guide/
9
11
  Keywords: mcp,security,scanner,supply-chain,claude,llm,prompt-injection,sast
10
12
  Classifier: Development Status :: 4 - Beta
11
13
  Classifier: Environment :: Console
12
14
  Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: License :: OSI Approved :: MIT License
13
17
  Classifier: Operating System :: OS Independent
14
18
  Classifier: Topic :: Security
15
19
  Classifier: Programming Language :: Python :: 3
@@ -17,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.9
17
21
  Classifier: Programming Language :: Python :: 3.10
18
22
  Classifier: Programming Language :: Python :: 3.11
19
23
  Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
20
25
  Requires-Python: >=3.9
21
26
  Description-Content-Type: text/markdown
22
27
  License-File: LICENSE
@@ -108,7 +113,7 @@ pip install -e .
108
113
  | **MCP004** | 🔓 Over-broad permissions | High–Critical | [MCP02:2025](#-owasp-mcp-top-10-mapping) | Wildcard grants (`Bash(*)`, `"*"`), `bypassPermissions`, auto-approve |
109
114
  | **MCP005** | 🔑 Leaked secrets | High–Critical | [MCP01:2025](#-owasp-mcp-top-10-mapping) | API keys / tokens committed into configs (auto-redacted in output) |
110
115
  | **MCP006** | 📦 Vulnerable SDK | High | [MCP04:2025](#-owasp-mcp-top-10-mapping) | Known-bad `@modelcontextprotocol/sdk` / `mcp` / `fastmcp` versions |
111
- | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input |
116
+ | **MCP007** | 📂 Path traversal | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | File reads (`open`, `fs.readFile`) whose path is built from tool input; Python writes to a function parameter with no base-dir check |
112
117
  | **MCP008** | 🌐 SSRF | Medium–High | [MCP05:2025](#-owasp-mcp-top-10-mapping) | Outbound requests (`requests`, `fetch`, `axios`) to a URL built from input |
113
118
  | **MCP009** | 📦 Insecure deserialization | High–Critical | [MCP05:2025](#-owasp-mcp-top-10-mapping) | `pickle`/`marshal`/`yaml.load` (no SafeLoader), `node-serialize` on untrusted data |
114
119
  | **MCP010** | 🔐 Disabled TLS | High | [MCP07:2025](#-owasp-mcp-top-10-mapping) | `verify=False`, `rejectUnauthorized: false`, unverified SSL context |
@@ -52,6 +52,7 @@ tests/test_drift.py
52
52
  tests/test_mcp_server.py
53
53
  tests/test_origin_check.py
54
54
  tests/test_rule_mcp001.py
55
+ tests/test_rule_mcp007.py
55
56
  tests/test_rule_mcp015.py
56
57
  tests/test_runtime_guard.py
57
58
  tests/test_runtime_provenance.py
@@ -4,17 +4,19 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "mcpscan-cli"
7
- version = "0.21.0"
7
+ version = "0.23.0"
8
8
  description = "Supply-chain security scanner for MCP servers and Claude Code projects — catch tool-poisoning, command injection and risky permissions before you install."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = { text = "MIT" }
12
- authors = [{ name = "glatinone" }]
12
+ authors = [{ name = "Kiell Tampubolon" }]
13
13
  keywords = ["mcp", "security", "scanner", "supply-chain", "claude", "llm", "prompt-injection", "sast"]
14
14
  classifiers = [
15
15
  "Development Status :: 4 - Beta",
16
16
  "Environment :: Console",
17
17
  "Intended Audience :: Developers",
18
+ "Intended Audience :: Information Technology",
19
+ "License :: OSI Approved :: MIT License",
18
20
  "Operating System :: OS Independent",
19
21
  "Topic :: Security",
20
22
  "Programming Language :: Python :: 3",
@@ -22,12 +24,15 @@ classifiers = [
22
24
  "Programming Language :: Python :: 3.10",
23
25
  "Programming Language :: Python :: 3.11",
24
26
  "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
25
28
  ]
26
29
  dependencies = [] # zero runtime dependencies — stdlib only
27
30
 
28
31
  [project.urls]
29
32
  Homepage = "https://github.com/glatinone/mcpscan"
30
33
  Issues = "https://github.com/glatinone/mcpscan/issues"
34
+ Changelog = "https://github.com/glatinone/mcpscan/releases"
35
+ "Write-up" = "https://www.kielltampubolon.id/writing/mcp-security-guide/"
31
36
 
32
37
  [project.scripts]
33
38
  mcpscan = "mcpscan.cli:main"
@@ -0,0 +1,194 @@
1
+ """Tests for MCP007 (path traversal), mcpscan/rules/path_traversal.py.
2
+
3
+ Regression coverage for CVE-2026-27825 (sooperset/mcp-atlassian <= 0.16.0):
4
+ download_attachment(url, target_path) wrote to `target_path`, a bare tool
5
+ parameter, with no base-directory check. The line-based check missed it because
6
+ nothing on the `open(...)` line was interpolated. v0.17.0 fixed it with
7
+ validate_safe_path(). Also covers a false positive from the same repo: browser
8
+ `window.open(` inside a Python HTML string.
9
+ """
10
+
11
+ import unittest
12
+
13
+ from mcpscan.findings import Severity
14
+ from mcpscan.loaders import FileInfo
15
+ from mcpscan.rules.path_traversal import PathTraversal
16
+
17
+ VULNERABLE = '''
18
+ import os
19
+
20
+ def download_attachment(self, url, target_path):
21
+ if not os.path.isabs(target_path):
22
+ target_path = os.path.abspath(target_path)
23
+ with open(target_path, "wb") as f:
24
+ f.write(b"x")
25
+ '''
26
+
27
+ FIXED = '''
28
+ import os
29
+ from .io import validate_safe_path
30
+
31
+ def download_attachment(self, url, target_path):
32
+ if not os.path.isabs(target_path):
33
+ target_path = os.path.abspath(target_path)
34
+ validate_safe_path(target_path)
35
+ with open(target_path, "wb") as f:
36
+ f.write(b"x")
37
+ '''
38
+
39
+
40
+ def _file(text, relpath="server.py"):
41
+ return FileInfo(
42
+ relpath=relpath, abspath=relpath, text=text, kind="source", in_dot_claude=False
43
+ )
44
+
45
+
46
+ def _check(text):
47
+ return PathTraversal().check([_file(text)])
48
+
49
+
50
+ class TestParamWriteSink(unittest.TestCase):
51
+ def test_cve_2026_27825_shape_is_flagged(self):
52
+ findings = _check(VULNERABLE)
53
+ self.assertEqual([f.line for f in findings], [7])
54
+ self.assertEqual(findings[0].severity, Severity.HIGH)
55
+
56
+ def test_validate_safe_path_fix_is_clean(self):
57
+ self.assertEqual(_check(FIXED), [])
58
+
59
+ def test_resolve_plus_prefix_check_is_clean(self):
60
+ self.assertEqual(_check(
61
+ "from pathlib import Path\n"
62
+ "def save(p, data):\n"
63
+ " q = Path(p).resolve()\n"
64
+ " if not q.is_relative_to(BASE):\n"
65
+ " raise ValueError(p)\n"
66
+ " q.write_bytes(data)\n"
67
+ ), [])
68
+
69
+ def test_path_derived_write_text_and_shutil_are_flagged(self):
70
+ findings = _check(
71
+ "import shutil\nfrom pathlib import Path\n"
72
+ "def save(dest, src):\n"
73
+ " out = Path(dest)\n"
74
+ " out.write_text('x')\n"
75
+ " shutil.copy(src, dest)\n"
76
+ )
77
+ self.assertEqual([f.line for f in findings], [5, 6])
78
+
79
+ def test_read_mode_and_mkdir_are_not_write_sinks(self):
80
+ self.assertEqual(_check(
81
+ "from pathlib import Path\n"
82
+ "def load(p):\n"
83
+ " Path(p).mkdir(parents=True)\n"
84
+ " return open(p, 'rb').read()\n"
85
+ ), [])
86
+
87
+ def test_non_parameter_path_is_not_flagged(self):
88
+ self.assertEqual(_check(
89
+ "def save(data):\n"
90
+ " with open('out.json', 'w') as f:\n"
91
+ " f.write(data)\n"
92
+ ), [])
93
+
94
+
95
+ class TestJoinedAndArgumentPaths(unittest.TestCase):
96
+ """CVE-2026-44336 (PraisonAI rules_create), CVE-2026-84201 (appium-mcp-server write_file /
97
+ write_files_batch), CVE-2026-40576 (excel-mcp-server get_excel_path)."""
98
+
99
+ def test_join_then_open_write_is_flagged(self):
100
+ findings = _check(
101
+ "import os\n"
102
+ "def rules_create(rule_name, content):\n"
103
+ " rule_path = os.path.join(RULES_DIR, rule_name)\n"
104
+ " with open(rule_path, 'w') as f:\n"
105
+ " f.write(content)\n"
106
+ )
107
+ self.assertEqual([f.line for f in findings], [4])
108
+ self.assertEqual(findings[0].severity, Severity.HIGH)
109
+
110
+ def test_join_with_commonpath_check_is_clean(self):
111
+ self.assertEqual(_check(
112
+ "import os\n"
113
+ "def rules_create(rule_name, content):\n"
114
+ " rule_path = os.path.realpath(os.path.join(RULES_DIR, rule_name))\n"
115
+ " if os.path.commonpath([RULES_DIR, rule_path]) != RULES_DIR:\n"
116
+ " raise ValueError(rule_name)\n"
117
+ " with open(rule_path, 'w') as f:\n"
118
+ " f.write(content)\n"
119
+ ), [])
120
+
121
+ def test_arguments_get_and_batch_loop_are_flagged(self):
122
+ findings = _check(
123
+ "async def handle_call_tool(name, arguments):\n"
124
+ " path = arguments.get('path')\n"
125
+ " target = PROJECT_ROOT / path\n"
126
+ " with open(target, 'w') as f:\n"
127
+ " f.write(arguments['content'])\n"
128
+ "async def write_batch(arguments):\n"
129
+ " for file in arguments.get('files', []):\n"
130
+ " (PROJECT_ROOT / file['path']).write_text(file['content'])\n"
131
+ )
132
+ self.assertEqual([f.line for f in findings], [4, 8])
133
+
134
+ def test_arguments_get_with_resolve_check_is_clean(self):
135
+ self.assertEqual(_check(
136
+ "async def handle_call_tool(name, arguments):\n"
137
+ " target = (PROJECT_ROOT / arguments['path']).resolve()\n"
138
+ " if not target.is_relative_to(PROJECT_ROOT):\n"
139
+ " raise ValueError('outside project')\n"
140
+ " target.write_text(arguments['content'])\n"
141
+ ), [])
142
+
143
+ def test_path_builder_helper_is_flagged(self):
144
+ findings = _check(
145
+ "import os\n"
146
+ "def get_excel_path(filename):\n"
147
+ " if os.path.isabs(filename):\n"
148
+ " return filename\n"
149
+ " return os.path.join(EXCEL_FILES_PATH, filename)\n"
150
+ )
151
+ self.assertEqual([f.line for f in findings], [5])
152
+ self.assertEqual(findings[0].severity, Severity.MEDIUM)
153
+
154
+ def test_path_builder_with_containment_check_is_clean(self):
155
+ self.assertEqual(_check(
156
+ "import os\n"
157
+ "def get_excel_path(filename):\n"
158
+ " base = os.path.realpath(EXCEL_FILES_PATH)\n"
159
+ " p = os.path.realpath(os.path.join(base, filename))\n"
160
+ " if os.path.commonpath([base, p]) != base:\n"
161
+ " raise ValueError(filename)\n"
162
+ " return p\n"
163
+ ), [])
164
+
165
+ def test_save_of_joined_path_is_flagged_but_not_a_handed_in_path(self):
166
+ findings = _check(
167
+ "import os\n"
168
+ "def export(wb, name):\n"
169
+ " wb.save(os.path.join(OUT_DIR, name))\n"
170
+ "def write_data(filepath, wb):\n"
171
+ " wb.save(filepath)\n"
172
+ )
173
+ self.assertEqual([f.line for f in findings], [3])
174
+
175
+ def test_pytest_tmp_path_is_not_caller_input(self):
176
+ self.assertEqual(_check(
177
+ "def test_upload(tmp_path):\n"
178
+ " (tmp_path / 'a.txt').write_text('x')\n"
179
+ ), [])
180
+
181
+
182
+ class TestWindowOpenFalsePositive(unittest.TestCase):
183
+ def test_js_window_open_in_python_string_is_not_flagged(self):
184
+ self.assertEqual(_check(
185
+ 'html = f"""<script>window.open(\'\', \'_self\').close(); {status}</script>"""\n'
186
+ ), [])
187
+
188
+ def test_interpolated_open_is_still_flagged(self):
189
+ findings = _check('open("data/" + name).read()\n') # mcpscan: ignore[MCP007]
190
+ self.assertEqual(len(findings), 1)
191
+
192
+
193
+ if __name__ == "__main__":
194
+ unittest.main()
@@ -392,7 +392,7 @@ class TestFixer(unittest.TestCase):
392
392
  # readable/writable after this helper returns (see apply_fixes tests).
393
393
  tmp = tempfile.mkdtemp()
394
394
  abspath = os.path.join(tmp, relpath)
395
- with open(abspath, "w", encoding="utf-8") as fh:
395
+ with open(abspath, "w", encoding="utf-8") as fh: # mcpscan: ignore[MCP007]
396
396
  fh.write(text)
397
397
  f = FileInfo(relpath=relpath, abspath=abspath, text=text,
398
398
  kind="source", in_dot_claude=False)
@@ -1,57 +0,0 @@
1
- """MCP007 — path traversal in file-reading tools.
2
-
3
- A tool that opens a path built from its arguments lets a caller walk out of the
4
- intended directory (``../../etc/passwd``) and read arbitrary files. We flag file
5
- reads whose path is interpolated/concatenated rather than a constant literal.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import re
11
- from typing import List
12
-
13
- from ..findings import Finding, Severity
14
- from ..loaders import FileInfo, by_kind
15
- from .base import Rule, register
16
-
17
- # File-open sinks.
18
- PY_OPEN = re.compile(
19
- r"\bopen\s*\(|\.read_text\s*\(|\.read_bytes\s*\(|send_file\s*\(|FileResponse\s*\(",
20
- )
21
- JS_OPEN = re.compile(
22
- r"\bfs\.(?:readFile|readFileSync|createReadStream)\s*\(|\breadFile(?:Sync)?\s*\(",
23
- )
24
- # Path is dynamically built (concat / f-string / template / join with a var).
25
- INTERP = re.compile(r"`[^`]*\$\{|\+\s*\w|f['\"]|\.format\(|os\.path\.join\([^)]*\b\w")
26
- # Explicit traversal token sitting in a literal.
27
- TRAVERSAL = re.compile(r"\.\./|\.\.\\")
28
-
29
-
30
- @register
31
- class PathTraversal(Rule):
32
- id = "MCP007"
33
- name = "Path traversal in file tool"
34
- severity = Severity.MEDIUM
35
- owasp = "MCP05:2025" # Command Injection & Execution (untrusted-input-driven action)
36
-
37
- def check(self, files: List[FileInfo]) -> List[Finding]:
38
- out: List[Finding] = []
39
- for f in by_kind(files, "source"):
40
- is_py = f.ext == ".py"
41
- sink = PY_OPEN if is_py else JS_OPEN
42
- for i, line in enumerate(f.lines, start=1):
43
- s = line.strip()
44
- if s.startswith("#") or s.startswith("//"):
45
- continue
46
- if not sink.search(line):
47
- continue
48
- if INTERP.search(line):
49
- sev = Severity.HIGH if TRAVERSAL.search(line) else Severity.MEDIUM
50
- out.append(self.finding(
51
- f, i, line,
52
- title="File path built from untrusted input",
53
- detail="Resolve the path and confirm it stays within an allowed base "
54
- "directory (e.g. os.path.realpath + prefix check) before opening.",
55
- severity=sev,
56
- ))
57
- return out
File without changes
File without changes