attackmap-analyzer-node-service 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of attackmap-analyzer-node-service might be problematic. Click here for more details.

@@ -0,0 +1,3 @@
1
+ from .analyzer import NodeServiceAnalyzer
2
+
3
+ __all__ = ["NodeServiceAnalyzer"]
@@ -0,0 +1,284 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import re
5
+ from pathlib import Path
6
+ from urllib.parse import urlparse
7
+
8
+ from .contracts import AnalyzerMetadata, AuthHint, DatabaseHint, ExternalCall, Route, ScanResult, SecretHint
9
+
10
+ CODE_SUFFIXES = {".js", ".mjs", ".cjs", ".ts", ".tsx"}
11
+ SKIP_DIRS = {"node_modules", ".git", "dist", "build", ".next", ".turbo"}
12
+
13
+ EXPRESS_ROUTE_PATTERN = re.compile(
14
+ r"\b(?:app|router)\.(get|post|put|patch|delete|options|head)\(\s*['\"]([^'\"]+)['\"]",
15
+ re.IGNORECASE,
16
+ )
17
+ FASTIFY_ROUTE_PATTERN = re.compile(
18
+ r"\bfastify\.(get|post|put|patch|delete|options|head)\(\s*['\"]([^'\"]+)['\"]",
19
+ re.IGNORECASE,
20
+ )
21
+ ENTRYPOINT_PATTERNS = [
22
+ (re.compile(r"\bapp\.listen\s*\(", re.IGNORECASE), "entrypoint:express_listen"),
23
+ (re.compile(r"\bcreateServer\s*\(", re.IGNORECASE), "entrypoint:create_server"),
24
+ (re.compile(r"\bfastify\s*\(", re.IGNORECASE), "entrypoint:fastify_server"),
25
+ (re.compile(r"\bnew\s+Hono\s*\(", re.IGNORECASE), "entrypoint:hono_app"),
26
+ (re.compile(r"\bregisterHandler\b|\bregisterRoute\b", re.IGNORECASE), "entrypoint:handler_registration"),
27
+ ]
28
+
29
+ OUTBOUND_PATTERNS = [
30
+ re.compile(r"\bfetch\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
31
+ re.compile(r"\baxios\.(?:get|post|put|patch|delete)\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
32
+ re.compile(r"\bgot(?:\.(?:get|post|put|patch|delete))?\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
33
+ re.compile(r"\bundici\.(?:request|fetch)\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
34
+ ]
35
+ ENV_URL_PATTERN = re.compile(r"process\.env\.([A-Z0-9_]+_URL)\b")
36
+
37
+ DB_PATTERNS = [
38
+ (re.compile(r"\bnew\s+PrismaClient\s*\(", re.IGNORECASE), "sql"),
39
+ (re.compile(r"\bPool\s*\(\s*\{", re.IGNORECASE), "postgresql"),
40
+ (re.compile(r"\bpg\b|\bnode-postgres\b", re.IGNORECASE), "postgresql"),
41
+ (re.compile(r"\bknex\s*\(", re.IGNORECASE), "sql"),
42
+ (re.compile(r"\bmongoose\.connect\s*\(", re.IGNORECASE), "mongodb"),
43
+ (re.compile(r"\bMongoClient\s*\(", re.IGNORECASE), "mongodb"),
44
+ (re.compile(r"\bredis\.createClient\s*\(", re.IGNORECASE), "redis"),
45
+ (re.compile(r"\bioredis\b|\bnew\s+Redis\s*\(", re.IGNORECASE), "redis"),
46
+ (re.compile(r"\bS3Client\b|\bPutObjectCommand\b|\bGetObjectCommand\b", re.IGNORECASE), "object_storage"),
47
+ ]
48
+
49
+ AUTH_PATTERNS = [
50
+ (re.compile(r"\bAuthorization\b", re.IGNORECASE), "authorization_header"),
51
+ (re.compile(r"\bBearer\b", re.IGNORECASE), "bearer_token"),
52
+ (re.compile(r"\bjwt\b|\bjsonwebtoken\b", re.IGNORECASE), "jwt"),
53
+ (re.compile(r"\bverify\b\s*\(", re.IGNORECASE), "signature_verify"),
54
+ (re.compile(r"\bsign\b\s*\(", re.IGNORECASE), "signature_sign"),
55
+ (re.compile(r"\boauth\b|\boidc\b", re.IGNORECASE), "oauth"),
56
+ (re.compile(r"\btoken\b", re.IGNORECASE), "token"),
57
+ ]
58
+
59
+ SECRET_PATTERNS = [
60
+ re.compile(r"process\.env\.([A-Z0-9_]*(?:SECRET|TOKEN|KEY|PASSWORD)[A-Z0-9_]*)"),
61
+ ]
62
+
63
+
64
+ class NodeServiceAnalyzer:
65
+ metadata = AnalyzerMetadata(
66
+ name="node-service",
67
+ display_name="Node Service Analyzer",
68
+ version="0.1.0",
69
+ description="Broad Node.js/TypeScript service analyzer for distributed backend repositories.",
70
+ scope="Node/TypeScript backend service repos with service boundaries, handler registration, and inter-service calls.",
71
+ targets=["node-service", "node", "typescript-service"],
72
+ languages=["javascript", "typescript"],
73
+ priority=25,
74
+ experimental=True,
75
+ enabled_by_default=False,
76
+ )
77
+
78
+ @property
79
+ def name(self) -> str:
80
+ return self.metadata.name
81
+
82
+ def detect(self, repo_path: str | Path) -> bool:
83
+ root = Path(repo_path).resolve()
84
+ if not root.exists() or not root.is_dir():
85
+ return False
86
+
87
+ has_package = (root / "package.json").exists() or any(root.glob("**/package.json"))
88
+ has_typescript = (root / "tsconfig.json").exists() or any(root.glob("**/tsconfig.json"))
89
+ has_service_dirs = (root / "services").is_dir() or (root / "packages").is_dir()
90
+
91
+ if has_package and (has_typescript or has_service_dirs):
92
+ return True
93
+
94
+ for file_path in root.rglob("*"):
95
+ if not file_path.is_file() or file_path.suffix not in CODE_SUFFIXES:
96
+ continue
97
+ if any(part in SKIP_DIRS for part in file_path.parts):
98
+ continue
99
+ content = self._read_text(file_path)
100
+ if not content:
101
+ continue
102
+ if re.search(r"\bapp\.listen\b|\bfastify\b|\bcreateServer\b|\bservices?/|packages?/", content, re.IGNORECASE):
103
+ return True
104
+ return False
105
+
106
+ def analyze(self, repo_path: str | Path) -> ScanResult:
107
+ root = Path(repo_path).resolve()
108
+ result = ScanResult(root=str(root))
109
+ if not root.exists() or not root.is_dir():
110
+ return result
111
+
112
+ root_package_name = self._package_name_from(root / "package.json")
113
+ for file_path in root.rglob("*"):
114
+ if not file_path.is_file() or file_path.suffix not in CODE_SUFFIXES:
115
+ continue
116
+ if any(part in SKIP_DIRS for part in file_path.parts):
117
+ continue
118
+
119
+ result.files_scanned += 1
120
+ language = "typescript" if file_path.suffix in {".ts", ".tsx"} else "javascript"
121
+ if language not in result.languages:
122
+ result.languages.append(language)
123
+
124
+ content = self._read_text(file_path)
125
+ if content is None:
126
+ continue
127
+
128
+ relative = str(file_path.relative_to(root))
129
+ service_name = self._infer_service_name(relative, root_package_name)
130
+ service_role = self._infer_service_role(service_name, relative)
131
+
132
+ self._append_unique_auth(result, f"service_name:{service_name}", relative)
133
+ self._append_unique_auth(result, f"service_role:{service_role}", relative)
134
+
135
+ self._extract_routes(content, relative, result)
136
+ self._extract_entrypoint_hints(content, relative, result)
137
+ self._extract_outbound_and_edges(content, relative, service_name, result)
138
+ self._extract_datastore_hints(content, relative, result)
139
+ self._extract_auth_hints(content, relative, result)
140
+ self._extract_secret_hints(content, relative, result)
141
+
142
+ result.languages.sort()
143
+ return result
144
+
145
+ def _extract_routes(self, content: str, relative: str, result: ScanResult) -> None:
146
+ for match in EXPRESS_ROUTE_PATTERN.finditer(content):
147
+ method, path = match.group(1).upper(), match.group(2)
148
+ self._append_unique_route(result, path, method, relative)
149
+ for match in FASTIFY_ROUTE_PATTERN.finditer(content):
150
+ method, path = match.group(1).upper(), match.group(2)
151
+ self._append_unique_route(result, path, method, relative)
152
+
153
+ def _extract_entrypoint_hints(self, content: str, relative: str, result: ScanResult) -> None:
154
+ for pattern, hint in ENTRYPOINT_PATTERNS:
155
+ if pattern.search(content):
156
+ self._append_unique_auth(result, hint, relative)
157
+
158
+ def _extract_outbound_and_edges(self, content: str, relative: str, service_name: str, result: ScanResult) -> None:
159
+ for pattern in OUTBOUND_PATTERNS:
160
+ for match in pattern.finditer(content):
161
+ target = match.group(1)
162
+ self._append_unique_external(result, target, relative)
163
+ target_service = self._service_from_url(target)
164
+ if target_service:
165
+ self._append_unique_auth(result, f"edge:{service_name}->{target_service}", relative)
166
+
167
+ for match in ENV_URL_PATTERN.finditer(content):
168
+ env_name = match.group(1)
169
+ self._append_unique_external(result, f"env://{env_name}", relative)
170
+ target_service = self._service_from_env_name(env_name)
171
+ if target_service:
172
+ self._append_unique_auth(result, f"edge:{service_name}->{target_service}", relative)
173
+
174
+ def _extract_datastore_hints(self, content: str, relative: str, result: ScanResult) -> None:
175
+ for pattern, kind in DB_PATTERNS:
176
+ if pattern.search(content):
177
+ self._append_unique_database(result, kind, relative)
178
+
179
+ def _extract_auth_hints(self, content: str, relative: str, result: ScanResult) -> None:
180
+ for pattern, hint in AUTH_PATTERNS:
181
+ if pattern.search(content):
182
+ self._append_unique_auth(result, hint, relative)
183
+
184
+ def _extract_secret_hints(self, content: str, relative: str, result: ScanResult) -> None:
185
+ for pattern in SECRET_PATTERNS:
186
+ for match in pattern.finditer(content):
187
+ self._append_unique_secret(result, match.group(1), relative)
188
+
189
+ def _infer_service_name(self, relative: str, root_package_name: str | None) -> str:
190
+ normalized = relative.replace("\\", "/")
191
+ parts = normalized.split("/")
192
+ if len(parts) >= 2 and parts[0] in {"services", "packages"}:
193
+ return parts[1].lower()
194
+ if root_package_name:
195
+ return root_package_name.lower().split("/")[-1]
196
+ return "repo-service"
197
+
198
+ @staticmethod
199
+ def _infer_service_role(service_name: str, relative: str) -> str:
200
+ name = f"{service_name} {relative}".lower()
201
+ if any(token in name for token in {"api", "server", "gateway", "http"}):
202
+ return "api"
203
+ if any(token in name for token in {"worker", "queue", "job", "consumer"}):
204
+ return "worker"
205
+ if any(token in name for token in {"store", "db", "cache", "redis"}):
206
+ return "storage"
207
+ return "service"
208
+
209
+ @staticmethod
210
+ def _service_from_url(target: str) -> str | None:
211
+ try:
212
+ host = urlparse(target).hostname or ""
213
+ except ValueError:
214
+ return None
215
+ if not host:
216
+ return None
217
+ if host in {"localhost", "127.0.0.1"}:
218
+ return "local-service"
219
+ return host.split(".")[0].split("-")[0].lower()
220
+
221
+ @staticmethod
222
+ def _service_from_env_name(env_name: str) -> str | None:
223
+ token = env_name.upper().removesuffix("_URL")
224
+ if token.endswith("_SERVICE"):
225
+ token = token.removesuffix("_SERVICE")
226
+ token = token.replace("__", "_").strip("_")
227
+ if not token:
228
+ return None
229
+ return token.lower().replace("_", "-")
230
+
231
+ @staticmethod
232
+ def _package_name_from(path: Path) -> str | None:
233
+ if not path.exists():
234
+ return None
235
+ try:
236
+ data = json.loads(path.read_text(encoding="utf-8"))
237
+ except (UnicodeDecodeError, json.JSONDecodeError):
238
+ return None
239
+ name = data.get("name")
240
+ if isinstance(name, str) and name.strip():
241
+ return name.strip()
242
+ return None
243
+
244
+ @staticmethod
245
+ def _read_text(path: Path) -> str | None:
246
+ try:
247
+ return path.read_text(encoding="utf-8")
248
+ except UnicodeDecodeError:
249
+ return None
250
+
251
+ @staticmethod
252
+ def _append_unique_route(result: ScanResult, path: str, method: str, file: str) -> None:
253
+ key = (path, method, file)
254
+ if any((item.path, item.method, item.file) == key for item in result.routes):
255
+ return
256
+ result.routes.append(Route(path=path, method=method, file=file))
257
+
258
+ @staticmethod
259
+ def _append_unique_external(result: ScanResult, target: str, file: str) -> None:
260
+ key = (target, file)
261
+ if any((item.target, item.file) == key for item in result.external_calls):
262
+ return
263
+ result.external_calls.append(ExternalCall(target=target, file=file))
264
+
265
+ @staticmethod
266
+ def _append_unique_database(result: ScanResult, kind: str, file: str) -> None:
267
+ key = (kind, file)
268
+ if any((item.kind, item.file) == key for item in result.databases):
269
+ return
270
+ result.databases.append(DatabaseHint(kind=kind, file=file))
271
+
272
+ @staticmethod
273
+ def _append_unique_auth(result: ScanResult, hint: str, file: str) -> None:
274
+ key = (hint, file)
275
+ if any((item.hint, item.file) == key for item in result.auth_hints):
276
+ return
277
+ result.auth_hints.append(AuthHint(hint=hint, file=file))
278
+
279
+ @staticmethod
280
+ def _append_unique_secret(result: ScanResult, name: str, file: str) -> None:
281
+ key = (name, file)
282
+ if any((item.name, item.file) == key for item in result.secret_hints):
283
+ return
284
+ result.secret_hints.append(SecretHint(name=name, file=file))
@@ -0,0 +1,18 @@
1
+ from __future__ import annotations
2
+
3
+ from attackmap.sdk.contracts import AnalyzerMetadata, AnalyzerProtocol
4
+ from attackmap.sdk.models import AuthHint, DatabaseHint, ExternalCall, Route, ScanResult, SecretHint
5
+
6
+ # Compatibility alias used by existing analyzer implementations.
7
+ AttackMapAnalyzerProtocol = AnalyzerProtocol
8
+
9
+ __all__ = [
10
+ "AnalyzerMetadata",
11
+ "AttackMapAnalyzerProtocol",
12
+ "Route",
13
+ "ExternalCall",
14
+ "DatabaseHint",
15
+ "AuthHint",
16
+ "SecretHint",
17
+ "ScanResult",
18
+ ]
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackmap-analyzer-node-service
3
+ Version: 0.1.0
4
+ Summary: Broad Node.js/TypeScript service analyzer plugin for AttackMap
5
+ Author: AttackMap Contributors
6
+ Author-email: Matthew Davis <matthewd@matthewd.xyz>
7
+ Maintainer-email: Matthew Davis <matthewd@matthewd.xyz>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/mlaify/attackmap-analyzer-node-service
10
+ Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-node-service
11
+ Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-node-service/issues
12
+ Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-node-service/blob/main/CHANGELOG.md
13
+ Project-URL: AttackMap core, https://github.com/mlaify/AttackMap
14
+ Keywords: security,static-analysis,appsec,defensive-security,attackmap,attackmap-plugin
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Information Technology
18
+ Classifier: Intended Audience :: System Administrators
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3 :: Only
26
+ Classifier: Topic :: Security
27
+ Classifier: Topic :: Software Development :: Quality Assurance
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.11
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: pydantic>=2.7.0
33
+ Provides-Extra: core
34
+ Requires-Dist: attackmap>=0.1.0; extra == "core"
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
37
+ Requires-Dist: build>=1.2.0; extra == "dev"
38
+ Requires-Dist: attackmap>=0.1.0; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # AttackMap Node Service Analyzer
42
+
43
+ `attackmap-analyzer-node-service` is a broad Node.js/TypeScript backend analyzer module for AttackMap.
44
+
45
+ It is designed for distributed service repositories and emits structured scan signals for:
46
+ - service identity and role hints
47
+ - route and handler registration hints
48
+ - outbound HTTP and env-configured service URLs
49
+ - datastore and storage usage hints
50
+ - auth/signing/token hints
51
+ - lightweight inter-service edge hints
52
+
53
+ This analyzer is intentionally heuristic and incremental. It is not Bluesky-specific.
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ pip install git+https://github.com/mlaify/attackmap-analyzer-node-service.git
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ ```bash
64
+ attackmap analyze /path/to/repo --module node-service
65
+ ```
@@ -0,0 +1,9 @@
1
+ attackmap_analyzer_node_service/__init__.py,sha256=2f30LPbsX_sHS3g8Z3Gw2F2IQLm6KpfNpDQj3KWKUTw,77
2
+ attackmap_analyzer_node_service/analyzer.py,sha256=EDruEivasmvn9Fl8fAfuObLNLTOGUNIXUVsVvCnUltQ,12492
3
+ attackmap_analyzer_node_service/contracts.py,sha256=uwshWT7fHGD_lTg8LGS-4JxuHlRQJ7ejBS92Ls3p6Vc,496
4
+ attackmap_analyzer_node_service-0.1.0.dist-info/licenses/LICENSE,sha256=vtPQVGUyxq359j0JmD3_eJaXyHmaHyjzaMOtaLwJc88,1097
5
+ attackmap_analyzer_node_service-0.1.0.dist-info/METADATA,sha256=2SEUQhZb9S_nqEwPZe82wCJkf4_LmPZilI2S81ETr6A,2568
6
+ attackmap_analyzer_node_service-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ attackmap_analyzer_node_service-0.1.0.dist-info/entry_points.txt,sha256=PPfCR-i9If3fa2v7AgkM8Bule6pnvUGqDCkBqLvYEIk,89
8
+ attackmap_analyzer_node_service-0.1.0.dist-info/top_level.txt,sha256=DwrLiRQLyrae24-tVGmY5U58jy2evKwVV5h5_e3xXhc,32
9
+ attackmap_analyzer_node_service-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [attackmap.analyzers]
2
+ node_service = attackmap_analyzer_node_service:NodeServiceAnalyzer
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Davis and AttackMap Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ attackmap_analyzer_node_service