@hoanghainh/komagu 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +202 -0
  3. package/README.md +1 -0
  4. package/assess/lsa/CHANGELOG.md +15 -0
  5. package/assess/lsa/scripts/detect_stack.py +15 -6
  6. package/assess/lsa/scripts/find_injection.py +35 -2
  7. package/assess/lsa/scripts/java_routes.py +323 -0
  8. package/assess/lsa/scripts/lsa_common.py +73 -7
  9. package/assess/lsa/scripts/map_routes.py +36 -160
  10. package/assess/lsa/scripts/merge_findings.py +2 -0
  11. package/assess/lsa/scripts/redaction.py +118 -0
  12. package/assess/lsa/tests/test_java_legacy_realistic.py +453 -0
  13. package/assess/lsa/tests/test_modern_stacks.py +13 -0
  14. package/contracts/schemas/persona-suite.schema.json +38 -2
  15. package/examples/member-portal/backend-dotnet/Dockerfile +2 -1
  16. package/examples/member-portal/backend-spring/Dockerfile +2 -0
  17. package/examples/member-portal/docker-compose.yml +1 -1
  18. package/examples/member-portal/frontend/Dockerfile +3 -2
  19. package/examples/member-portal/frontend/package-lock.json +24 -656
  20. package/examples/member-portal/frontend/package.json +1 -1
  21. package/operate/ai/context.py +22 -2
  22. package/operate/ai/runner.py +20 -2
  23. package/operate/cli/__init__.py +1 -1
  24. package/operate/cli/commands/fix.py +4 -0
  25. package/operate/cli/commands/leak_check.py +75 -0
  26. package/operate/cli/commands/protect.py +32 -3
  27. package/operate/cli/commands/test.py +131 -15
  28. package/operate/cli/main.py +5 -3
  29. package/operate/cross_user_tester/persona_matrix.py +118 -25
  30. package/operate/cross_user_tester/runner.py +190 -7
  31. package/operate/cross_user_tester/session_config.py +180 -0
  32. package/operate/cross_user_tester/session_http.py +288 -0
  33. package/operate/devsecops/leak_check.py +314 -0
  34. package/operate/remediator/runner.py +18 -1
  35. package/operate/remediator/strategies.py +2 -2
  36. package/operate/simulate/scenarios.py +2 -2
  37. package/operate/tests/mock_legacy_session_app.py +160 -0
  38. package/operate/tests/test_ai_redaction.py +181 -0
  39. package/operate/tests/test_cross_user_session.py +565 -0
  40. package/operate/tests/test_docker_packaging.py +3 -3
  41. package/operate/tests/test_headless_ai.py +22 -1
  42. package/operate/tests/test_leak_check.py +250 -0
  43. package/operate/tests/test_legacy_session_edge.py +192 -0
  44. package/operate/tests/test_pilot_safeguards.py +245 -0
  45. package/operate/tests/test_remediator_java_legacy.py +330 -0
  46. package/package.json +2 -1
  47. package/remediate/authz/patcher.py +120 -11
  48. package/remediate/authz/tests/test_bola_patcher.py +4 -1
  49. package/remediate/edge/coraza/Caddyfile +1 -1
  50. package/remediate/edge/coraza/Dockerfile +9 -0
  51. package/remediate/edge/coraza/rules/coraza-crs-custom.conf +12 -0
  52. package/remediate/edge/coraza/virtual_patcher.py +24 -0
  53. package/remediate/edge/docker-compose.yml +7 -2
  54. package/remediate/edge/kong/kong-legacy-session.yaml +51 -0
  55. package/remediate/edge/mock-backend/Dockerfile +2 -0
  56. package/remediate/edge/tests/test_edge_security.py +21 -1
  57. package/remediate/resilience/terraform/backup_worm.tf +39 -1
  58. package/remediate/resilience/terraform/main.tf +15 -3
  59. package/remediate/resilience/terraform/variables.tf +11 -0
  60. package/remediate/resilience/tests/test_resilience.py +16 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  All notable changes to `@hoanghainh/komagu` (published as `komainu-guard` up to v1.7.0) are documented here. From v1.2.2 on, entries are generated by [release-please](https://github.com/googleapis/release-please) from [Conventional Commits](https://www.conventionalcommits.org/). Earlier entries are copied from the [GitHub Releases](https://github.com/hoanghainh1188/komainu/releases).
4
4
 
5
+ ## [2.5.0](https://github.com/hoanghainh1188/komagu/compare/v2.4.0...v2.5.0) (2026-11-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * **docker:** move the published image to an Alpine base ([#363](https://github.com/hoanghainh1188/komagu/issues/363)) ([fb45135](https://github.com/hoanghainh1188/komagu/commit/fb451356e4fdd8b3d16a785f121fd7a9ed702231))
11
+ * **pilot:** add leak check, exclude list, deletion record and pilot data guard ([#370](https://github.com/hoanghainh1188/komagu/issues/370)) ([b0eaef9](https://github.com/hoanghainh1188/komagu/commit/b0eaef9b779816bcfe000633fea5bc5f18fcafc5))
12
+ * **test:** verify cross-user authorization on session-based Java legacy apps ([#371](https://github.com/hoanghainh1188/komagu/issues/371)) ([2aff6eb](https://github.com/hoanghainh1188/komagu/commit/2aff6eb59adc0043d59cfe5d2a30bd0f084c33e3))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **assess/lsa:** close Tier 1 gaps found on real Java legacy apps ([#369](https://github.com/hoanghainh1188/komagu/issues/369)) ([41177c7](https://github.com/hoanghainh1188/komagu/commit/41177c74673bcdbf89a7f5c6b4863b50850ea199))
18
+ * **examples:** upgrade plugin-react so the portal frontend builds on vite 8 ([#362](https://github.com/hoanghainh1188/komagu/issues/362)) ([9485fce](https://github.com/hoanghainh1188/komagu/commit/9485fcebb475ebf4d6c22b3e1d48a3ccd729b3d6))
19
+ * **pilot:** pin the runbook to v2.4.0 and add the Apache-2.0 LICENSE ([#357](https://github.com/hoanghainh1188/komagu/issues/357)) ([79e9e71](https://github.com/hoanghainh1188/komagu/commit/79e9e715fdab86581d378a6205e90dc39d2eb2a8))
20
+ * **pilot:** rehearse the runbook on a running Struts legacy app and fix what broke ([#375](https://github.com/hoanghainh1188/komagu/issues/375)) ([62d8f8d](https://github.com/hoanghainh1188/komagu/commit/62d8f8d5678320ddf43a264889ab148bd97006ef))
21
+ * **remediate/authz:** stop emitting unusable patches on Java legacy code ([#373](https://github.com/hoanghainh1188/komagu/issues/373)) ([4ae9c29](https://github.com/hoanghainh1188/komagu/commit/4ae9c293d1ffab8153e10c46d7af21cc1b123a15))
22
+ * **security:** harden images and Terraform flagged by code scanning ([#359](https://github.com/hoanghainh1188/komagu/issues/359)) ([4658417](https://github.com/hoanghainh1188/komagu/commit/46584174efe86e6b49231302b0f51c5217a657bf))
23
+
24
+
25
+ ### Documentation
26
+
27
+ * mark pilot ROI claims as internal and add CONTRIBUTING.md ([#366](https://github.com/hoanghainh1188/komagu/issues/366)) ([63c223c](https://github.com/hoanghainh1188/komagu/commit/63c223c976c46d60f789dafdeaff169b9cd6b974))
28
+
29
+ ## [2.4.0](https://github.com/hoanghainh1188/komagu/compare/v2.3.0...v2.4.0) (2026-11-03)
30
+
31
+
32
+ ### Features
33
+
34
+ * **pilot:** prepare the AMS pilot on a Java legacy system and redact secrets sent to the model ([#352](https://github.com/hoanghainh1188/komagu/issues/352)) ([fb02b3c](https://github.com/hoanghainh1188/komagu/commit/fb02b3cbdf70e3d6e5ee7c73c7e308f03c2ff7f3))
35
+
36
+
37
+ ### Documentation
38
+
39
+ * **delivery:** remove Komainu leftovers and file:/// links from pilot deliverables ([#353](https://github.com/hoanghainh1188/komagu/issues/353)) ([f61d1df](https://github.com/hoanghainh1188/komagu/commit/f61d1dff03469986970d0a6d640a37fd2f7b947f))
40
+
5
41
  ## [2.3.0](https://github.com/hoanghainh1188/komagu/compare/v2.2.1...v2.3.0) (2026-11-01)
6
42
 
7
43
 
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md CHANGED
@@ -231,3 +231,4 @@ komagu/
231
231
 
232
232
  - **The Two-Person Rule:** Komagu enforces strict governance ([`governance/usage-policy.md`](governance/usage-policy.md)) where automated audits/patches (Person A) must be validated by a human architect/engineer (Person B) prior to production deployment.
233
233
  - **100% Open Source Architecture ([ADR-0008](docs/adr/0008-transition-to-fully-open-source.md)):** Komagu is fully open source under the **Apache License 2.0**. The assessment kit, WAF edge shields, AST auto-fix generators, and CI cross-user testing engines are completely open and auditable by the global engineering community.
234
+ - **Contributing:** See [`CONTRIBUTING.md`](CONTRIBUTING.md) for issues, branches, pull requests, tests, and Apache-2.0 contribution terms.
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ AMS pilot readiness (#350).
6
+
7
+ - **Secret redaction (`scripts/redaction.py`, re-exported by `lsa_common`):** besides quoted `password`-like values, it now masks:
8
+ - unquoted config values (`.properties`, YAML, `.env`) and dotted keys inside comments (`<%-- db.password=x --%>`);
9
+ - JSON and PHP keys, plus `pass`, `pw`, `passphrase` and `credential` key names such as Tomcat `keystorePass`;
10
+ - Java legacy forms: `setPassword("x")`, `getConnection(url, user, "x")`, `PasswordAuthentication`, Spring XML `<property name=… value=…>`, and `web.xml` `<param-name>` / `<param-value>`, including when split across lines;
11
+ - credentials in connection strings and URIs (`;password=`, `?pwd=`, `password={…}`, `scheme://user:pass@host`, `jdbc:oracle:thin:user/pass@host`);
12
+ - `Basic` / `Bearer` values and AWS, GitHub, `sk-` and Google API tokens;
13
+ - private key blocks.
14
+
15
+ Lines longer than 4,000 characters are dropped whole, which keeps the regexes linear on minified files. The headless runner applies `redact_lines()` to every code excerpt it sends to the model (`operate/ai/context.py`).
16
+ - **`detect_stack.py`:** JPA's `@Entity` and Spring Data's `getRepository` no longer report "TypeORM (Node/TS)" on Java code.
17
+
3
18
  ## 0.3.1 — 2026-10-30
4
19
 
5
20
  SARIF replay properties (#289).
@@ -12,7 +12,10 @@ import sys
12
12
  from pathlib import Path
13
13
 
14
14
  sys.path.insert(0, str(Path(__file__).resolve().parent))
15
- from lsa_common import KIT_VERSION, iter_source_files, load_config, read_text, write_json # noqa: E402
15
+ from lsa_common import KIT_VERSION, blank_java_comments, iter_source_files, load_config, read_text, write_json # noqa: E402
16
+
17
+ # org.hibernate.validator is the Bean Validation implementation: it says nothing about the persistence layer
18
+ HIBERNATE_ORM = r"org\.hibernate\.(?!validator\b)"
16
19
 
17
20
  # (stack id, language, knowledge file, list of (kind, pattern))
18
21
  # kind = "name" -> regex on relative path
@@ -35,7 +38,7 @@ RULES = [
35
38
  ("java-jaxrs", "java", "java.md", [("text", r"javax\.ws\.rs\.|jakarta\.ws\.rs\.")]),
36
39
  ("java-mybatis", "java", "java.md", [("text", r"<mapper\s+namespace=|org\.apache\.ibatis")]),
37
40
  ("java-ibatis", "java", "java.md", [("text", r"<sqlMap\b|com\.ibatis\.")]),
38
- ("java-hibernate", "java", "java.md", [("text", r"org\.hibernate\.|\.hbm\.xml|createQuery\s*\(")]),
41
+ ("java-hibernate", "java", "java.md", [("text", HIBERNATE_ORM + r"|\.hbm\.xml|createQuery\s*\(")]),
39
42
  ("dotnet-webforms", "csharp/vbnet", "dotnet.md", [("ext", {".aspx", ".ascx"})]),
40
43
  ("dotnet-handlers", "csharp/vbnet", "dotnet.md", [("ext", {".ashx"})]),
41
44
  ("dotnet-asmx-wcf", "csharp/vbnet", "dotnet.md", [("ext", {".asmx", ".svc"})]),
@@ -73,8 +76,8 @@ DATA_ACCESS = [
73
76
  ("JDBC", r"java\.sql\.|DriverManager\.getConnection"),
74
77
  ("Spring JdbcTemplate", r"JdbcTemplate"),
75
78
  ("MyBatis/iBATIS", r"<mapper\s+namespace=|<sqlMap\b"),
76
- ("Hibernate/JPA", r"org\.hibernate\.|javax\.persistence\."),
77
- ("ADO.NET", r"SqlCommand|OleDbCommand|OdbcCommand|OracleCommand"),
79
+ ("Hibernate/JPA", HIBERNATE_ORM + r"|javax\.persistence\.|jakarta\.persistence\."),
80
+ ("ADO.NET", r"\b(?:SqlCommand|OleDbCommand|OdbcCommand|OracleCommand)\b"),
78
81
  ("Entity Framework / LINQ to SQL", r"DbContext|DataContext|System\.Data\.Entity"),
79
82
  ("Classic ADO", r"ADODB\.(Connection|Recordset|Command)"),
80
83
  ("Perl DBI", r"DBI->connect"),
@@ -86,7 +89,8 @@ DATA_ACCESS = [
86
89
  ("database/sql (Go)", r"sql\.Open|db\.Query|db\.Exec"),
87
90
  ("SQLAlchemy (Python)", r"sqlalchemy\.|create_engine|SessionLocal"),
88
91
  ("Prisma (Node/TS)", r"PrismaClient|@prisma/client"),
89
- ("TypeORM (Node/TS)", r"typeorm|@Entity|getRepository"),
92
+ # Not bare @Entity / getRepository: JPA and Spring Data use the same names
93
+ ("TypeORM (Node/TS)", r"['\"]typeorm['\"]|\bTypeORM\b"),
90
94
  ("Drizzle ORM (Node/TS)", r"drizzle-orm"),
91
95
  ("postgres.js (Node/TS)", r"from\s+['\"]postgres['\"]|require\(\s*['\"]postgres['\"]\s*\)"),
92
96
  ]
@@ -97,6 +101,7 @@ DB_HINTS = [
97
101
  ("MongoDB", r"(?i)mongo"), ("SQLite", r"(?i)sqlite"),
98
102
  ]
99
103
 
104
+ DOTNET_TEXT_EXTS = {".cs", ".vb", ".aspx", ".asax", ".config"}
100
105
  TEXT_SAMPLE_EXTS = {".sql", ".php", ".inc", ".java", ".jsp", ".xml", ".cs", ".vb", ".aspx", ".asax", ".config", ".asp",
101
106
  ".pl", ".pm", ".cgi", ".cfm", ".cfc", ".js", ".mjs", ".ts", ".tsx", ".jsx", ".py", ".rb", ".kt", ".kts",
102
107
  ".rs", ".go", ".toml", ".mod"}
@@ -128,9 +133,13 @@ def detect(target: Path, config: dict) -> dict:
128
133
  for path, rel in files:
129
134
  if path.suffix.lower() not in TEXT_SAMPLE_EXTS:
130
135
  continue
136
+ ext = path.suffix.lower()
131
137
  text = read_text(path, enc)
138
+ rule_text = blank_java_comments(text) if ext == ".java" else text
132
139
  for sid, rx in text_rules:
133
- if seen_text[sid] < 3 and rx.search(text):
140
+ if sid.startswith("dotnet-") and ext not in DOTNET_TEXT_EXTS:
141
+ continue
142
+ if seen_text[sid] < 3 and rx.search(rule_text):
134
143
  seen_text[sid] += 1
135
144
  evidence[sid].append(f"pattern /{rx.pattern[:40]}/ in {rel}")
136
145
  for n, rx in da_rules:
@@ -37,6 +37,11 @@ STRONG_SQL = re.compile(
37
37
  r"(?i)(\bselect\b[\s\S]*?\bfrom\b|\bselect\s+[\w*]|\binsert\s+into\b|\bupdate\s+[\w\[\].`\"]+\s+set\b|\bupdate\s+[\w\[\].`\"]+\s*$"
38
38
  r"|\bdelete\s+from\b|\bwhere\b\s*[\w(`\[]|\border\s+by\b|\bgroup\s+by\b|\bvalues\s*\(|\bexec(ute)?\s+\w|\bunion\s+select\b"
39
39
  r"|\bfrom\s+[\w\[\].`\"]+\s+(where|order|group|inner|left|join)\b|\bhaving\b)")
40
+ # Java only: an HTML opening tag is markup, and a literal ending in WHERE is SQL/JPQL about to take a concatenated clause
41
+ HTML_OPEN_TAG = re.compile(r"</?[a-zA-Z][\w:-]*\b")
42
+ JAVA_TRAILING_WHERE = re.compile(r"(?i)\bwhere\s*\"$")
43
+ # JPQL positional parameter: the appended value is the numeric index of a bind mark, as in " = ?").append(size)
44
+ JAVA_POSITIONAL_APPEND = re.compile(r"\?\"\s*\)\s*\.\s*append\s*\(\s*(?:size|index|idx|i|n|pos|position|count|\w*[Ii]ndex)\s*\)\s*;?\s*$")
40
45
  WEAK_SQL = re.compile(r"(?i)\b(and|or|like|in|not|between|set|where|order\s+by|limit|offset|values|join|on)\b|=\s*['\"]?$|[(,=<>]\s*'?$")
41
46
  SQL_IDENT = re.compile(r"(?i)\b(order\s+by|group\s+by|asc|desc|limit)\b")
42
47
 
@@ -132,6 +137,20 @@ def raw_fragment_arg_is_constant(arg: str) -> bool:
132
137
  return False
133
138
 
134
139
 
140
+ def is_sql_literal(text: str, lang: str) -> bool:
141
+ if lang == "java":
142
+ return bool(STRONG_SQL.search(HTML_OPEN_TAG.sub("", text)) or JAVA_TRAILING_WHERE.search(text))
143
+ return bool(STRONG_SQL.search(text))
144
+
145
+
146
+ def java_continuation_is_dynamic(line: str, lit: re.Pattern) -> bool:
147
+ """True when a continuation line of a multi-line SQL statement joins a non-constant operand."""
148
+ if concat_kind(line, "java", lit) == "dynamic":
149
+ return True
150
+ leading = re.match(r"\s*\+\s*([A-Za-z_][\w.]*)", strip_literals(line, lit))
151
+ return bool(leading and not CONST_OPERAND.match(leading.group(1)))
152
+
153
+
135
154
  def strip_literals(line: str, lit: re.Pattern) -> str:
136
155
  return lit.sub('""', line)
137
156
 
@@ -249,7 +268,7 @@ class Finder:
249
268
  if com and com.search(line):
250
269
  continue
251
270
  lits = untagged(line, literals(line, lit), lang)
252
- if not any(STRONG_SQL.search(m.group(0)) for m in lits):
271
+ if not any(is_sql_literal(m.group(0), lang) for m in lits):
253
272
  continue
254
273
  if assign_rx:
255
274
  m = assign_rx.search(line)
@@ -259,6 +278,7 @@ class Finder:
259
278
  if am:
260
279
  sqlvars.setdefault(am.group(1), i)
261
280
  heredoc_end = None
281
+ open_sql = False
262
282
  # pass 2 — flag dynamic building
263
283
  for i, line in enumerate(lines, 1):
264
284
  if com and com.search(line):
@@ -283,7 +303,12 @@ class Finder:
283
303
  self.add(lang, rel, i, lines, "heredoc-interpolation", "string_interpolation", "sql", None, file_has_input)
284
304
  continue
285
305
  lits = untagged(line, literals(line, lit), lang)
286
- sql_lits = [m for m in lits if STRONG_SQL.search(m.group(0))]
306
+ sql_lits = [m for m in lits if is_sql_literal(m.group(0), lang)]
307
+ continuing = False
308
+ if lang == "java":
309
+ code = strip_literals(line, lit)
310
+ continuing = open_sql
311
+ open_sql = (bool(sql_lits) or open_sql) and not re.search(r"[;{}]", code)
287
312
  target_var = None
288
313
  if assign_rx:
289
314
  am = assign_rx.search(line)
@@ -294,6 +319,8 @@ class Finder:
294
319
  target_var = ap.group(1)
295
320
  is_sqlish = bool(sql_lits) or target_var is not None
296
321
  if not is_sqlish:
322
+ if continuing and java_continuation_is_dynamic(line, lit):
323
+ self.add(lang, rel, i, lines, "sql-concat", "string_concatenation", "sql", None, file_has_input)
297
324
  continue
298
325
  # interpolation inside a SQL literal (or SQL-variable literal)
299
326
  cand_lits = sql_lits or (lits if target_var else [])
@@ -317,6 +344,10 @@ class Finder:
317
344
  self.suppressed.append({"file": rel, "line": i, "reason": "concatenation with constant-looking operands only",
318
345
  "snippet": redact(snippet(lines, i))})
319
346
  continue
347
+ if lang == "java" and JAVA_POSITIONAL_APPEND.search(line):
348
+ self.suppressed.append({"file": rel, "line": i, "reason": "appended value is a positional bind index",
349
+ "snippet": redact(snippet(lines, i))})
350
+ continue
320
351
  if target_var and re.search(r"\.\s*(append|Append|AppendLine|concat)\s*\(\s*(?![\"'@\s])", line):
321
352
  self.add(lang, rel, i, lines, "sql-append", "string_concatenation", "sql", target_var, file_has_input)
322
353
  continue
@@ -350,6 +381,8 @@ class Finder:
350
381
  def scan_xml(self, rel: str, text: str) -> None:
351
382
  if not re.search(r"<mapper\b|<sqlMap\b|<!DOCTYPE\s+(mapper|sqlMap)", text):
352
383
  return
384
+ if re.search(r"<#(?:if|list|assign|macro|include)\b", text):
385
+ return # FreeMarker code-generator template: ${...} is the template language, not MyBatis
353
386
  lines = text.splitlines()
354
387
  in_stmt = False
355
388
  for i, line in enumerate(lines, 1):