@voxgig/sdkgen 4.49.1 → 4.51.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 (218) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/debug.c +1 -0
  30. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  31. package/project/.sdk/tm/c/feature/telemetry.c +1 -0
  32. package/project/.sdk/tm/c/tests/feature_test.c +142 -0
  33. package/project/.sdk/tm/c/utility/clean.c +26 -33
  34. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  35. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  36. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  37. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  38. package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
  39. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
  40. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  41. package/project/.sdk/tm/cpp/Makefile +5 -0
  42. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  43. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  44. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  45. package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
  46. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  47. package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
  48. package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
  49. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  50. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  51. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  52. package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
  53. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  54. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
  55. package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
  56. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  57. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  58. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  59. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  60. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  61. package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
  62. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  63. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
  64. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  65. package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
  66. package/project/.sdk/tm/go/core/context.go +6 -0
  67. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  68. package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
  69. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  70. package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
  71. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  72. package/project/.sdk/tm/go/test/feature_test.go +101 -0
  73. package/project/.sdk/tm/go/utility/clean.go +5 -7
  74. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  75. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  76. package/project/.sdk/tm/java/core/Context.java +9 -0
  77. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  78. package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
  79. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  80. package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
  81. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  82. package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
  83. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  84. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  85. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  86. package/project/.sdk/tm/js/src/Context.js +4 -0
  87. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  88. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  89. package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
  90. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  91. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  92. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  93. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  94. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
  95. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  96. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  97. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  98. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  99. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  100. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  101. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  102. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  103. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  104. package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
  105. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  106. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
  107. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
  108. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  109. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  110. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  111. package/project/.sdk/tm/lua/core/context.lua +6 -0
  112. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  113. package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
  114. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  115. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
  116. package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
  117. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  118. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  119. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  120. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  121. package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
  122. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  123. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  124. package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
  125. package/project/.sdk/tm/perl/core/context.pm +3 -0
  126. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  127. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  128. package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
  129. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  130. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
  131. package/project/.sdk/tm/perl/t/feature.t +86 -0
  132. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  133. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  134. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  135. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  136. package/project/.sdk/tm/php/core/Context.php +4 -0
  137. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  138. package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
  139. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  140. package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
  141. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  142. package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
  143. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  144. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  145. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  146. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  147. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  148. package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
  149. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  150. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
  151. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  152. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  153. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  154. package/project/.sdk/tm/py/test/test_feature.py +73 -0
  155. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  156. package/project/.sdk/tm/rb/core/context.rb +4 -1
  157. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  158. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  159. package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
  160. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  161. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
  162. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  163. package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
  164. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  165. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  166. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  167. package/project/.sdk/tm/rust/core/context.rs +8 -0
  168. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  169. package/project/.sdk/tm/rust/feature/debug.rs +1 -0
  170. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  171. package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
  172. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  173. package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
  174. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  175. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  176. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  177. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  178. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  179. package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
  180. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  181. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
  182. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
  183. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  184. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  185. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  186. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  187. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  188. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
  189. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  190. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
  191. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  192. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  193. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  194. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
  195. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  196. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  197. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  198. package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
  199. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  200. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  201. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  202. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  203. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
  204. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  205. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  206. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  207. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  208. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  209. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  210. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  211. package/project/.sdk/tm/zig/core/context.zig +5 -0
  212. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  213. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  214. package/project/.sdk/tm/zig/feature/debug.zig +1 -0
  215. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  216. package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
  217. package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
  218. package/project/sdkgen-package.json +1 -1
package/bin/voxgig-sdkgen CHANGED
@@ -8,7 +8,7 @@ const { Shape, Nof, Skip } = require('shape')
8
8
 
9
9
  const { SdkGen } = require('../dist/sdkgen.js')
10
10
 
11
- const VERSION = '4.49.1'
11
+ const VERSION = '4.51.0'
12
12
  const KONSOLE = console
13
13
 
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/sdkgen",
3
- "version": "4.49.1",
3
+ "version": "4.51.0",
4
4
  "main": "dist/sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -3,7 +3,7 @@ main: kit: feature: cache: {
3
3
 
4
4
  name: key()
5
5
  title: "Response cache"
6
- description: "Response caching for safe read requests"
6
+ description: "Per-client response caching for safe read requests"
7
7
  version: '0.0.1'
8
8
  active: true
9
9
  base: 'BASE'
@@ -12,16 +12,18 @@ main: kit: feature: cache: {
12
12
  config: {
13
13
  options: {
14
14
  active: false
15
- # time-to-live in milliseconds
15
+ # time-to-live in milliseconds; a response's Cache-Control max-age caps it
16
16
  ttl: 5000
17
- # maximum cached entries (oldest evicted)
17
+ # maximum cached entries in this client's store (oldest evicted)
18
18
  max: 256
19
- # cacheable request methods
19
+ # cacheable request methods; any other but GET and HEAD is a write, which
20
+ # drops its own path, everything under it and its parent path's entry
20
21
  methods: ['GET']
21
22
  }
22
23
  }
23
24
 
24
25
  # Cache wraps the transport in init(); it dispatches no pipeline hooks.
26
+ # The key is the method, the URL and a keyed digest of the request headers.
25
27
  hook: {}
26
28
  }
