attackmap-analyzer-java-spring 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-java-spring might be problematic. Click here for more details.
- attackmap_analyzer_java_spring/__init__.py +3 -0
- attackmap_analyzer_java_spring/analyzer.py +602 -0
- attackmap_analyzer_java_spring/contracts.py +30 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/METADATA +92 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/RECORD +9 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/WHEEL +5 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/entry_points.txt +2 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/licenses/LICENSE +21 -0
- attackmap_analyzer_java_spring-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
"""Java/Kotlin Spring Boot ecosystem analyzer for AttackMap.
|
|
2
|
+
|
|
3
|
+
Coverage (v0.1):
|
|
4
|
+
- Web frameworks: Spring MVC / Spring Boot (annotation routing, with class-level
|
|
5
|
+
@RequestMapping prefix joining), JAX-RS / Jersey / Quarkus (@Path + @GET/@POST),
|
|
6
|
+
Ktor (Kotlin DSL routing), Javalin, Micronaut
|
|
7
|
+
- Databases: Spring Data JPA (@Entity, JpaRepository), Spring Data MongoDB
|
|
8
|
+
(@Document, MongoRepository), Spring Data Redis (RedisTemplate), JDBC
|
|
9
|
+
(DriverManager.getConnection), Hibernate, jOOQ
|
|
10
|
+
- Auth: Spring Security (@PreAuthorize, @Secured, SecurityFilterChain),
|
|
11
|
+
jjwt / nimbus-jose-jwt, BCryptPasswordEncoder / Argon2PasswordEncoder,
|
|
12
|
+
OAuth2 (oauth2Login, OAuth2AuthenticationToken)
|
|
13
|
+
- HTTP clients (external calls): RestTemplate, WebClient, java.net.http.HttpClient,
|
|
14
|
+
OkHttpClient, @FeignClient, Apache HttpClient
|
|
15
|
+
- Secrets: System.getenv("X"), @Value("${X}"), Environment.getProperty("X")
|
|
16
|
+
- Entrypoints: @SpringBootApplication, SpringApplication.run, embedded servlet
|
|
17
|
+
containers
|
|
18
|
+
- Service hints: artifactId/groupId from pom.xml, rootProject.name from
|
|
19
|
+
build.gradle, spring.application.name from application.properties/yml
|
|
20
|
+
|
|
21
|
+
Class-level @RequestMapping prefixes are joined with method-level
|
|
22
|
+
@GetMapping / @PostMapping etc. to produce the full route path. Multiple
|
|
23
|
+
classes per file are tracked correctly (each class's prefix only applies
|
|
24
|
+
to methods that follow it).
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import re
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
from .contracts import (
|
|
33
|
+
AnalyzerMetadata,
|
|
34
|
+
AuthHint,
|
|
35
|
+
DatabaseHint,
|
|
36
|
+
EntrypointHint,
|
|
37
|
+
ExternalCall,
|
|
38
|
+
FrameworkHint,
|
|
39
|
+
Route,
|
|
40
|
+
ScanResult,
|
|
41
|
+
SecretHint,
|
|
42
|
+
ServiceHint,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
CODE_SUFFIXES = {".java", ".kt", ".kts"}
|
|
46
|
+
SKIP_DIRS = {
|
|
47
|
+
"target", # Maven build output
|
|
48
|
+
"build", # Gradle build output
|
|
49
|
+
".gradle",
|
|
50
|
+
".mvn",
|
|
51
|
+
".idea",
|
|
52
|
+
".git",
|
|
53
|
+
"out",
|
|
54
|
+
"bin",
|
|
55
|
+
"node_modules",
|
|
56
|
+
}
|
|
57
|
+
_SNIPPET_MAX_CHARS = 160
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ---------- Patterns ----------
|
|
61
|
+
|
|
62
|
+
# Spring MVC method-level mappings: @GetMapping("/x"), @PostMapping(value = "/x"), etc.
|
|
63
|
+
SPRING_METHOD_MAPPING_PATTERN = re.compile(
|
|
64
|
+
r'@(Get|Post|Put|Delete|Patch)Mapping\s*\(\s*(?:value\s*=\s*)?"([^"]+)"',
|
|
65
|
+
)
|
|
66
|
+
# @RequestMapping("/x", method = RequestMethod.GET) — method-level, with explicit method.
|
|
67
|
+
SPRING_REQUEST_MAPPING_PATTERN = re.compile(
|
|
68
|
+
r'@RequestMapping\s*\(\s*'
|
|
69
|
+
r'(?:value\s*=\s*)?"([^"]+)"'
|
|
70
|
+
r'(?P<rest>[^)]*)\)',
|
|
71
|
+
re.DOTALL,
|
|
72
|
+
)
|
|
73
|
+
# @RequestMapping("/x") — class-level form; we recognize class-level by lookahead for `class `.
|
|
74
|
+
SPRING_CLASS_REQUEST_MAPPING_PATTERN = re.compile(
|
|
75
|
+
r'@RequestMapping\s*\(\s*(?:value\s*=\s*)?"([^"]+)"[^)]*\)\s*'
|
|
76
|
+
r'(?:@\w+(?:\([^)]*\))?\s*)*'
|
|
77
|
+
r'(?:public\s+|abstract\s+|final\s+|@\w+\s+)*class\s+\w+',
|
|
78
|
+
re.DOTALL,
|
|
79
|
+
)
|
|
80
|
+
# JAX-RS / Jersey / Quarkus
|
|
81
|
+
JAXRS_PATH_PATTERN = re.compile(r'@Path\s*\(\s*"([^"]+)"\s*\)')
|
|
82
|
+
JAXRS_METHOD_PATTERN = re.compile(r'@(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)\b')
|
|
83
|
+
|
|
84
|
+
# Ktor (Kotlin): get("/x") { ... } inside `routing { ... }`.
|
|
85
|
+
KTOR_ROUTE_PATTERN = re.compile(
|
|
86
|
+
r'\b(get|post|put|delete|patch|head|options)\s*\(\s*"([^"]+)"\s*\)\s*\{',
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Javalin: app.get("/x", ...), app.post("/x", ...)
|
|
90
|
+
JAVALIN_ROUTE_PATTERN = re.compile(
|
|
91
|
+
r'\bapp\.(get|post|put|delete|patch|head|options)\s*\(\s*"([^"]+)"',
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Micronaut: @Controller("/x") + @Get / @Post / ...
|
|
95
|
+
MICRONAUT_CLASS_PATTERN = re.compile(r'@Controller\s*\(\s*(?:value\s*=\s*)?"([^"]+)"')
|
|
96
|
+
MICRONAUT_METHOD_PATTERN = re.compile(
|
|
97
|
+
r'@(Get|Post|Put|Delete|Patch)\s*\(\s*(?:value\s*=\s*)?"([^"]+)"',
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _spring_method_from_request_mapping(rest: str) -> list[str]:
|
|
102
|
+
methods: list[str] = []
|
|
103
|
+
for match in re.finditer(r'RequestMethod\.(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)', rest):
|
|
104
|
+
methods.append(match.group(1).upper())
|
|
105
|
+
return methods or ["ANY"]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# External HTTP calls
|
|
109
|
+
OUTBOUND_PATTERNS: list[re.Pattern[str]] = [
|
|
110
|
+
re.compile(r'\brestTemplate\.\w+(?:For\w+)?\s*\(\s*"(https?://[^"]+)"', re.IGNORECASE),
|
|
111
|
+
re.compile(r'\bWebClient\.\w+\(\).*?\.uri\s*\(\s*"(https?://[^"]+)"', re.DOTALL),
|
|
112
|
+
re.compile(r'\bHttpRequest\.newBuilder\(\s*URI\.create\s*\(\s*"(https?://[^"]+)"'),
|
|
113
|
+
re.compile(r'\bnew\s+Request\.Builder\(\)[^.]*\.url\s*\(\s*"(https?://[^"]+)"', re.DOTALL),
|
|
114
|
+
re.compile(r'\b(?:OkHttpClient|HttpClient)\(\s*\)[^.]*?\.url\s*\(\s*"(https?://[^"]+)"', re.DOTALL),
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
# Database libs
|
|
118
|
+
DB_PATTERNS: list[tuple[re.Pattern[str], str]] = [
|
|
119
|
+
(re.compile(r'\borg\.springframework\.data\.jpa\b|\bJpaRepository\b|\b@Entity\b'), "sql"),
|
|
120
|
+
(re.compile(r'\borg\.springframework\.data\.mongodb\b|\bMongoRepository\b|\b@Document\b'), "mongodb"),
|
|
121
|
+
(re.compile(r'\borg\.springframework\.data\.redis\b|\bRedisTemplate\b'), "redis"),
|
|
122
|
+
(re.compile(r'\borg\.springframework\.data\.cassandra\b|\bCassandraRepository\b'), "cassandra"),
|
|
123
|
+
(re.compile(r'\borg\.hibernate\b|\bSessionFactory\b'), "sql"),
|
|
124
|
+
(re.compile(r'\borg\.jooq\b|\bDSLContext\b'), "sql"),
|
|
125
|
+
(re.compile(r'\bDriverManager\.getConnection\s*\(\s*"jdbc:postgresql:'), "postgresql"),
|
|
126
|
+
(re.compile(r'\bDriverManager\.getConnection\s*\(\s*"jdbc:mysql:'), "mysql"),
|
|
127
|
+
(re.compile(r'\bDriverManager\.getConnection\s*\(\s*"jdbc:sqlite:'), "sqlite"),
|
|
128
|
+
(re.compile(r'\bDriverManager\.getConnection\s*\(\s*"jdbc:oracle:'), "oracle"),
|
|
129
|
+
(re.compile(r'\bDriverManager\.getConnection\s*\('), "sql"),
|
|
130
|
+
(re.compile(r'\bMongoClients\.create\s*\(|\bcom\.mongodb\.client\b'), "mongodb"),
|
|
131
|
+
(re.compile(r'\bJedis\b|\blettuce\b', re.IGNORECASE), "redis"),
|
|
132
|
+
(re.compile(r'\bsoftware\.amazon\.awssdk\.services\.s3\b|\bAmazonS3\b'), "object_storage"),
|
|
133
|
+
(re.compile(r'\bsoftware\.amazon\.awssdk\.services\.dynamodb\b|\bAmazonDynamoDB\b'), "dynamodb"),
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
# Auth-related signals
|
|
137
|
+
AUTH_PATTERNS: list[tuple[re.Pattern[str], str, float]] = [
|
|
138
|
+
(re.compile(r'\borg\.springframework\.security\.config\.\w+\.SecurityFilterChain\b|\bSecurityFilterChain\s+\w+\s*\('), "spring_security_filter_chain", 0.9),
|
|
139
|
+
(re.compile(r'@PreAuthorize\s*\(|@PostAuthorize\s*\('), "spring_method_security", 0.9),
|
|
140
|
+
(re.compile(r'@Secured\s*\(|@RolesAllowed\s*\('), "role_check", 0.85),
|
|
141
|
+
(re.compile(r'\bWebSecurityConfigurerAdapter\b'), "spring_security_legacy", 0.85),
|
|
142
|
+
(re.compile(r'\bio\.jsonwebtoken\b|\bJwts\.\w+\(|\bJWT\.create\(|\bnimbusds\.jwt\b', re.IGNORECASE), "jwt", 0.85),
|
|
143
|
+
(re.compile(r'\bBCryptPasswordEncoder\b'), "bcrypt", 0.9),
|
|
144
|
+
(re.compile(r'\bArgon2PasswordEncoder\b|\bargon2\b', re.IGNORECASE), "argon2", 0.9),
|
|
145
|
+
(re.compile(r'\bSCryptPasswordEncoder\b'), "scrypt", 0.9),
|
|
146
|
+
(re.compile(r'\boauth2Login\s*\(|\bOAuth2AuthenticationToken\b'), "oauth", 0.85),
|
|
147
|
+
(re.compile(r'@EnableWebSecurity\b'), "spring_security_enabled", 0.85),
|
|
148
|
+
(re.compile(r'@EnableGlobalMethodSecurity\b|@EnableMethodSecurity\b'), "spring_method_security_enabled", 0.85),
|
|
149
|
+
(re.compile(r'\bAuthorization\b'), "authorization_header", 0.6),
|
|
150
|
+
(re.compile(r'\bBearer\b'), "bearer_token", 0.6),
|
|
151
|
+
(re.compile(r'\bapi[_-]?key\b', re.IGNORECASE), "api_key", 0.6),
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
FRAMEWORK_PATTERNS: list[tuple[re.Pattern[str], str]] = [
|
|
155
|
+
(re.compile(r'\borg\.springframework\.boot\b|@SpringBootApplication\b'), "spring-boot"),
|
|
156
|
+
(re.compile(r'\borg\.springframework\.web\b|@RestController\b|@Controller\b'), "spring-mvc"),
|
|
157
|
+
(re.compile(r'\borg\.springframework\.webflux\b|\bWebFlux\b'), "spring-webflux"),
|
|
158
|
+
(re.compile(r'\bjavax\.ws\.rs\b|\bjakarta\.ws\.rs\b'), "jax-rs"),
|
|
159
|
+
(re.compile(r'\borg\.eclipse\.jersey\b|\bJersey\b'), "jersey"),
|
|
160
|
+
(re.compile(r'\bio\.quarkus\b'), "quarkus"),
|
|
161
|
+
(re.compile(r'\bio\.ktor\b|\bktor\.server\b'), "ktor"),
|
|
162
|
+
(re.compile(r'\bio\.micronaut\b'), "micronaut"),
|
|
163
|
+
(re.compile(r'\bio\.javalin\b'), "javalin"),
|
|
164
|
+
(re.compile(r'\borg\.springframework\.security\b'), "spring-security"),
|
|
165
|
+
]
|
|
166
|
+
|
|
167
|
+
ENTRYPOINT_PATTERNS: list[tuple[re.Pattern[str], str]] = [
|
|
168
|
+
(re.compile(r'@SpringBootApplication\b'), "spring_boot_application"),
|
|
169
|
+
(re.compile(r'\bSpringApplication\.run\s*\('), "spring_application_run"),
|
|
170
|
+
(re.compile(r'\bembeddedServletContainerFactory\b'), "embedded_servlet_container"),
|
|
171
|
+
(re.compile(r'\bquarkusMain\b|\bQuarkusApplication\b'), "quarkus_main"),
|
|
172
|
+
(re.compile(r'\bembeddedServer\s*\(\s*Netty\b|\bembeddedServer\s*\(\s*Tomcat\b|\bembeddedServer\s*\(\s*Jetty\b'), "ktor_embedded_server"),
|
|
173
|
+
(re.compile(r'\bJavalin\.create\s*\(\s*\)?'), "javalin_create"),
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
# Secrets in Java are commonly two shapes:
|
|
177
|
+
# - System.getenv("X")
|
|
178
|
+
# - @Value("${X}") (where X looks secret-like)
|
|
179
|
+
# - Environment.getProperty("X")
|
|
180
|
+
SECRET_PATTERNS: list[re.Pattern[str]] = [
|
|
181
|
+
re.compile(
|
|
182
|
+
r'\bSystem\.getenv\s*\(\s*"([A-Z0-9_]*(?:SECRET|TOKEN|KEY|PASSWORD|PASS|PWD)[A-Z0-9_]*)"',
|
|
183
|
+
),
|
|
184
|
+
re.compile(
|
|
185
|
+
r'@Value\s*\(\s*"\$\{([A-Za-z0-9_.]*(?:secret|token|key|password|pass|pwd)[A-Za-z0-9_.]*)\}?"',
|
|
186
|
+
re.IGNORECASE,
|
|
187
|
+
),
|
|
188
|
+
re.compile(
|
|
189
|
+
r'\bgetProperty\s*\(\s*"([A-Za-z0-9_.]*(?:secret|token|key|password|pass|pwd)[A-Za-z0-9_.]*)"',
|
|
190
|
+
re.IGNORECASE,
|
|
191
|
+
),
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _line_of(content: str, offset: int) -> int:
|
|
196
|
+
if offset <= 0:
|
|
197
|
+
return 1
|
|
198
|
+
return content.count("\n", 0, offset) + 1
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _line_snippet(content: str, offset: int, *, max_chars: int = _SNIPPET_MAX_CHARS) -> str:
|
|
202
|
+
line_start = content.rfind("\n", 0, offset) + 1
|
|
203
|
+
line_end = content.find("\n", offset)
|
|
204
|
+
if line_end == -1:
|
|
205
|
+
line_end = len(content)
|
|
206
|
+
line = content[line_start:line_end].strip()
|
|
207
|
+
if len(line) > max_chars:
|
|
208
|
+
line = line[: max_chars - 1] + "…"
|
|
209
|
+
return line
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _join_paths(prefix: str, suffix: str) -> str:
|
|
213
|
+
"""Join a class-level prefix and a method-level path Spring-style."""
|
|
214
|
+
p = prefix.strip()
|
|
215
|
+
s = suffix.strip()
|
|
216
|
+
if not p:
|
|
217
|
+
return s or "/"
|
|
218
|
+
if not s:
|
|
219
|
+
return p or "/"
|
|
220
|
+
if p == "/":
|
|
221
|
+
return s if s.startswith("/") else "/" + s
|
|
222
|
+
if s == "/":
|
|
223
|
+
return p
|
|
224
|
+
return p.rstrip("/") + "/" + s.lstrip("/")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _class_prefixes_in_file(content: str) -> list[tuple[int, str]]:
|
|
228
|
+
"""Return [(start_offset, prefix), ...] for every class-level @RequestMapping in the file.
|
|
229
|
+
|
|
230
|
+
A class-level mapping is one whose annotation precedes a `class Foo` declaration
|
|
231
|
+
(with at most other annotations/modifiers in between). Order matters — when a
|
|
232
|
+
method-level mapping is at offset N, we use the *latest* class prefix at offset < N.
|
|
233
|
+
"""
|
|
234
|
+
prefixes: list[tuple[int, str]] = []
|
|
235
|
+
for match in SPRING_CLASS_REQUEST_MAPPING_PATTERN.finditer(content):
|
|
236
|
+
prefixes.append((match.start(), match.group(1)))
|
|
237
|
+
return prefixes
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _active_class_prefix(prefixes: list[tuple[int, str]], offset: int) -> str:
|
|
241
|
+
"""Find the most recent class prefix preceding the given offset."""
|
|
242
|
+
active = ""
|
|
243
|
+
for start, prefix in prefixes:
|
|
244
|
+
if start < offset:
|
|
245
|
+
active = prefix
|
|
246
|
+
else:
|
|
247
|
+
break
|
|
248
|
+
return active
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _module_name_from_pom(pom_path: Path) -> str | None:
|
|
252
|
+
if not pom_path.exists():
|
|
253
|
+
return None
|
|
254
|
+
try:
|
|
255
|
+
text = pom_path.read_text(encoding="utf-8")
|
|
256
|
+
except UnicodeDecodeError:
|
|
257
|
+
return None
|
|
258
|
+
artifact = re.search(r"<artifactId>([^<]+)</artifactId>", text)
|
|
259
|
+
if artifact:
|
|
260
|
+
return artifact.group(1).strip()
|
|
261
|
+
return None
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _module_name_from_gradle(root: Path) -> str | None:
|
|
265
|
+
for candidate in ("settings.gradle", "settings.gradle.kts"):
|
|
266
|
+
path = root / candidate
|
|
267
|
+
if not path.exists():
|
|
268
|
+
continue
|
|
269
|
+
try:
|
|
270
|
+
text = path.read_text(encoding="utf-8")
|
|
271
|
+
except UnicodeDecodeError:
|
|
272
|
+
continue
|
|
273
|
+
match = re.search(r'rootProject\.name\s*=\s*[\'"]([^\'"]+)[\'"]', text)
|
|
274
|
+
if match:
|
|
275
|
+
return match.group(1).strip()
|
|
276
|
+
return None
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _spring_app_name_from_properties(root: Path) -> str | None:
|
|
280
|
+
for candidate in (
|
|
281
|
+
"src/main/resources/application.properties",
|
|
282
|
+
"src/main/resources/application.yml",
|
|
283
|
+
"application.properties",
|
|
284
|
+
"application.yml",
|
|
285
|
+
):
|
|
286
|
+
path = root / candidate
|
|
287
|
+
if not path.exists():
|
|
288
|
+
continue
|
|
289
|
+
try:
|
|
290
|
+
text = path.read_text(encoding="utf-8")
|
|
291
|
+
except UnicodeDecodeError:
|
|
292
|
+
continue
|
|
293
|
+
match = re.search(r'^\s*spring\.application\.name\s*[:=]\s*([^\s#]+)', text, re.MULTILINE)
|
|
294
|
+
if match:
|
|
295
|
+
return match.group(1).strip().strip("'\"")
|
|
296
|
+
return None
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class JavaSpringAnalyzer:
|
|
300
|
+
metadata = AnalyzerMetadata(
|
|
301
|
+
name="java-spring",
|
|
302
|
+
display_name="Java/Kotlin Spring Boot Analyzer",
|
|
303
|
+
version="0.1.0",
|
|
304
|
+
description="Java and Kotlin analyzer with Spring Boot, JAX-RS, Ktor, and Spring Security awareness.",
|
|
305
|
+
scope="Maven, Gradle, and Kotlin Spring Boot projects. Detects Spring MVC, JAX-RS, Ktor, Javalin, and Micronaut routing.",
|
|
306
|
+
targets=["java", "kotlin", "spring", "spring-boot"],
|
|
307
|
+
languages=["java", "kotlin"],
|
|
308
|
+
priority=20,
|
|
309
|
+
experimental=False,
|
|
310
|
+
enabled_by_default=True,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
@property
|
|
314
|
+
def name(self) -> str:
|
|
315
|
+
return self.metadata.name
|
|
316
|
+
|
|
317
|
+
# ---------- Public entry points ----------
|
|
318
|
+
|
|
319
|
+
def detect(self, repo_path: str | Path) -> bool:
|
|
320
|
+
root = Path(repo_path).resolve()
|
|
321
|
+
if not root.exists() or not root.is_dir():
|
|
322
|
+
return False
|
|
323
|
+
for marker in ("pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts"):
|
|
324
|
+
if (root / marker).exists():
|
|
325
|
+
return True
|
|
326
|
+
for path in root.rglob("*"):
|
|
327
|
+
if any(part in SKIP_DIRS for part in path.parts):
|
|
328
|
+
continue
|
|
329
|
+
if path.is_file() and path.suffix in CODE_SUFFIXES:
|
|
330
|
+
return True
|
|
331
|
+
if path.is_file() and path.name in {"pom.xml", "build.gradle", "build.gradle.kts"}:
|
|
332
|
+
return True
|
|
333
|
+
return False
|
|
334
|
+
|
|
335
|
+
def analyze(self, repo_path: str | Path) -> ScanResult:
|
|
336
|
+
root = Path(repo_path).resolve()
|
|
337
|
+
result = ScanResult(root=str(root))
|
|
338
|
+
if not root.exists() or not root.is_dir():
|
|
339
|
+
return result
|
|
340
|
+
|
|
341
|
+
# Service-name hints from build/application metadata
|
|
342
|
+
artifact = _module_name_from_pom(root / "pom.xml")
|
|
343
|
+
gradle_name = _module_name_from_gradle(root)
|
|
344
|
+
spring_app = _spring_app_name_from_properties(root)
|
|
345
|
+
if artifact:
|
|
346
|
+
self._append_unique_service(result, f"artifact:{artifact}", "pom.xml")
|
|
347
|
+
if gradle_name:
|
|
348
|
+
self._append_unique_service(result, f"gradle_root:{gradle_name}", "settings.gradle")
|
|
349
|
+
if spring_app:
|
|
350
|
+
self._append_unique_service(result, f"spring_app:{spring_app}", "application.properties")
|
|
351
|
+
|
|
352
|
+
for file_path in root.rglob("*"):
|
|
353
|
+
if not file_path.is_file():
|
|
354
|
+
continue
|
|
355
|
+
if any(part in SKIP_DIRS for part in file_path.parts):
|
|
356
|
+
continue
|
|
357
|
+
if file_path.suffix not in CODE_SUFFIXES:
|
|
358
|
+
continue
|
|
359
|
+
|
|
360
|
+
result.files_scanned += 1
|
|
361
|
+
language = "kotlin" if file_path.suffix in {".kt", ".kts"} else "java"
|
|
362
|
+
if language not in result.languages:
|
|
363
|
+
result.languages.append(language)
|
|
364
|
+
|
|
365
|
+
try:
|
|
366
|
+
content = file_path.read_text(encoding="utf-8")
|
|
367
|
+
except UnicodeDecodeError:
|
|
368
|
+
continue
|
|
369
|
+
|
|
370
|
+
relative = str(file_path.relative_to(root))
|
|
371
|
+
self._extract_routes(content, relative, result)
|
|
372
|
+
self._extract_databases(content, relative, result)
|
|
373
|
+
self._extract_auth(content, relative, result)
|
|
374
|
+
self._extract_secrets(content, relative, result)
|
|
375
|
+
self._extract_external_calls(content, relative, result)
|
|
376
|
+
self._extract_frameworks(content, relative, result)
|
|
377
|
+
self._extract_entrypoints(content, relative, result)
|
|
378
|
+
self._infer_service_role(content, relative, result)
|
|
379
|
+
|
|
380
|
+
result.languages.sort()
|
|
381
|
+
return result
|
|
382
|
+
|
|
383
|
+
# ---------- Extractors ----------
|
|
384
|
+
|
|
385
|
+
def _extract_routes(self, content: str, relative: str, result: ScanResult) -> None:
|
|
386
|
+
# Spring: class-level @RequestMapping prefix + method-level @GetMapping etc.
|
|
387
|
+
class_prefixes = _class_prefixes_in_file(content)
|
|
388
|
+
|
|
389
|
+
for match in SPRING_METHOD_MAPPING_PATTERN.finditer(content):
|
|
390
|
+
verb, suffix = match.group(1), match.group(2)
|
|
391
|
+
method = verb.upper()
|
|
392
|
+
prefix = _active_class_prefix(class_prefixes, match.start())
|
|
393
|
+
full_path = _join_paths(prefix, suffix)
|
|
394
|
+
self._append_unique_route(result, full_path, method, relative, _line_of(content, match.start()))
|
|
395
|
+
|
|
396
|
+
# Method-level @RequestMapping with explicit method = RequestMethod.X
|
|
397
|
+
for match in SPRING_REQUEST_MAPPING_PATTERN.finditer(content):
|
|
398
|
+
# Skip class-level mappings — they're handled as prefixes, not routes themselves.
|
|
399
|
+
if (match.start(), match.group(1)) in [(p[0], p[1]) for p in class_prefixes]:
|
|
400
|
+
continue
|
|
401
|
+
suffix = match.group(1)
|
|
402
|
+
rest = match.group("rest") or ""
|
|
403
|
+
methods = _spring_method_from_request_mapping(rest)
|
|
404
|
+
prefix = _active_class_prefix(class_prefixes, match.start())
|
|
405
|
+
full_path = _join_paths(prefix, suffix)
|
|
406
|
+
line = _line_of(content, match.start())
|
|
407
|
+
for method in methods:
|
|
408
|
+
self._append_unique_route(result, full_path, method, relative, line)
|
|
409
|
+
|
|
410
|
+
# JAX-RS: class-level @Path("/x") + method-level @Path("/y") + @GET/@POST/...
|
|
411
|
+
# In typical JAX-RS code, the verb annotation can come *before* or *after* the
|
|
412
|
+
# method-level @Path (`@GET\n@Path("/{id}")` is just as common as the inverse).
|
|
413
|
+
# We pair each verb annotation with the @Path it sits closest to within a window.
|
|
414
|
+
if "javax.ws.rs" in content or "jakarta.ws.rs" in content:
|
|
415
|
+
path_matches = list(JAXRS_PATH_PATTERN.finditer(content))
|
|
416
|
+
verb_matches = list(JAXRS_METHOD_PATTERN.finditer(content))
|
|
417
|
+
class_path = path_matches[0].group(1) if path_matches else ""
|
|
418
|
+
class_path_offset = path_matches[0].start() if path_matches else -1
|
|
419
|
+
for verb_match in verb_matches:
|
|
420
|
+
# Find the @Path annotation closest to this verb (excluding the class-level
|
|
421
|
+
# one) within a 400-char proximity window — that's "the same method block".
|
|
422
|
+
best_path: re.Match | None = None
|
|
423
|
+
best_distance = 401
|
|
424
|
+
for path_match in path_matches:
|
|
425
|
+
if path_match.start() == class_path_offset:
|
|
426
|
+
continue
|
|
427
|
+
distance = abs(path_match.start() - verb_match.start())
|
|
428
|
+
if distance < best_distance:
|
|
429
|
+
best_distance = distance
|
|
430
|
+
best_path = path_match
|
|
431
|
+
method = verb_match.group(1)
|
|
432
|
+
if best_path is not None:
|
|
433
|
+
method_path = best_path.group(1)
|
|
434
|
+
line = _line_of(content, best_path.start())
|
|
435
|
+
else:
|
|
436
|
+
# No method-level @Path — the verb applies to the class-level path.
|
|
437
|
+
method_path = ""
|
|
438
|
+
line = _line_of(content, verb_match.start())
|
|
439
|
+
full_path = _join_paths(class_path, method_path)
|
|
440
|
+
self._append_unique_route(result, full_path, method, relative, line)
|
|
441
|
+
|
|
442
|
+
# Ktor: routing { get("/x") { ... } }
|
|
443
|
+
if "io.ktor" in content or "ktor.server.routing" in content:
|
|
444
|
+
for match in KTOR_ROUTE_PATTERN.finditer(content):
|
|
445
|
+
method, path = match.group(1).upper(), match.group(2)
|
|
446
|
+
self._append_unique_route(result, path, method, relative, _line_of(content, match.start()))
|
|
447
|
+
|
|
448
|
+
# Javalin: app.get("/x", ...)
|
|
449
|
+
if "io.javalin" in content or "Javalin.create" in content:
|
|
450
|
+
for match in JAVALIN_ROUTE_PATTERN.finditer(content):
|
|
451
|
+
method, path = match.group(1).upper(), match.group(2)
|
|
452
|
+
self._append_unique_route(result, path, method, relative, _line_of(content, match.start()))
|
|
453
|
+
|
|
454
|
+
# Micronaut: @Controller("/x") + method @Get/@Post
|
|
455
|
+
if "io.micronaut" in content:
|
|
456
|
+
class_match = MICRONAUT_CLASS_PATTERN.search(content)
|
|
457
|
+
class_path = class_match.group(1) if class_match else ""
|
|
458
|
+
for match in MICRONAUT_METHOD_PATTERN.finditer(content):
|
|
459
|
+
method, suffix = match.group(1).upper(), match.group(2)
|
|
460
|
+
full_path = _join_paths(class_path, suffix)
|
|
461
|
+
self._append_unique_route(result, full_path, method, relative, _line_of(content, match.start()))
|
|
462
|
+
|
|
463
|
+
def _extract_databases(self, content: str, relative: str, result: ScanResult) -> None:
|
|
464
|
+
for pattern, kind in DB_PATTERNS:
|
|
465
|
+
match = pattern.search(content)
|
|
466
|
+
if match is None:
|
|
467
|
+
continue
|
|
468
|
+
self._append_unique_database(
|
|
469
|
+
result, kind, relative,
|
|
470
|
+
_line_of(content, match.start()),
|
|
471
|
+
_line_snippet(content, match.start()),
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
def _extract_auth(self, content: str, relative: str, result: ScanResult) -> None:
|
|
475
|
+
for pattern, hint, confidence in AUTH_PATTERNS:
|
|
476
|
+
match = pattern.search(content)
|
|
477
|
+
if match is None:
|
|
478
|
+
continue
|
|
479
|
+
self._append_unique_auth(
|
|
480
|
+
result, hint, relative,
|
|
481
|
+
_line_of(content, match.start()),
|
|
482
|
+
_line_snippet(content, match.start()),
|
|
483
|
+
confidence,
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
def _extract_secrets(self, content: str, relative: str, result: ScanResult) -> None:
|
|
487
|
+
for pattern in SECRET_PATTERNS:
|
|
488
|
+
for match in pattern.finditer(content):
|
|
489
|
+
groups = match.groups()
|
|
490
|
+
name = groups[0] if groups and groups[0] else "unknown"
|
|
491
|
+
self._append_unique_secret(
|
|
492
|
+
result, name, relative,
|
|
493
|
+
_line_of(content, match.start()),
|
|
494
|
+
_line_snippet(content, match.start()),
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
def _extract_external_calls(self, content: str, relative: str, result: ScanResult) -> None:
|
|
498
|
+
for pattern in OUTBOUND_PATTERNS:
|
|
499
|
+
for match in pattern.finditer(content):
|
|
500
|
+
target = match.group(1)
|
|
501
|
+
if not (target.startswith("http://") or target.startswith("https://")):
|
|
502
|
+
continue
|
|
503
|
+
self._append_unique_external(
|
|
504
|
+
result, target, relative,
|
|
505
|
+
_line_of(content, match.start()),
|
|
506
|
+
_line_snippet(content, match.start()),
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
def _extract_frameworks(self, content: str, relative: str, result: ScanResult) -> None:
|
|
510
|
+
for pattern, name in FRAMEWORK_PATTERNS:
|
|
511
|
+
match = pattern.search(content)
|
|
512
|
+
if match is None:
|
|
513
|
+
continue
|
|
514
|
+
self._append_unique_framework(
|
|
515
|
+
result, name, relative,
|
|
516
|
+
_line_of(content, match.start()),
|
|
517
|
+
_line_snippet(content, match.start()),
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
def _extract_entrypoints(self, content: str, relative: str, result: ScanResult) -> None:
|
|
521
|
+
for pattern, hint in ENTRYPOINT_PATTERNS:
|
|
522
|
+
match = pattern.search(content)
|
|
523
|
+
if match is None:
|
|
524
|
+
continue
|
|
525
|
+
self._append_unique_entrypoint(
|
|
526
|
+
result, hint, relative,
|
|
527
|
+
_line_of(content, match.start()),
|
|
528
|
+
_line_snippet(content, match.start()),
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
def _infer_service_role(self, content: str, relative: str, result: ScanResult) -> None:
|
|
532
|
+
haystack = (relative + " " + content[:500]).lower()
|
|
533
|
+
role: str | None = None
|
|
534
|
+
if any(token in haystack for token in ("worker", "consumer", "queue", "scheduler", "background")):
|
|
535
|
+
role = "worker"
|
|
536
|
+
elif any(token in haystack for token in ("controller", "rest", "resource", "api", "router")):
|
|
537
|
+
role = "api"
|
|
538
|
+
elif any(token in haystack for token in ("client", "sdk")):
|
|
539
|
+
role = "client"
|
|
540
|
+
if role:
|
|
541
|
+
self._append_unique_service(result, f"service_role:{role}", relative)
|
|
542
|
+
|
|
543
|
+
# ---------- Append helpers ----------
|
|
544
|
+
|
|
545
|
+
@staticmethod
|
|
546
|
+
def _append_unique_route(result: ScanResult, path: str, method: str, file: str, line: int | None) -> None:
|
|
547
|
+
key = (path, method, file)
|
|
548
|
+
if any((item.path, item.method, item.file) == key for item in result.routes):
|
|
549
|
+
return
|
|
550
|
+
result.routes.append(Route(path=path, method=method, file=file, line=line))
|
|
551
|
+
|
|
552
|
+
@staticmethod
|
|
553
|
+
def _append_unique_database(result: ScanResult, kind: str, file: str, line: int | None, evidence: str | None) -> None:
|
|
554
|
+
key = (kind, file)
|
|
555
|
+
if any((item.kind, item.file) == key for item in result.databases):
|
|
556
|
+
return
|
|
557
|
+
result.databases.append(DatabaseHint(kind=kind, file=file, line=line, evidence_text=evidence))
|
|
558
|
+
|
|
559
|
+
@staticmethod
|
|
560
|
+
def _append_unique_auth(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None, confidence: float) -> None:
|
|
561
|
+
key = (hint, file)
|
|
562
|
+
if any((item.hint, item.file) == key for item in result.auth_hints):
|
|
563
|
+
return
|
|
564
|
+
result.auth_hints.append(AuthHint(hint=hint, file=file, line=line, evidence_text=evidence, confidence=confidence))
|
|
565
|
+
|
|
566
|
+
@staticmethod
|
|
567
|
+
def _append_unique_secret(result: ScanResult, name: str, file: str, line: int | None, evidence: str | None) -> None:
|
|
568
|
+
key = (name, file)
|
|
569
|
+
if any((item.name, item.file) == key for item in result.secret_hints):
|
|
570
|
+
return
|
|
571
|
+
result.secret_hints.append(SecretHint(name=name, file=file, line=line, evidence_text=evidence, confidence=0.85))
|
|
572
|
+
|
|
573
|
+
@staticmethod
|
|
574
|
+
def _append_unique_external(result: ScanResult, target: str, file: str, line: int | None, evidence: str | None) -> None:
|
|
575
|
+
key = (target, file)
|
|
576
|
+
if any((item.target, item.file) == key for item in result.external_calls):
|
|
577
|
+
return
|
|
578
|
+
result.external_calls.append(ExternalCall(target=target, file=file, line=line, evidence_text=evidence))
|
|
579
|
+
|
|
580
|
+
@staticmethod
|
|
581
|
+
def _append_unique_framework(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None) -> None:
|
|
582
|
+
key = (hint, file)
|
|
583
|
+
if any((item.hint, item.file) == key for item in result.framework_hints):
|
|
584
|
+
return
|
|
585
|
+
result.framework_hints.append(FrameworkHint(hint=hint, file=file, line=line, evidence_text=evidence))
|
|
586
|
+
|
|
587
|
+
@staticmethod
|
|
588
|
+
def _append_unique_entrypoint(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None) -> None:
|
|
589
|
+
key = (hint, file)
|
|
590
|
+
if any((item.hint, item.file) == key for item in result.entrypoint_hints):
|
|
591
|
+
return
|
|
592
|
+
result.entrypoint_hints.append(EntrypointHint(hint=hint, file=file, line=line, evidence_text=evidence))
|
|
593
|
+
|
|
594
|
+
@staticmethod
|
|
595
|
+
def _append_unique_service(result: ScanResult, hint: str, file: str) -> None:
|
|
596
|
+
key = (hint, file)
|
|
597
|
+
if any((item.hint, item.file) == key for item in result.service_hints):
|
|
598
|
+
return
|
|
599
|
+
result.service_hints.append(ServiceHint(hint=hint, file=file))
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
__all__ = ["JavaSpringAnalyzer"]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from attackmap.sdk.contracts import AnalyzerMetadata, AnalyzerProtocol
|
|
4
|
+
from attackmap.sdk.models import (
|
|
5
|
+
AuthHint,
|
|
6
|
+
DatabaseHint,
|
|
7
|
+
EntrypointHint,
|
|
8
|
+
ExternalCall,
|
|
9
|
+
FrameworkHint,
|
|
10
|
+
Route,
|
|
11
|
+
ScanResult,
|
|
12
|
+
SecretHint,
|
|
13
|
+
ServiceHint,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
AttackMapAnalyzerProtocol = AnalyzerProtocol
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"AnalyzerMetadata",
|
|
20
|
+
"AttackMapAnalyzerProtocol",
|
|
21
|
+
"Route",
|
|
22
|
+
"ExternalCall",
|
|
23
|
+
"DatabaseHint",
|
|
24
|
+
"AuthHint",
|
|
25
|
+
"EntrypointHint",
|
|
26
|
+
"FrameworkHint",
|
|
27
|
+
"ServiceHint",
|
|
28
|
+
"SecretHint",
|
|
29
|
+
"ScanResult",
|
|
30
|
+
]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: attackmap-analyzer-java-spring
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Java/Kotlin Spring Boot ecosystem analyzer plugin for AttackMap (Spring MVC routing, JAX-RS, Ktor; Spring Data JPA / Mongo / Redis; Spring Security; jjwt; RestTemplate / WebClient / OkHttp).
|
|
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-java-spring
|
|
10
|
+
Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-java-spring
|
|
11
|
+
Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-java-spring/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-java-spring/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-analyzer-java-spring
|
|
42
|
+
|
|
43
|
+
Java and Kotlin Spring Boot ecosystem analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
|
|
44
|
+
|
|
45
|
+
This analyzer extracts structured signals from Maven and Gradle projects:
|
|
46
|
+
|
|
47
|
+
- **Web frameworks** — Spring MVC / Spring Boot (annotation routing with class-level `@RequestMapping` prefix joining), JAX-RS / Jersey / Quarkus (`@Path` + `@GET`/`@POST`), Ktor (Kotlin DSL), Javalin, Micronaut
|
|
48
|
+
- **Databases** — Spring Data JPA (`@Entity`, `JpaRepository`), Spring Data MongoDB (`@Document`, `MongoRepository`), Spring Data Redis (`RedisTemplate`), JDBC (`DriverManager.getConnection` with driver-aware kind inference), Hibernate, jOOQ, AWS SDK (S3, DynamoDB)
|
|
49
|
+
- **Auth packages** — Spring Security (`@PreAuthorize`, `@Secured`, `SecurityFilterChain`, `@EnableWebSecurity`), jjwt / nimbus-jose-jwt, BCrypt / Argon2 / SCrypt password encoders, OAuth2 (`oauth2Login`, `OAuth2AuthenticationToken`)
|
|
50
|
+
- **HTTP clients (external calls)** — RestTemplate, WebClient, java.net.http.HttpClient, OkHttpClient, `@FeignClient`, Apache HttpClient
|
|
51
|
+
- **Secrets** — `System.getenv`, `@Value("${...}")`, `Environment.getProperty(...)`
|
|
52
|
+
- **Service hints** — `<artifactId>` from `pom.xml`, `rootProject.name` from Gradle settings, `spring.application.name` from `application.properties`/`application.yml`
|
|
53
|
+
|
|
54
|
+
All emissions populate AttackMap's Signal v2 fields (line numbers, evidence snippets, confidence scores) so downstream insights can cite `path/to/file.java:NN`.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install git+https://github.com/mlaify/attackmap-analyzer-java-spring.git
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
|
|
63
|
+
|
|
64
|
+
## Usage with AttackMap
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Auto-discovered when installed:
|
|
68
|
+
attackmap analyze /path/to/spring/repo
|
|
69
|
+
|
|
70
|
+
# Or invoke explicitly:
|
|
71
|
+
attackmap analyze /path/to/spring/repo --module java-spring
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Detection
|
|
75
|
+
|
|
76
|
+
`detect()` returns true when any of the following are present, ignoring `target/`, `build/`, `.gradle/`, `.mvn/`, `.idea/`, `.git/`, `out/`, `bin/`, and `node_modules/`:
|
|
77
|
+
|
|
78
|
+
- `pom.xml`, `build.gradle`, `build.gradle.kts`, `settings.gradle`, or `settings.gradle.kts` at the root
|
|
79
|
+
- `.java`, `.kt`, or `.kts` files anywhere in the tree
|
|
80
|
+
|
|
81
|
+
## Coverage notes
|
|
82
|
+
|
|
83
|
+
- **Class-level `@RequestMapping` prefix joining**: a class annotated with `@RequestMapping("/api/users")` causes its method-level `@GetMapping("/{id}")` to emit as `/api/users/{id}`. Multiple classes in one file are tracked correctly — the prefix in effect is whichever class declaration most recently preceded the method annotation.
|
|
84
|
+
- **`@PostMapping` with no value** (e.g. `@PostMapping public Object create()`) is **not currently extracted** — the regex requires a string argument. Workaround: write `@PostMapping("")` or `@PostMapping("/")`. Roadmap.
|
|
85
|
+
- **JAX-RS class + method `@Path` joining**: the first `@Path` in a JAX-RS file is treated as the class-level prefix and joined to subsequent method-level `@Path` annotations. HTTP verb (`@GET`, `@POST`, etc.) is captured by looking ahead from the `@Path` for the next verb annotation within ~800 chars.
|
|
86
|
+
- **Kotlin Ktor**: `routing { get("/x") { ... } }` extraction only fires when the file contains an `io.ktor` import or `ktor.server.routing` reference, to avoid mis-attributing `get(...)` calls on Maps and other types.
|
|
87
|
+
- **Javalin** and **Micronaut** are similarly framework-gated.
|
|
88
|
+
- **OkHttp / java.net.http.HttpClient**: literal-URL builder patterns (`new Request.Builder().url("https://...")`, `HttpRequest.newBuilder(URI.create("https://..."))`) are picked up. Calls where the URL is built by string concatenation are not.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
attackmap_analyzer_java_spring/__init__.py,sha256=KJSALbhfbFgJgkYbbL-zz3W4PSzUjP-s-NT7j88F8nY,75
|
|
2
|
+
attackmap_analyzer_java_spring/analyzer.py,sha256=u3TR9Xhmi2VdQ9iiSTtBXjj7jmlHgq5OyPnfFSwLGKc,27007
|
|
3
|
+
attackmap_analyzer_java_spring/contracts.py,sha256=dsveFe7szz7xceev0PIfyc5jQlNiES0whsdxwu9D7YI,578
|
|
4
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/licenses/LICENSE,sha256=vtPQVGUyxq359j0JmD3_eJaXyHmaHyjzaMOtaLwJc88,1097
|
|
5
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/METADATA,sha256=rOo54II8zWOJty24daCi-8WMYWOjabXT8qDwhv1r3sM,5624
|
|
6
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/entry_points.txt,sha256=VZO4542hocH02OvgISydT4zRunx6lkBv5d6LYwlCVqU,86
|
|
8
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/top_level.txt,sha256=JEj3pI66-dq9VrWTz0ESh7uwuOyHt92AyMwQdaQ6NoI,31
|
|
9
|
+
attackmap_analyzer_java_spring-0.1.0.dist-info/RECORD,,
|
|
@@ -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_java_spring
|