Commit f14f7ec
authored
fix(security): replace insecure TrustManager with default JVM trust validation (#157)
* fix(security): replace insecure TrustManager with default JVM trust validation
HIGH-severity TLS validation bypass (CWE-295, code-scanning alert #8).
The previous HttpClientFactory honored AxonFlowConfig.insecureSkipVerify(true)
as a single-flag opt-in to a permissive X509TrustManager whose
checkClientTrusted / checkServerTrusted methods returned void and whose
getAcceptedIssuers returned an empty array. With the flag set, the SDK
trusted ANY server certificate over HTTPS, including attacker-presented
certs in MITM scenarios.
Fix: double-gate the insecure path so it activates only when BOTH
- AxonFlowConfig#insecureSkipVerify(true) is set on the builder, AND
- AXONFLOW_INSECURE_TLS is set to "true" (case-insensitive) or "1" in
the runtime environment
are present. Otherwise the JVM's default TrustManager (validating against
the system + JDK trust store) is used. When the builder flag is set but
the env var is not, the SDK logs a warning at client construction time
and keeps verification enabled. When the insecure path actually
activates, a loud *** SECURITY WARNING *** is logged.
Rationale for keeping a development carve-out: AxonFlow demos and
self-hosted local stacks ship with self-signed agent certs in some
configurations; teams need a way to opt in for local dev without a
DIY trust-store override. The double-gate makes accidental production
bypass much harder: a stray builder flag in app code is no longer
sufficient.
Tests: HttpClientFactoryTest gains two assertions. The first verifies
that with insecureSkipVerify(true) but no env var, the resulting
OkHttpClient retains OkHttp's default OkHostnameVerifier (not the
permissive (h, s) -> true verifier). The second verifies the env-var
gate helper returns false when AXONFLOW_INSECURE_TLS is unset, which
is the default in CI and dev shells.
Default behavior in production: standard TLS validation against the
JDK + system trust store. No regressions in the existing 1224-test
suite (mvn test).
Resolves code-scanning alert #8.
* test(security): add positive-path test for insecure TLS double-gate
Code review on PR #157 caught that the existing tests only assert the
SAFE/DEFAULT path and the env-var helper's UNSET behaviour. They never
exercise the positive path where BOTH gates are present and the insecure
TrustManager actually activates — the one combination that ships a
trust-all SSLContext and permissive HostnameVerifier.
This commit adds four tests to close the gap:
- envVarHelperShouldBeTrueWhenSetToTrue / ...WhenSetToOne
Confirm isInsecureTlsEnvVarEnabled() honours both accepted values.
- shouldActivateInsecurePathWhenBothGatesArePresent
The positive-path regression. Builds an OkHttpClient with
insecureSkipVerify(true) AND AXONFLOW_INSECURE_TLS=true, then asserts:
1. hostnameVerifier class name does NOT contain "OkHostnameVerifier"
(i.e. the synthetic permissive lambda is installed),
2. that verifier returns true for an arbitrary hostname,
3. sslSocketFactory() is NOT the same instance as the one a
default-path client produces (trust-all SSLContext is wired in).
- shouldKeepDefaultPathWhenOnlyEnvVarIsSet
Complementary negative path — env var alone, without the builder
flag, must keep OkHttp's default OkHostnameVerifier. Together with
the existing "neither flag set" test, this proves the gate is
symmetric: both must be present to flip behaviour.
Env-var injection is done with junit-pioneer 2.2.0's
@SetEnvironmentVariable, which scopes the variable to a single test
method via reflective access into java.base/java.util. The required
JDK 17+ --add-opens flags are added to the surefire argLine alongside
the existing -Dnet.bytebuddy.experimental=true.
Full suite: 1228/1228 green.1 parent fa27583 commit f14f7ec
5 files changed
Lines changed: 172 additions & 12 deletions
File tree
- src
- main/java/com/getaxonflow/sdk
- util
- test/java/com/getaxonflow/sdk/util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
| |||
183 | 191 | | |
184 | 192 | | |
185 | 193 | | |
186 | | - | |
| 194 | + | |
| 195 | + | |
187 | 196 | | |
188 | 197 | | |
189 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
466 | | - | |
| 466 | + | |
467 | 467 | | |
468 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
469 | 473 | | |
470 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
471 | 482 | | |
472 | 483 | | |
473 | 484 | | |
| |||
Lines changed: 43 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
41 | 55 | | |
42 | 56 | | |
43 | 57 | | |
| |||
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
53 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
54 | 78 | | |
55 | 79 | | |
56 | 80 | | |
| |||
111 | 135 | | |
112 | 136 | | |
113 | 137 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
117 | 144 | | |
118 | 145 | | |
119 | 146 | | |
120 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
121 | 160 | | |
Lines changed: 101 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
81 | | - | |
82 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
83 | 180 | | |
84 | 181 | | |
0 commit comments