attackmap-analyzer-node-service 0.1.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.
Potentially problematic release.
This version of attackmap-analyzer-node-service might be problematic. Click here for more details.
- attackmap_analyzer_node_service-0.1.0/LICENSE +21 -0
- attackmap_analyzer_node_service-0.1.0/PKG-INFO +65 -0
- attackmap_analyzer_node_service-0.1.0/README.md +25 -0
- attackmap_analyzer_node_service-0.1.0/pyproject.toml +74 -0
- attackmap_analyzer_node_service-0.1.0/setup.cfg +4 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service/__init__.py +3 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service/analyzer.py +284 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service/contracts.py +18 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/PKG-INFO +65 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/SOURCES.txt +13 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/dependency_links.txt +1 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/entry_points.txt +2 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/requires.txt +9 -0
- attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/top_level.txt +1 -0
- attackmap_analyzer_node_service-0.1.0/tests/test_node_service_analyzer.py +74 -0
|
@@ -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,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,25 @@
|
|
|
1
|
+
# AttackMap Node Service Analyzer
|
|
2
|
+
|
|
3
|
+
`attackmap-analyzer-node-service` is a broad Node.js/TypeScript backend analyzer module for AttackMap.
|
|
4
|
+
|
|
5
|
+
It is designed for distributed service repositories and emits structured scan signals for:
|
|
6
|
+
- service identity and role hints
|
|
7
|
+
- route and handler registration hints
|
|
8
|
+
- outbound HTTP and env-configured service URLs
|
|
9
|
+
- datastore and storage usage hints
|
|
10
|
+
- auth/signing/token hints
|
|
11
|
+
- lightweight inter-service edge hints
|
|
12
|
+
|
|
13
|
+
This analyzer is intentionally heuristic and incremental. It is not Bluesky-specific.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install git+https://github.com/mlaify/attackmap-analyzer-node-service.git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
attackmap analyze /path/to/repo --module node-service
|
|
25
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "attackmap-analyzer-node-service"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Broad Node.js/TypeScript service analyzer plugin for AttackMap"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Matthew Davis", email = "matthewd@matthewd.xyz"},
|
|
14
|
+
{name = "AttackMap Contributors"},
|
|
15
|
+
]
|
|
16
|
+
maintainers = [
|
|
17
|
+
{name = "Matthew Davis", email = "matthewd@matthewd.xyz"},
|
|
18
|
+
]
|
|
19
|
+
keywords = [
|
|
20
|
+
"security",
|
|
21
|
+
"static-analysis",
|
|
22
|
+
"appsec",
|
|
23
|
+
"defensive-security",
|
|
24
|
+
"attackmap",
|
|
25
|
+
"attackmap-plugin",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Intended Audience :: Information Technology",
|
|
31
|
+
"Intended Audience :: System Administrators",
|
|
32
|
+
"License :: OSI Approved :: MIT License",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
39
|
+
"Topic :: Security",
|
|
40
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
41
|
+
"Typing :: Typed",
|
|
42
|
+
]
|
|
43
|
+
dependencies = [
|
|
44
|
+
"pydantic>=2.7.0",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
core = [
|
|
49
|
+
"attackmap>=0.1.0",
|
|
50
|
+
]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8.0.0",
|
|
53
|
+
"build>=1.2.0",
|
|
54
|
+
"attackmap>=0.1.0",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[project.urls]
|
|
58
|
+
Homepage = "https://github.com/mlaify/attackmap-analyzer-node-service"
|
|
59
|
+
Repository = "https://github.com/mlaify/attackmap-analyzer-node-service"
|
|
60
|
+
Issues = "https://github.com/mlaify/attackmap-analyzer-node-service/issues"
|
|
61
|
+
Changelog = "https://github.com/mlaify/attackmap-analyzer-node-service/blob/main/CHANGELOG.md"
|
|
62
|
+
"AttackMap core" = "https://github.com/mlaify/AttackMap"
|
|
63
|
+
|
|
64
|
+
[project.entry-points."attackmap.analyzers"]
|
|
65
|
+
node_service = "attackmap_analyzer_node_service:NodeServiceAnalyzer"
|
|
66
|
+
|
|
67
|
+
[tool.setuptools]
|
|
68
|
+
package-dir = {"" = "src"}
|
|
69
|
+
|
|
70
|
+
[tool.setuptools.packages.find]
|
|
71
|
+
where = ["src"]
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
testpaths = ["tests"]
|
|
@@ -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
|
+
```
|
attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/SOURCES.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/attackmap_analyzer_node_service/__init__.py
|
|
5
|
+
src/attackmap_analyzer_node_service/analyzer.py
|
|
6
|
+
src/attackmap_analyzer_node_service/contracts.py
|
|
7
|
+
src/attackmap_analyzer_node_service.egg-info/PKG-INFO
|
|
8
|
+
src/attackmap_analyzer_node_service.egg-info/SOURCES.txt
|
|
9
|
+
src/attackmap_analyzer_node_service.egg-info/dependency_links.txt
|
|
10
|
+
src/attackmap_analyzer_node_service.egg-info/entry_points.txt
|
|
11
|
+
src/attackmap_analyzer_node_service.egg-info/requires.txt
|
|
12
|
+
src/attackmap_analyzer_node_service.egg-info/top_level.txt
|
|
13
|
+
tests/test_node_service_analyzer.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
attackmap_analyzer_node_service-0.1.0/src/attackmap_analyzer_node_service.egg-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
attackmap_analyzer_node_service
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from attackmap.sdk.contracts import AnalyzerMetadata as SharedAnalyzerMetadata
|
|
4
|
+
from attackmap.sdk.models import ScanResult as SharedScanResult
|
|
5
|
+
from attackmap_analyzer_node_service.contracts import AnalyzerMetadata, ScanResult
|
|
6
|
+
from attackmap_analyzer_node_service import NodeServiceAnalyzer
|
|
7
|
+
|
|
8
|
+
FIXTURES = Path(__file__).parent / "fixtures"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_contracts_use_shared_sdk_types() -> None:
|
|
12
|
+
assert AnalyzerMetadata is SharedAnalyzerMetadata
|
|
13
|
+
assert ScanResult is SharedScanResult
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_metadata_contains_required_fields() -> None:
|
|
17
|
+
analyzer = NodeServiceAnalyzer()
|
|
18
|
+
metadata = analyzer.metadata
|
|
19
|
+
|
|
20
|
+
assert metadata.name == "node-service"
|
|
21
|
+
assert metadata.display_name == "Node Service Analyzer"
|
|
22
|
+
assert metadata.version == "0.1.0"
|
|
23
|
+
assert metadata.description
|
|
24
|
+
assert metadata.scope
|
|
25
|
+
assert "node-service" in metadata.targets
|
|
26
|
+
assert "typescript" in metadata.languages
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_detect_identifies_node_service_repo() -> None:
|
|
30
|
+
analyzer = NodeServiceAnalyzer()
|
|
31
|
+
assert analyzer.detect(FIXTURES / "node_service_repo") is True
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_analyze_extracts_service_signals_and_edges() -> None:
|
|
35
|
+
analyzer = NodeServiceAnalyzer()
|
|
36
|
+
result = analyzer.analyze(FIXTURES / "node_service_repo")
|
|
37
|
+
|
|
38
|
+
route_keys = {(route.path, route.method) for route in result.routes}
|
|
39
|
+
auth_hints = {hint.hint for hint in result.auth_hints}
|
|
40
|
+
external_targets = {call.target for call in result.external_calls}
|
|
41
|
+
databases = {db.kind for db in result.databases}
|
|
42
|
+
secret_names = {secret.name for secret in result.secret_hints}
|
|
43
|
+
|
|
44
|
+
assert ("/xrpc/ping", "GET") in route_keys
|
|
45
|
+
assert ("/internal/rebuild", "POST") in route_keys
|
|
46
|
+
|
|
47
|
+
assert "service_name:api" in auth_hints
|
|
48
|
+
assert "service_role:api" in auth_hints
|
|
49
|
+
assert "service_name:worker" in auth_hints
|
|
50
|
+
assert "service_role:worker" in auth_hints
|
|
51
|
+
assert "entrypoint:express_listen" in auth_hints
|
|
52
|
+
assert "edge:api->worker" in auth_hints
|
|
53
|
+
assert "edge:api->feedgen" in auth_hints
|
|
54
|
+
|
|
55
|
+
assert "https://worker.internal.local/rebuild" in external_targets
|
|
56
|
+
assert "env://FEEDGEN_URL" in external_targets
|
|
57
|
+
|
|
58
|
+
assert "postgresql" in databases
|
|
59
|
+
assert "redis" in databases
|
|
60
|
+
assert "JWT_SIGNING_KEY" in secret_names
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_analyze_returns_core_compatible_scan_shape() -> None:
|
|
64
|
+
analyzer = NodeServiceAnalyzer()
|
|
65
|
+
result = analyzer.analyze(FIXTURES / "node_service_repo")
|
|
66
|
+
|
|
67
|
+
assert isinstance(result.root, str)
|
|
68
|
+
assert isinstance(result.files_scanned, int)
|
|
69
|
+
assert isinstance(result.languages, list)
|
|
70
|
+
assert hasattr(result, "routes")
|
|
71
|
+
assert hasattr(result, "external_calls")
|
|
72
|
+
assert hasattr(result, "databases")
|
|
73
|
+
assert hasattr(result, "auth_hints")
|
|
74
|
+
assert hasattr(result, "secret_hints")
|