27
29
 
@@ -34,6 +34,12 @@ main: kit: feature: &: target: lua: deps: &: {
34
34
  }
35
35
 
36
36
 
37
+ main: kit: target: lua: feature: {
38
+ trim: true
39
+ fullset: ['test/feature_test.lua']
40
+ }
41
+
42
+
37
43
  main: kit: target: lua: publish: {
38
44
  registry: {
39
45
  name: 'luarocks'
@@ -92,11 +92,10 @@ FEATURE_TEST_SRCS += $(wildcard tests/feature/${fname}/*.c)
92
92
  Content(`
93
93
  # A plugin group is active: the selected kinds and the five shared helpers
94
94
  # they call (the socket HTTP client and its OpenSSL binding, the encoders,
95
- # the clock and the child-process launcher), with the two external
96
- # libraries they bring - OpenSSL for the vault kinds' TLS, libcurl for the
97
- # token-exchange transport of last resort in kinds.c.
95
+ # the clock and the child-process launcher), with the external library they
96
+ # bring - OpenSSL for the vault kinds' TLS.
98
97
  FEATURE_SRCS += $(wildcard feature/${fname}/plugins/*.c)
99
- LDLIBS += -lssl -lcrypto -lcurl
98
+ LDLIBS += -lssl -lcrypto
100
99
  `)
101
100
  }
102
101
  })
@@ -138,136 +137,6 @@ ${syms.map((sym: string, i: number) => ` ${fname.toUpperCase()}_KINDS[${i}] = $
138
137
  return ${fname.toUpperCase()}_KINDS;
139
138
  }
140
139
  `}`)
141
-
142
- if ('secrets' !== fname) return
143
-
144
- if (0 === groups) {
145
- Content(`
146
- // THE EXCHANGE TRANSPORT OF LAST RESORT, when no plugin group is active: the
147
- // SDK's own client (utility/http.c), called directly rather than through
148
- // the transport this feature wraps, which the token request must never pass
149
- // back through. Reached only by an exchange whose caller supplied no
150
- // system.fetch; a chain that resolves a static credential never comes here.
151
- voxgig_value* secrets_rawfetch(Context* ctx, const char* url,
152
- voxgig_value* fetchdef, PNError** err) {
153
- return http_fetch(ctx, url, fetchdef, err);
154
- }
155
- `)
156
- return
157
- }
158
-
159
- Content(`
160
- // THE EXCHANGE TRANSPORT OF LAST RESORT (go's rawExchangeFetch): plain
161
- // libcurl, answering the same transport-shaped map the system.fetch seam
162
- // promises ({status, statusText, headers, json(), body}). It exists so an
163
- // exchange works with ordinary SDK options - requiring a custom transport
164
- // for the COMMON case would refuse every live token purchase before a
165
- // request was made. Deliberately NOT the SDK transport: that is what the
166
- // secrets feature wraps, and sending the token request back through it
167
- // would recurse on the first expiry.
168
- //
169
- // libcurl is linked because a plugin group is active in this model; the
170
- // Makefile adds -lcurl on exactly that condition.
171
-
172
- #include <curl/curl.h>
173
-
174
- typedef struct {
175
- char* data;
176
- size_t len;
177
- } SecretsBuf;
178
-
179
- static size_t secrets_curl_write(char* ptr, size_t size, size_t nmemb, void* ud) {
180
- SecretsBuf* b = (SecretsBuf*)ud;
181
- size_t add = size * nmemb;
182
- char* grown = (char*)realloc(b->data, b->len + add + 1);
183
- if (NULL == grown) return 0;
184
- b->data = grown;
185
- memcpy(b->data + b->len, ptr, add);
186
- b->len += add;
187
- b->data[b->len] = '\\0';
188
- return add;
189
- }
190
-
191
- voxgig_value* secrets_rawfetch(Context* ctx, const char* url,
192
- voxgig_value* fetchdef, PNError** err) {
193
- static bool inited = false;
194
- *err = NULL;
195
- if (!inited) {
196
- curl_global_init(CURL_GLOBAL_DEFAULT);
197
- inited = true;
198
- }
199
-
200
- CURL* curl = curl_easy_init();
201
- if (NULL == curl) {
202
- *err = context_make_error(ctx, "secrets_transport", "secrets: curl_easy_init failed");
203
- return NULL;
204
- }
205
-
206
- const char* method = get_str(fetchdef, "method");
207
- if (NULL == method || '\\0' == method[0]) method = "POST";
208
-
209
- struct curl_slist* hdrs = NULL;
210
- voxgig_value* headers = getp(fetchdef, "headers");
211
- if (voxgig_is_map(headers)) {
212
- voxgig_map* hm = voxgig_as_map(headers);
213
- for (size_t i = 0; i < hm->len; i++) {
214
- if (!voxgig_is_string(hm->entries[i].value)) continue;
215
- size_t klen = strlen(hm->entries[i].key);
216
- const char* v = voxgig_as_string(hm->entries[i].value);
217
- char* line = (char*)malloc(klen + 2 + strlen(v) + 1);
218
- sprintf(line, "%s: %s", hm->entries[i].key, v);
219
- hdrs = curl_slist_append(hdrs, line);
220
- free(line);
221
- }
222
- }
223
-
224
- SecretsBuf body = {NULL, 0};
225
- curl_easy_setopt(curl, CURLOPT_URL, url);
226
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method);
227
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hdrs);
228
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
229
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
230
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, secrets_curl_write);
231
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body);
232
- const char* reqbody = get_str(fetchdef, "body");
233
- if (NULL != reqbody) {
234
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, reqbody);
235
- }
236
-
237
- CURLcode rc = curl_easy_perform(curl);
238
- long status = 0;
239
- // Where a redirect points, resolved by curl, which follows none.
240
- voxgig_value* rheaders = v_map();
241
- if (CURLE_OK == rc) {
242
- char* location = NULL;
243
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
244
- curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &location);
245
- if (NULL != location) setp(rheaders, "location", v_str(location));
246
- }
247
- curl_slist_free_all(hdrs);
248
- curl_easy_cleanup(curl);
249
-
250
- if (CURLE_OK != rc) {
251
- char msg[512];
252
- snprintf(msg, sizeof(msg), "secrets: token exchange transport failed: %s (URL was: \\"%s\\")",
253
- curl_easy_strerror(rc), url);
254
- free(body.data);
255
- *err = context_make_error(ctx, "secrets_transport", msg);
256
- return NULL;
257
- }
258
-
259
- const char* text = body.data ? body.data : "";
260
- voxgig_value* parsed = json_parse(text);
261
- voxgig_value* out = cmap(5,
262
- "status", v_num((double)status),
263
- "statusText", v_str(status >= 400 ? "ERR" : "OK"),
264
- "headers", rheaders,
265
- "json", json_thunk(parsed),
266
- "body", v_str(text));
267
- free(body.data);
268
- return out;
269
- }
270
- `)
271
140
  })
272
141
  })
273
142
  }
@@ -910,6 +910,20 @@ int main(void) {
910
910
  "a transport failure should fail direct()");
911
911
  push_value("direct", direct);
912
912
 
913
+ // The clean registry holds every credential in plain form, and is no option.
914
+ {
915
+ voxgig_value* held = sdk_options_map(${ident}_sdk_new(offline(cmap(1,
916
+ "apikey", v_str(CANARY_APIKEY))), NULL));
917
+ char* heldjson = voxgig_jsonify(held, NULL);
918
+ CHECK_STR_EQ(header(held, "apikey"), CANARY_APIKEY, "options_map keeps the caller's apikey");
919
+ char* at = strstr(heldjson, CANARY_APIKEY);
920
+ if (at) memmove(at, at + strlen(CANARY_APIKEY), strlen(at + strlen(CANARY_APIKEY)) + 1);
921
+ char heldfound[4096];
922
+ CHECK(0 == leaks(heldjson, heldfound, sizeof(heldfound)),
923
+ "options_map carries a credential beyond the option the caller set");
924
+ if (heldfound[0]) fprintf(stderr, "options_map: [%s]\\n", heldfound);
925
+ }
926
+
913
927
  size_t nleaks = 0;
914
928
  char found[4096];
915
929
  for (size_t i = 0; i < NSINKS; i++) {
@@ -432,9 +432,8 @@ ${candidates(entity)}
432
432
  ;; The generated config's own clean block is read beside the
433
433
  ;; caller's, and is not changed by it.
434
434
  (let [config (vs/jm "options" (vs/jm "clean" (vs/jm "keys" "zzsens" "values" (:config CANARY))))
435
- built (core/u-make-options
436
- (atom {:config config :options (vs/jm "clean" (vs/jm "values" (:value CANARY)))}))
437
- cfgctx (atom {:options built})
435
+ cfgctx (atom {:config config :options (vs/jm "clean" (vs/jm "values" (:value CANARY)))})
436
+ _ (core/oset! cfgctx :options (core/u-make-options cfgctx))
438
437
  seeded (core/u-clean cfgctx (str "config " (:config CANARY) " caller " (:value CANARY)))]
439
438
  (swap! sinks conj {:name "config-clean" :text (str seeded)})
440
439
  (t/is-eq seeded (str "config " MASK " caller " MASK) "the config's clean values are registered")
@@ -465,6 +464,12 @@ ${candidates(entity)}
465
464
  :record (core/u-clean root "record PLAINRECORD-t5r3e1w9")
466
465
  :alias (core/u-clean root "alias PLAINALIAS-m2n4b6v8")
467
466
  :rule (core/u-clean root "rule PLAINRULE-k7j5h3g1")}))
467
+ ;; The clean registry holds every credential in plain form, and is no option.
468
+ (let [held (core/client-options-map (construct (vs/jm "apikey" (:apikey CANARY))))
469
+ text (pr-str held)]
470
+ (t/is-eq (vs/getprop held "apikey") (:apikey CANARY) "options-map keeps the caller's apikey")
471
+ (t/is-eq (leaks (str/replace-first text (:apikey CANARY) "")) []
472
+ (str "options-map carries a credential beyond the option the caller set: " text)))
468
473
  (let [leaked (filterv (fn [s] (seq (leaks (:text s)))) @sinks)]
469
474
  (println (str "clean: swept " (count @sinks) " surface(s), " (count leaked) " leak(s)"))
470
475
  (t/is-eq (count leaked) 0
@@ -531,7 +536,7 @@ ${candidates(entity)}
531
536
  (t/run-check rec "clean-a-registered-value-used-as-a-property-name"
532
537
  (fn []
533
538
  (let [cfg (core/make-clean-config (vs/jm "keys" "key,secret,token"))
534
- ctx (atom {:options (vs/jm "__derived__" (vs/jm "clean" cfg))})]
539
+ ctx (atom {:cleancfg cfg})]
535
540
  (core/u-clean-add ctx "ZZVAL-abc123")
536
541
  (core/u-clean-add ctx "ZZVAL-xyz789")
537
542
  (let [out (core/u-clean ctx (vs/jm "ZZVAL-abc123" 1 "ZZVAL-xyz789" 2 "plain" 3))]
@@ -543,7 +548,7 @@ ${candidates(entity)}
543
548
  (t/run-check rec "clean-add-sensitive-registers-every-scalar-under-a-sensitive-name"
544
549
  (fn []
545
550
  (let [cfg (core/make-clean-config (vs/jm "keys" "key,secret,token"))
546
- ctx (atom {:options (vs/jm "__derived__" (vs/jm "clean" cfg))})
551
+ ctx (atom {:cleancfg cfg})
547
552
  _ (core/u-clean-add-sensitive ctx (vs/jm "apikey" (vs/jm "value" "NESTED-SECRET-1")
548
553
  "headers" (vs/jm "X-Api-Token" (vs/jt "LISTED-SECRET-2"))
549
554
  "secret" 123456789
@@ -738,6 +738,19 @@ static void no_credential_leaves_the_sdk() {
738
738
  ASSERT_TRUE(is_false(getp(direct, "ok")), "a transport failure should fail direct()");
739
739
  addForms(sinks, "direct", direct);
740
740
 
741
+ // The clean registry holds every credential in plain form, and is no option.
742
+ {
743
+ Value held = construct(vmap({{"apikey", Value(CANARY_APIKEY)}}))->optionsMap();
744
+ std::string heldjson = vs::jsonify(held, 0);
745
+ ASSERT_TRUE(getp(held, "apikey").is_string() && CANARY_APIKEY == getp(held, "apikey").as_string(),
746
+ "optionsMap keeps the caller's apikey");
747
+ std::string heldrest = heldjson;
748
+ size_t at = heldrest.find(CANARY_APIKEY);
749
+ if (std::string::npos != at) heldrest.erase(at, CANARY_APIKEY.size());
750
+ ASSERT_TRUE(leaks(heldrest).empty(),
751
+ "optionsMap carries a credential beyond the option the caller set: " + heldjson);
752
+ }
753
+
741
754
  std::string leaked;
742
755
  int leakcount = 0;
743
756
  for (const Sink& s : sinks) {
@@ -876,6 +876,15 @@ ${candidateLines}
876
876
  new ${Name}Error("code_" + CanaryValue, "coded", null));
877
877
  sinks.AddRange(FormsOf("coded", coded));
878
878
 
879
+ // The clean registry holds every credential in plain form, and is no option.
880
+ var held = Construct(new Dictionary<string, object?> { ["apikey"] = CanaryApikey }).OptionsMap();
881
+ var heldtext = Render(held);
882
+ Assert.Equal(CanaryApikey, held.GetValueOrDefault("apikey"));
883
+ var heldat = heldtext.IndexOf(CanaryApikey, StringComparison.Ordinal);
884
+ var heldrest = heldat < 0 ? heldtext : heldtext.Remove(heldat, CanaryApikey.Length);
885
+ Assert.True(0 == Leaks(heldrest).Count,
886
+ "OptionsMap carries a credential beyond the option the caller set: " + heldtext);
887
+
879
888
  var leaked = sinks
880
889
  .Select(s => (s.Name, Found: Leaks(s.Text)))
881
890
  .Where(s => 0 < s.Found.Count)
@@ -613,6 +613,13 @@ ${candidates(Name, entity, model)}
613
613
  assert S.getprop(direct, "ok") == false, "a transport failure should fail direct()"
614
614
  add(sinks, forms("direct", S.getprop(direct, "err")))
615
615
 
616
+ # The clean registry holds every credential in plain form, and is no option.
617
+ held = ${Name}.options_map(construct(S.jm(["apikey", @canary.apikey])))
618
+ heldjson = S.jsonify(held)
619
+ assert S.getprop(held, "apikey") == @canary.apikey
620
+ assert leaks(String.replace(heldjson, @canary.apikey, "", global: false)) == [],
621
+ "options_map carries a credential beyond the option the caller set: " <> heldjson
622
+
616
623
  all = sink_list(sinks)
617
624
  leaked = Enum.filter(all, fn s -> leaks(s.text) != [] end)
618
625
 
@@ -683,7 +690,7 @@ ${candidates(Name, entity, model)}
683
690
 
684
691
  test "a registered value used as a property name is masked, collisions kept" do
685
692
  cfg = ${Name}.Utility.make_clean_config(S.jm(["keys", "key,secret,token"]))
686
- ctx = S.jm(["options", S.jm(["__derived__", S.jm(["clean", cfg])])])
693
+ ctx = S.jm(["cleancfg", cfg])
687
694
  ${Name}.Utility.clean_add_impl(ctx, "ZZVAL-abc123")
688
695
  ${Name}.Utility.clean_add_impl(ctx, "ZZVAL-xyz789")
689
696
  out = ${Name}.Utility.clean_impl(ctx, S.jm(["ZZVAL-abc123", 1, "ZZVAL-xyz789", 2, "plain", 3]))
@@ -724,7 +731,8 @@ ${candidates(Name, entity, model)}
724
731
  test "the generated config's own clean block is honoured" do
725
732
  config = S.jm(["options", S.jm(["clean", S.jm(["keys", "zzsens", "values", "CONFIG-SEEDED-1"])])])
726
733
  ctx = S.jm(["config", config, "options", S.jm(["clean", S.jm(["values", "CALLER-SEEDED-2"])])])
727
- cctx = S.jm(["options", ${Name}.Utility.make_options_impl(ctx)])
734
+ S.setprop(ctx, "options", ${Name}.Utility.make_options_impl(ctx))
735
+ cctx = ctx
728
736
 
729
737
  assert ${Name}.Utility.clean_impl(cctx, "a CONFIG-SEEDED-1 b CALLER-SEEDED-2") ==
730
738
  "a " <> @mask <> " b " <> @mask
@@ -738,7 +746,7 @@ ${candidates(Name, entity, model)}
738
746
 
739
747
  test "clean_add_sensitive registers every scalar under a sensitive name, at any depth" do
740
748
  cfg = ${Name}.Utility.make_clean_config(S.jm(["keys", "key,secret,token"]))
741
- ctx = S.jm(["options", S.jm(["__derived__", S.jm(["clean", cfg])])])
749
+ ctx = S.jm(["cleancfg", cfg])
742
750
 
743
751
  ${Name}.Utility.clean_add_sensitive(ctx, S.jm([
744
752
  "apikey", S.jm(["value", "NESTED-SECRET-1"]),
@@ -190,6 +190,33 @@ func cleanContentLeaks(text string, forms [][2]string) []string {
190
190
 
191
191
  // The default prints and the JSON form of a value: what a log line, a panic
192
192
  // message or a structured logger would carry.
193
+ // Every string a value holds, unexported fields included, as a debugger shows them.
194
+ func cleanDump(v reflect.Value, depth int) string {
195
+ if !v.IsValid() || 12 < depth {
196
+ return ""
197
+ }
198
+ parts := []string{}
199
+ switch v.Kind() {
200
+ case reflect.String:
201
+ return v.String()
202
+ case reflect.Ptr, reflect.Interface:
203
+ return cleanDump(v.Elem(), depth+1)
204
+ case reflect.Map:
205
+ for _, k := range v.MapKeys() {
206
+ parts = append(parts, cleanDump(k, depth+1)+"="+cleanDump(v.MapIndex(k), depth+1))
207
+ }
208
+ case reflect.Slice, reflect.Array:
209
+ for i := 0; i < v.Len(); i++ {
210
+ parts = append(parts, cleanDump(v.Index(i), depth+1))
211
+ }
212
+ case reflect.Struct:
213
+ for i := 0; i < v.NumField(); i++ {
214
+ parts = append(parts, cleanDump(v.Field(i), depth+1))
215
+ }
216
+ }
217
+ return "{" + strings.Join(parts, " ") + "}"
218
+ }
219
+
193
220
  func cleanSurfaces(name string, val any) []cleanSink {
194
221
  out := []cleanSink{}
195
222
  if raw, err := json.Marshal(val); err == nil {
@@ -872,15 +899,16 @@ func TestCleanSweep(t *testing.T) {
872
899
  // and is not changed by it.
873
900
  cfgclean := map[string]any{"keys": "zzsens", "values": cleanCanary["config"]}
874
901
  util := probe.GetUtility()
875
- cfgopts, err := util.MakeOptions(&core.Context{
902
+ cfgctx := &core.Context{
876
903
  Utility: util,
877
904
  Config: map[string]any{"options": map[string]any{"clean": cfgclean}},
878
905
  Options: map[string]any{"clean": map[string]any{"values": cleanCanary["value"]}},
879
- })
906
+ }
907
+ cfgopts, err := util.MakeOptions(cfgctx)
880
908
  if err != nil {
881
909
  t.Fatal(err)
882
910
  }
883
- cfgctx := &core.Context{Options: cfgopts}
911
+ cfgctx.Options = cfgopts
884
912
  seeded, _ := util.Clean(cfgctx, "config "+cleanCanary["config"]+" caller "+cleanCanary["value"]).(string)
885
913
  sinks = append(sinks, cleanSink{"config-clean", seeded})
886
914
  if want := "config " + cleanMask + " caller " + cleanMask; seeded != want {
@@ -941,6 +969,14 @@ func TestCleanSweep(t *testing.T) {
941
969
  t.Errorf("an rbac rule keyed by entity and operation was registered: %q", got)
942
970
  }
943
971
 
972
+ // The clean registry holds every credential in plain form, and is no option.
973
+ held := cleanNew(map[string]any{"apikey": cleanCanary["apikey"]}).OptionsMap()
974
+ helddump := cleanDump(reflect.ValueOf(held), 0)
975
+ if held["apikey"] != cleanCanary["apikey"] ||
976
+ 0 < len(cleanLeaks(strings.Replace(helddump, cleanCanary["apikey"], "", 1))) {
977
+ t.Errorf("OptionsMap() carries a credential beyond the option the caller set: %s", helddump)
978
+ }
979
+
944
980
  leaked := []string{}
945
981
  for _, s := range sinks {
946
982
  if found := cleanLeaks(s.text); 0 < len(found) {
@@ -971,6 +971,14 @@ public class CleanTest {
971
971
  release(handler);
972
972
  }
973
973
 
974
+ // The clean registry holds every credential in plain form, and is no option.
975
+ Map<String, Object> held = construct(jm("apikey", CANARY_APIKEY)).optionsMap();
976
+ String heldjson = Struct.jsonify(plain(held, 0, new IdentityHashMap<>()));
977
+ assertEquals(CANARY_APIKEY, held.get("apikey"));
978
+ assertEquals(List.of(), leaks(heldjson.replaceFirst(
979
+ java.util.regex.Pattern.quote("\\"" + CANARY_APIKEY + "\\""), "")),
980
+ "optionsMap carries a credential beyond the option the caller set: " + heldjson);
981
+
974
982
  List<String> leaked = new ArrayList<>();
975
983
  for (Sink s : sinks) {
976
984
  List<String> found = leaks(s.text);
@@ -465,9 +465,10 @@ describe('clean', () => {
465
465
  // and is not changed by it.
466
466
  const util = makeSdk(SCENARIOS[0], sinks).utility()
467
467
  const cfgclean = { keys: 'zzsens', values: CANARY.config }
468
- const built = util.makeOptions({ utility: util, config: { options: { clean: cfgclean } },
469
- options: { clean: { values: CANARY.value } } })
470
- const seeded = util.clean({ options: built }, 'config ' + CANARY.config + ' caller ' + CANARY.value)
468
+ const built = { utility: util, config: { options: { clean: cfgclean } },
469
+ options: { clean: { values: CANARY.value } } }
470
+ built.options = util.makeOptions(built)
471
+ const seeded = util.clean(built, 'config ' + CANARY.config + ' caller ' + CANARY.value)
471
472
  sinks.push({ name: 'config-clean', text: seeded })
472
473
 
473
474
  // A feature's name is not a field name: only the sensitive names inside
@@ -480,7 +481,7 @@ describe('clean', () => {
480
481
  rbac: { active: false, rules: { 'zztoken.load': 'PLAINRULE-k7j5h3g1' } },
481
482
  test: { active: false, entity: { zztoken: { ZZTOKEN01: { note: 'PLAINRECORD-t5r3e1w9' } } } },
482
483
  }, entity: { zztoken: { alias: { zzkey: 'PLAINALIAS-m2n4b6v8' } } } })
483
- const fctx = { options: featured._options }
484
+ const fctx = featured._rootctx
484
485
 
485
486
  // The raw path returns its failure rather than throwing it, a
486
487
  // DOMException's included.
@@ -492,6 +493,13 @@ describe('clean', () => {
492
493
  ok(false === raw.ok && null != raw.err, 'a transport failure should fail direct()')
493
494
  sinks.push(...forms('direct', raw.err))
494
495
 
496
+ // The clean registry holds every credential in plain form, and is no option.
497
+ const held = construct({ apikey: CANARY.apikey }).options()
498
+ const optsjson = JSON.stringify(held)
499
+ equal(held.apikey, CANARY.apikey)
500
+ deepStrictEqual(leaks(optsjson.replace(JSON.stringify(CANARY.apikey), '')), [],
501
+ 'options() carries a credential beyond the option the caller set: ' + optsjson)
502
+
495
503
  const leaked = sinks
496
504
  .map((s) => ({ name: s.name, found: leaks(s.text) }))
497
505
  .filter((s) => 0 < s.found.length)
@@ -525,7 +533,7 @@ describe('clean', () => {
525
533
  equal(header(notfound.spec.headers, 'x-custom-token'), MASK)
526
534
 
527
535
  equal(seeded, 'config ' + MASK + ' caller ' + MASK)
528
- deepStrictEqual(util.clean({ options: built }, { my_zzsens: 'x', other: 'y' }), { my_zzsens: MASK, other: 'y' })
536
+ deepStrictEqual(util.clean(built, { my_zzsens: 'x', other: 'y' }), { my_zzsens: MASK, other: 'y' })
529
537
  deepStrictEqual(cfgclean, { keys: 'zzsens', values: CANARY.config })
530
538
 
531
539
  equal(featured.utility().clean(fctx, 'kind PLAINSETTING-q8w2e4r6'), 'kind PLAINSETTING-q8w2e4r6')
@@ -190,6 +190,21 @@ class CleanTest {
190
190
  else -> v
191
191
  }
192
192
 
193
+ // Every string a value holds, private fields included, as a debugger shows them.
194
+ private fun dump(v: Any?, depth: Int = 0): String = when {
195
+ v == null || 12 < depth -> ""
196
+ v is String -> v
197
+ v is Map<*, *> -> v.entries.joinToString(" ", "{", "}") {
198
+ dump(it.key, depth + 1) + "=" + dump(it.value, depth + 1)
199
+ }
200
+ v is Iterable<*> -> v.joinToString(" ", "[", "]") { dump(it, depth + 1) }
201
+ v.javaClass.name.startsWith("java.") || v.javaClass.name.startsWith("kotlin.") -> v.toString()
202
+ else -> v.javaClass.declaredFields.filter { !Modifier.isStatic(it.modifiers) }
203
+ .joinToString(" ", "{", "}") { f ->
204
+ runCatching { f.trySetAccessible(); dump(f.get(v), depth + 1) }.getOrDefault("")
205
+ }
206
+ }
207
+
193
208
  private fun stack(err: Throwable): String {
194
209
  val sw = StringWriter()
195
210
  err.printStackTrace(PrintWriter(sw))
@@ -684,6 +699,13 @@ class CleanTest {
684
699
  linkedMapOf<String, Any?>(canaryValue to 1, canaryHeader to 2, "plain" to 3))
685
700
  sinks.addAll(surfaces("named", named))
686
701
 
702
+ // The clean registry holds every credential in plain form, and is no option.
703
+ val held = construct(linkedMapOf<String, Any?>("apikey" to canaryApikey)).optionsMap()
704
+ val helddump = dump(held)
705
+ assertEquals(canaryApikey, held["apikey"])
706
+ assertEquals(listOf<String>(), leaks(helddump.replaceFirst(canaryApikey, "")),
707
+ "optionsMap carries a credential beyond the option the caller set: " + helddump)
708
+
687
709
  val leaked = sinks
688
710
  .map { Pair(it.name, leaks(it.text)) }
689
711
  .filter { it.second.isNotEmpty() }
@@ -798,6 +798,15 @@ describe("clean", function()
798
798
  assert.are.same({ [MASK] = 1, [MASK .. "#1"] = 2, plain = 3 }, named)
799
799
  append(sinks, surfaces("named", named))
800
800
 
801
+ -- The clean registry holds every credential in plain form, and is no option.
802
+ local held = construct({ apikey = CANARY.apikey }):options_map()
803
+ local heldjson = tojson(held)
804
+ assert.are.equal(CANARY.apikey, held.apikey)
805
+ local at, upto = string.find(heldjson, CANARY.apikey, 1, true)
806
+ local heldrest = at and (heldjson:sub(1, at - 1) .. heldjson:sub(upto + 1)) or heldjson
807
+ assert.are.same({}, leaks(heldrest),
808
+ "options_map carries a credential beyond the option the caller set: " .. heldjson)
809
+
801
810
  local leaked = {}
802
811
  for _, s in ipairs(sinks) do
803
812
  local found = leaks(s.text)
@@ -898,12 +907,12 @@ describe("clean", function()
898
907
  it("the generated config's own clean block is honoured", function()
899
908
  local utility = construct({}):get_utility()
900
909
  local config = { options = { clean = { keys = "zzsens", values = "CONFIG-SEEDED-1" } } }
901
- local opts = utility.make_options({
910
+ local ctx = {
902
911
  utility = utility,
903
912
  config = config,
904
913
  options = { clean = { values = "CALLER-SEEDED-2" } },
905
- })
906
- local ctx = { options = opts }
914
+ }
915
+ ctx.options = utility.make_options(ctx)
907
916
  assert.are.equal("a " .. MASK .. " b " .. MASK,
908
917
  utility.clean(ctx, "a CONFIG-SEEDED-1 b CALLER-SEEDED-2"))
909
918
  assert.are.same({ my_zzsens = MASK, other = "y" }, utility.clean(ctx, { my_zzsens = "x", other = "y" }))
@@ -490,6 +490,19 @@ let () =
490
490
  let direct = Sdk_client.direct (make_sdk (List.nth scenarios 3) sinks []) (jo [("path", Str "raw")]) in
491
491
  check "a transport failure should fail direct()" (getp direct "ok" = Bool false);
492
492
  value_forms sinks "direct" direct;
493
+ (* The clean registry holds every credential in plain form, and is no option. *)
494
+ let key = canary_of "apikey" in
495
+ let held = client_options_map (construct (jo [("apikey", Str key)])) in
496
+ let heldjson = jsonify held in
497
+ check_vstr "options_map keeps the caller's apikey" (getp held "apikey") key;
498
+ let heldrest =
499
+ let n = String.length key and m = String.length heldjson in
500
+ let rec find i = if i + n > m then None else if String.sub heldjson i n = key then Some i else find (i + 1) in
501
+ match find 0 with
502
+ | Some i -> String.sub heldjson 0 i ^ String.sub heldjson (i + n) (m - i - n)
503
+ | None -> heldjson in
504
+ if leaks heldrest <> [] then
505
+ failwith ("options_map carries a credential beyond the option the caller set: " ^ heldjson);
493
506
  let leaked = List.filter (fun (_, text) -> leaks text <> []) !sinks in
494
507
  Printf.printf "clean: swept %d surface(s), %d leak(s)\\n%!" (List.length !sinks) (List.length leaked);
495
508
  if leaked <> [] then
@@ -553,7 +566,7 @@ let () =
553
566
  let clean_ctx () : value * ctx =
554
567
  let cfg = make_clean_config (jo [("keys", Str "key,secret,token")]) in
555
568
  let base = make_context_impl (default_ctxspec ()) None in
556
- (cfg, { base with c_options = jo [("__derived__", jo [("clean", cfg)])] })
569
+ (cfg, { base with c_cleancfg = cfg })
557
570
 
558
571
  let () =
559
572
  test "clean.a_registered_value_used_as_a_property_name" (fun () ->
@@ -601,9 +614,10 @@ let () =
601
614
  let base = make_context_impl (default_ctxspec ()) None in
602
615
  let config = jo [("options", jo [("clean", jo [
603
616
  ("keys", Str "zzsens"); ("values", Str "CONFIG-SEEDED-1")])])] in
604
- let opts = make_options_util { base with c_config = config;
605
- c_options = jo [("clean", jo [("values", Str "CALLER-SEEDED-2")])] } in
606
- let ctx = { base with c_options = opts } in
617
+ let cctx = { base with c_config = config;
618
+ c_options = jo [("clean", jo [("values", Str "CALLER-SEEDED-2")])] } in
619
+ let opts = make_options_util cctx in
620
+ let ctx = { cctx with c_options = opts } in
607
621
  check_vstr "both seeded values are masked"
608
622
  (clean_util ctx (Str "a CONFIG-SEEDED-1 b CALLER-SEEDED-2")) ("a " ^ mask ^ " b " ^ mask);
609
623
  let out = clean_util ctx (jo [("my_zzsens", Str "x"); ("other", Str "y")]) in
@@ -745,12 +745,12 @@ SKIP: {
745
745
  # is not changed by it.
746
746
  my $util = $hooked->get_utility();
747
747
  my $cfgclean = { 'keys' => 'zzsens', 'values' => $CANARY{config} };
748
- my $built = $util->{make_options}->($util->{make_context}->({
748
+ my $cfgctx = $util->{make_context}->({
749
749
  'utility' => $util,
750
750
  'config' => { 'options' => { 'clean' => $cfgclean } },
751
751
  'options' => { 'clean' => { 'values' => $CANARY{value} } },
752
- }, undef));
753
- my $cfgctx = $util->{make_context}->({ 'options' => $built }, undef);
752
+ }, undef);
753
+ $cfgctx->{options} = $util->{make_options}->($cfgctx);
754
754
  my $seeded = $util->{clean}->($cfgctx, "config $CANARY{config} caller $CANARY{value}");
755
755
  push @sinks, { 'name' => 'config-clean', 'text' => "$seeded" };
756
756
  is($seeded, "config $MASK caller $MASK", "the config's clean values are registered");
@@ -794,6 +794,15 @@ SKIP: {
794
794
  my $falias = $fclean->($featured->get_root_ctx(), 'alias PLAINALIAS-m2n4b6v8');
795
795
  my $frule = $fclean->($featured->get_root_ctx(), 'rule PLAINRULE-k7j5h3g1');
796
796
 
797
+ # The clean registry holds every credential in plain form, and is no option.
798
+ my $held = construct({ 'apikey' => $CANARY{apikey} })->options_map();
799
+ my $heldjson = $JSON->encode($held);
800
+ my $heldquoted = $JSON->encode([$CANARY{apikey}]) =~ s/^\\[|\\]$//gr;
801
+ is($held->{apikey}, $CANARY{apikey}, 'options_map keeps the apikey the caller set');
802
+ is_deeply([ leaks($heldjson =~ s/\\Q$heldquoted\\E//r) ], [],
803
+ 'options_map carries no credential beyond the option the caller set')
804
+ or diag($heldjson);
805
+
797
806
  my @leaked = grep { @{ $_->{found} } }
798
807
  map { { 'name' => $_->{name}, 'found' => [ leaks($_->{text}) ] } } @sinks;
799
808