mcpscan-cli 0.21.0__tar.gz → 0.22.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.22.0}/PKG-INFO +8 -3
  2. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/README.md +1 -1
  3. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/__init__.py +1 -1
  4. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/drift.py +1 -1
  5. mcpscan_cli-0.22.0/mcpscan/rules/path_traversal.py +135 -0
  6. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan_cli.egg-info/PKG-INFO +8 -3
  7. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan_cli.egg-info/SOURCES.txt +1 -0
  8. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/pyproject.toml +7 -2
  9. mcpscan_cli-0.22.0/tests/test_rule_mcp007.py +107 -0
  10. mcpscan_cli-0.21.0/mcpscan/rules/path_traversal.py +0 -57
  11. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/LICENSE +0 -0
  12. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/__main__.py +0 -0
  13. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/cli.py +0 -0
  14. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/discover.py +0 -0
  15. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/findings.py +0 -0
  16. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/fixer.py +0 -0
  17. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/loaders.py +0 -0
  18. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/mcp_server.py +0 -0
  19. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/owasp.py +0 -0
  20. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/report.py +0 -0
  21. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/__init__.py +0 -0
  22. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/auth_gaps.py +0 -0
  23. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/base.py +0 -0
  24. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/command_injection.py +0 -0
  25. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/debug_endpoint.py +0 -0
  26. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/dom_trust.py +0 -0
  27. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/hooks.py +0 -0
  28. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/insecure_deser.py +0 -0
  29. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/insecure_transport.py +0 -0
  30. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/origin_check.py +0 -0
  31. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/permissions.py +0 -0
  32. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/policy_override.py +0 -0
  33. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/sdk_versions.py +0 -0
  34. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/secrets.py +0 -0
  35. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/server_auth.py +0 -0
  36. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/ssrf.py +0 -0
  37. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/tool_annotations.py +0 -0
  38. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/tool_poisoning.py +0 -0
  39. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/webfetch_domain.py +0 -0
  40. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/rules/workflow_injection.py +0 -0
  41. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/runtime/__init__.py +0 -0
  42. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/runtime/guard.py +0 -0
  43. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/runtime/provenance.py +0 -0
  44. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/runtime/rugpull.py +0 -0
  45. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/runtime/sanitizer.py +0 -0
  46. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/scanner.py +0 -0
  47. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan/suppress.py +0 -0
  48. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan_cli.egg-info/dependency_links.txt +0 -0
  49. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan_cli.egg-info/entry_points.txt +0 -0
  50. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/mcpscan_cli.egg-info/top_level.txt +0 -0
  51. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/setup.cfg +0 -0
  52. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_debug_endpoint.py +0 -0
  53. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_discover.py +0 -0
  54. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_dom_trust.py +0 -0
  55. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_drift.py +0 -0
  56. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_mcp_server.py +0 -0
  57. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_origin_check.py +0 -0
  58. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_rule_mcp001.py +0 -0
  59. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_rule_mcp015.py +0 -0
  60. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_runtime_guard.py +0 -0
  61. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_runtime_provenance.py +0 -0
  62. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_runtime_rugpull.py +0 -0
  63. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_runtime_sanitizer.py +0 -0
  64. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_scanner.py +0 -0
  65. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.0}/tests/test_server_auth.py +0 -0
  66. {mcpscan_cli-0.21.0 → mcpscan_cli-0.22.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.22.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.22.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,135 @@
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
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
+ TWO_PATH_SINKS = {("shutil", "copy"), ("shutil", "copy2"), ("shutil", "copyfile"),
34
+ ("shutil", "move"), ("os", "rename"), ("os", "replace")}
35
+
36
+
37
+ def _derived(value: ast.AST, tainted: set) -> bool:
38
+ """`p`, `Path(p)` or `os.path.abspath(p)` where p is tainted."""
39
+ if isinstance(value, ast.Name):
40
+ return value.id in tainted
41
+ if isinstance(value, ast.Call) and len(value.args) == 1:
42
+ fn = value.func
43
+ name = fn.id if isinstance(fn, ast.Name) else fn.attr if isinstance(fn, ast.Attribute) else ""
44
+ return name in ("Path", "abspath") and _derived(value.args[0], tainted)
45
+ return False
46
+
47
+
48
+ def _write_targets(call: ast.Call) -> List[ast.AST]:
49
+ """Path arguments of a filesystem write sink, or [] if `call` is not one."""
50
+ fn = call.func
51
+ if isinstance(fn, ast.Name) and fn.id == "open" and call.args:
52
+ mode = call.args[1] if len(call.args) > 1 else next(
53
+ (k.value for k in call.keywords if k.arg == "mode"), None)
54
+ if isinstance(mode, ast.Constant) and isinstance(mode.value, str) \
55
+ and set(mode.value) & set("wax+"):
56
+ return [call.args[0]]
57
+ return []
58
+ if not isinstance(fn, ast.Attribute):
59
+ return []
60
+ if fn.attr in ("write_text", "write_bytes"):
61
+ return [fn.value]
62
+ if isinstance(fn.value, ast.Name) and (fn.value.id, fn.attr) in TWO_PATH_SINKS:
63
+ return list(call.args[:2])
64
+ return []
65
+
66
+
67
+ def _param_write_lines(text: str) -> List[int]:
68
+ """Lines where a function writes to one of its own parameters with no base-dir check."""
69
+ try:
70
+ tree = ast.parse(text)
71
+ except (SyntaxError, ValueError):
72
+ return []
73
+ hits = set()
74
+ for fn in ast.walk(tree):
75
+ if not isinstance(fn, (ast.FunctionDef, ast.AsyncFunctionDef)):
76
+ continue
77
+ src = ast.get_source_segment(text, fn) or ""
78
+ if BOUNDARY_CALL.search(src) or (RESOLVE.search(src) and PREFIX_CHECK.search(src)):
79
+ continue
80
+ a = fn.args
81
+ tainted = {p.arg for p in a.posonlyargs + a.args + a.kwonlyargs} - {"self", "cls"}
82
+ assigns = sorted((n for n in ast.walk(fn) if isinstance(n, ast.Assign)),
83
+ key=lambda n: n.lineno)
84
+ for n in assigns:
85
+ if len(n.targets) == 1 and isinstance(n.targets[0], ast.Name) \
86
+ and _derived(n.value, tainted):
87
+ tainted.add(n.targets[0].id)
88
+ for n in ast.walk(fn):
89
+ if isinstance(n, ast.Call) and any(
90
+ isinstance(t, ast.Name) and t.id in tainted for t in _write_targets(n)):
91
+ hits.add(n.lineno)
92
+ return sorted(hits)
93
+
94
+
95
+ @register
96
+ class PathTraversal(Rule):
97
+ id = "MCP007"
98
+ name = "Path traversal in file tool"
99
+ severity = Severity.MEDIUM
100
+ owasp = "MCP05:2025" # Command Injection & Execution (untrusted-input-driven action)
101
+
102
+ def check(self, files: List[FileInfo]) -> List[Finding]:
103
+ out: List[Finding] = []
104
+ for f in by_kind(files, "source"):
105
+ is_py = f.ext == ".py"
106
+ sink = PY_OPEN if is_py else JS_OPEN
107
+ for i, line in enumerate(f.lines, start=1):
108
+ s = line.strip()
109
+ if s.startswith("#") or s.startswith("//"):
110
+ continue
111
+ if not sink.search(line):
112
+ continue
113
+ if INTERP.search(line):
114
+ sev = Severity.HIGH if TRAVERSAL.search(line) else Severity.MEDIUM
115
+ out.append(self.finding(
116
+ f, i, line,
117
+ title="File path built from untrusted input",
118
+ detail="Resolve the path and confirm it stays within an allowed base "
119
+ "directory (e.g. os.path.realpath + prefix check) before opening.",
120
+ severity=sev,
121
+ ))
122
+ if is_py:
123
+ seen = {x.line for x in out if x.path == f.relpath}
124
+ for i in _param_write_lines(f.text):
125
+ if i in seen:
126
+ continue
127
+ out.append(self.finding(
128
+ f, i, f.lines[i - 1],
129
+ title="Write to a caller-controlled path with no base-directory check",
130
+ detail="The written path is a function parameter. Resolve it and confirm it "
131
+ "stays inside an allowed base directory (Path.resolve() + "
132
+ "is_relative_to) before writing (CVE-2026-27825 shape).",
133
+ severity=Severity.HIGH,
134
+ ))
135
+ 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.22.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.22.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,107 @@
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 TestWindowOpenFalsePositive(unittest.TestCase):
96
+ def test_js_window_open_in_python_string_is_not_flagged(self):
97
+ self.assertEqual(_check(
98
+ 'html = f"""<script>window.open(\'\', \'_self\').close(); {status}</script>"""\n'
99
+ ), [])
100
+
101
+ def test_interpolated_open_is_still_flagged(self):
102
+ findings = _check('open("data/" + name).read()\n') # mcpscan: ignore[MCP007]
103
+ self.assertEqual(len(findings), 1)
104
+
105
+
106
+ if __name__ == "__main__":
107
+ unittest.main()
@@ -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