@pikku/inspector 0.12.75 → 0.12.82

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 (223) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-middleware.js +66 -42
  8. package/dist/add/add-wire-addon.js +7 -4
  9. package/dist/add/add-wire-remote-addon.js +1 -0
  10. package/dist/error-codes.d.ts +1 -0
  11. package/dist/error-codes.js +1 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +3 -1
  14. package/dist/inspector.js +5 -0
  15. package/dist/surface/collect-surface.d.ts +58 -0
  16. package/dist/surface/collect-surface.js +613 -0
  17. package/dist/types.d.ts +36 -12
  18. package/dist/utils/filter-inspector-state.js +14 -0
  19. package/dist/utils/load-addon-functions-meta.js +24 -11
  20. package/dist/utils/post-process.js +15 -0
  21. package/dist/utils/read-module-specifiers.d.ts +8 -0
  22. package/dist/utils/read-module-specifiers.js +23 -0
  23. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  24. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  25. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  26. package/dist/utils/resolve-deploy-target.js +15 -7
  27. package/dist/utils/serialize-inspector-state.d.ts +6 -0
  28. package/dist/utils/serialize-inspector-state.js +10 -0
  29. package/dist/visit.js +4 -0
  30. package/package.json +16 -6
  31. package/run-tests.sh +21 -6
  32. package/src/add/add-addon-bans.ts +0 -85
  33. package/src/add/add-agent-scorer.test.ts +0 -197
  34. package/src/add/add-agent-scorer.ts +0 -83
  35. package/src/add/add-agent.test.ts +0 -87
  36. package/src/add/add-agent.ts +0 -638
  37. package/src/add/add-approval-description.ts +0 -76
  38. package/src/add/add-auth.test.ts +0 -791
  39. package/src/add/add-auth.ts +0 -424
  40. package/src/add/add-channel.ts +0 -778
  41. package/src/add/add-cli-renderers.test.ts +0 -74
  42. package/src/add/add-cli.ts +0 -1006
  43. package/src/add/add-credential.ts +0 -186
  44. package/src/add/add-feature.test.ts +0 -306
  45. package/src/add/add-feature.ts +0 -253
  46. package/src/add/add-file-extends-core-type.ts +0 -66
  47. package/src/add/add-file-with-config.ts +0 -45
  48. package/src/add/add-file-with-factory.test.ts +0 -134
  49. package/src/add/add-file-with-factory.ts +0 -288
  50. package/src/add/add-functions.test.ts +0 -743
  51. package/src/add/add-functions.ts +0 -1548
  52. package/src/add/add-gateway.ts +0 -143
  53. package/src/add/add-http-route-ref.test.ts +0 -149
  54. package/src/add/add-http-route.ts +0 -530
  55. package/src/add/add-http-routes.ts +0 -471
  56. package/src/add/add-keyed-wiring.ts +0 -180
  57. package/src/add/add-mcp-prompt.ts +0 -157
  58. package/src/add/add-mcp-resource.ts +0 -175
  59. package/src/add/add-middleware.test.ts +0 -196
  60. package/src/add/add-middleware.ts +0 -879
  61. package/src/add/add-permission-auth.test.ts +0 -59
  62. package/src/add/add-permission.ts +0 -311
  63. package/src/add/add-personas.test.ts +0 -406
  64. package/src/add/add-personas.ts +0 -287
  65. package/src/add/add-queue-worker.ts +0 -117
  66. package/src/add/add-rpc-invocations.test.ts +0 -287
  67. package/src/add/add-rpc-invocations.ts +0 -221
  68. package/src/add/add-scenario-step.test.ts +0 -509
  69. package/src/add/add-schedule.ts +0 -120
  70. package/src/add/add-scope.test.ts +0 -419
  71. package/src/add/add-scope.ts +0 -221
  72. package/src/add/add-secret.ts +0 -10
  73. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  74. package/src/add/add-system-role.test.ts +0 -297
  75. package/src/add/add-system-role.ts +0 -162
  76. package/src/add/add-trigger.ts +0 -165
  77. package/src/add/add-variable.ts +0 -10
  78. package/src/add/add-wire-addon.test.ts +0 -185
  79. package/src/add/add-wire-addon.ts +0 -146
  80. package/src/add/add-wire-remote-addon.ts +0 -80
  81. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  82. package/src/add/add-workflow-fanout.test.ts +0 -166
  83. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  84. package/src/add/add-workflow-graph-input.test.ts +0 -94
  85. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  86. package/src/add/add-workflow-graph.ts +0 -644
  87. package/src/add/add-workflow-on-error.test.ts +0 -118
  88. package/src/add/add-workflow-return-switch.test.ts +0 -121
  89. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  90. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  91. package/src/add/add-workflow.test.ts +0 -155
  92. package/src/add/add-workflow.ts +0 -482
  93. package/src/add/addon-bans.test.ts +0 -121
  94. package/src/add/addon-contracts.test.ts +0 -221
  95. package/src/add/allow-escape-hatches.test.ts +0 -144
  96. package/src/add/audit-meta.test.ts +0 -75
  97. package/src/add/classified-sink-check.test.ts +0 -347
  98. package/src/add/config-value-metadata.test.ts +0 -263
  99. package/src/add/dynamic-import-check.test.ts +0 -119
  100. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  101. package/src/add/function-body-span.test.ts +0 -96
  102. package/src/add/inline-wiring-function.test.ts +0 -104
  103. package/src/add/pii-check.test.ts +0 -258
  104. package/src/add/rpc-type-cast.test.ts +0 -123
  105. package/src/add/scenario-instrumentation.test.ts +0 -89
  106. package/src/add/scenario-instrumentation.ts +0 -42
  107. package/src/add/scenario-marker.test.ts +0 -89
  108. package/src/add/scenario-not-extractable.test.ts +0 -159
  109. package/src/add/scenario-services.test.ts +0 -103
  110. package/src/add/scenario-skip.test.ts +0 -83
  111. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  112. package/src/add/wire-name-literal.test.ts +0 -117
  113. package/src/error-codes-emitted.test.ts +0 -76
  114. package/src/error-codes.ts +0 -145
  115. package/src/index.ts +0 -66
  116. package/src/inspector.ts +0 -575
  117. package/src/schema-generator.ts +0 -1
  118. package/src/source-file-cache.ts +0 -73
  119. package/src/tsconfig-paths.test.ts +0 -90
  120. package/src/types-map.ts +0 -141
  121. package/src/types.ts +0 -775
  122. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  123. package/src/utils/annotate-http-route-auth.ts +0 -53
  124. package/src/utils/check-classified-sinks.ts +0 -215
  125. package/src/utils/check-pii-output.ts +0 -120
  126. package/src/utils/compute-diagnostics.test.ts +0 -106
  127. package/src/utils/compute-required-schemas.ts +0 -48
  128. package/src/utils/contract-hashes.test.ts +0 -553
  129. package/src/utils/contract-hashes.ts +0 -387
  130. package/src/utils/custom-types-generator.test.ts +0 -124
  131. package/src/utils/custom-types-generator.ts +0 -150
  132. package/src/utils/detect-schema-vendor.test.ts +0 -123
  133. package/src/utils/detect-schema-vendor.ts +0 -120
  134. package/src/utils/does-type-extend-core-type.ts +0 -53
  135. package/src/utils/ensure-function-metadata.ts +0 -385
  136. package/src/utils/extract-function-name.ts +0 -612
  137. package/src/utils/extract-function-node.ts +0 -70
  138. package/src/utils/extract-node-value.test.ts +0 -117
  139. package/src/utils/extract-node-value.ts +0 -172
  140. package/src/utils/extract-secret-usage.test.ts +0 -81
  141. package/src/utils/extract-secret-usage.ts +0 -73
  142. package/src/utils/extract-services.ts +0 -70
  143. package/src/utils/extract-surface-usage.test.ts +0 -147
  144. package/src/utils/extract-surface-usage.ts +0 -121
  145. package/src/utils/filter-inspector-state.test.ts +0 -2232
  146. package/src/utils/filter-inspector-state.ts +0 -1298
  147. package/src/utils/filter-utils.test.ts +0 -843
  148. package/src/utils/filter-utils.ts +0 -161
  149. package/src/utils/find-root-dir.ts +0 -68
  150. package/src/utils/find-zod-transform.test.ts +0 -70
  151. package/src/utils/find-zod-transform.ts +0 -103
  152. package/src/utils/get-exported-variable-name.ts +0 -48
  153. package/src/utils/get-files-and-methods.ts +0 -157
  154. package/src/utils/get-property-value.test.ts +0 -141
  155. package/src/utils/get-property-value.ts +0 -331
  156. package/src/utils/hash.ts +0 -26
  157. package/src/utils/literal-properties.ts +0 -97
  158. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  159. package/src/utils/load-addon-functions-meta.ts +0 -508
  160. package/src/utils/load-addon-scopes.test.ts +0 -138
  161. package/src/utils/middleware.test.ts +0 -204
  162. package/src/utils/middleware.ts +0 -303
  163. package/src/utils/nested-project-filter.test.ts +0 -53
  164. package/src/utils/nested-project-filter.ts +0 -28
  165. package/src/utils/permissions-shorthand.test.ts +0 -79
  166. package/src/utils/permissions.test.ts +0 -125
  167. package/src/utils/permissions.ts +0 -129
  168. package/src/utils/post-process.test.ts +0 -1094
  169. package/src/utils/post-process.ts +0 -1604
  170. package/src/utils/resolve-addon-package.ts +0 -106
  171. package/src/utils/resolve-core-type.test.ts +0 -142
  172. package/src/utils/resolve-core-type.ts +0 -35
  173. package/src/utils/resolve-deploy-target.test.ts +0 -135
  174. package/src/utils/resolve-deploy-target.ts +0 -65
  175. package/src/utils/resolve-function-meta.ts +0 -25
  176. package/src/utils/resolve-function-types.ts +0 -42
  177. package/src/utils/resolve-identifier.ts +0 -46
  178. package/src/utils/resolve-ref-contract.ts +0 -71
  179. package/src/utils/resolve-versions.test.ts +0 -499
  180. package/src/utils/resolve-versions.ts +0 -228
  181. package/src/utils/schema-cache.test.ts +0 -124
  182. package/src/utils/schema-generator.test.ts +0 -272
  183. package/src/utils/schema-generator.ts +0 -780
  184. package/src/utils/secret-alias-services.test.ts +0 -146
  185. package/src/utils/secret-alias-services.ts +0 -58
  186. package/src/utils/serialize-inspector-state.ts +0 -742
  187. package/src/utils/serialize-mcp-json.ts +0 -150
  188. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  189. package/src/utils/serialize-openapi-json.ts +0 -277
  190. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  191. package/src/utils/single-declaration.ts +0 -57
  192. package/src/utils/type-utils.ts +0 -145
  193. package/src/utils/validate-auth-sessionless.ts +0 -30
  194. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  195. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  196. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  197. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  198. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  199. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  200. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  201. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  202. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  203. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  204. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  205. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  206. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  207. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  208. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  209. package/src/utils/workflow/dsl/index.ts +0 -11
  210. package/src/utils/workflow/dsl/patterns.ts +0 -440
  211. package/src/utils/workflow/dsl/validation.ts +0 -203
  212. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  213. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  214. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  215. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  216. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  217. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  218. package/src/utils/workflow/graph/index.ts +0 -28
  219. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  220. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  221. package/src/visit.ts +0 -181
  222. package/tsconfig.json +0 -19
  223. package/tsconfig.tsbuildinfo +0 -1
@@ -1,230 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { describe, test, beforeEach } from 'node:test'
3
- import { ErrorCode } from '../error-codes.js'
4
- import { validateExposedFunctionsGated } from './validate-exposed-functions-gated.js'
5
-
6
- const ADDON_PACKAGE = '@addon/console'
7
-
8
- let diagnostics: Array<{ severity: string; code: string; message: string }>
9
-
10
- const logger = {
11
- debug: () => {},
12
- info: () => {},
13
- warn: () => {},
14
- error: () => {},
15
- critical: () => {},
16
- diagnostic: (d: any) => diagnostics.push(d),
17
- hasCriticalErrors: () => false,
18
- } as any
19
-
20
- /**
21
- * The two pieces of state the check reads: every function's meta, and every
22
- * wireAddon declaration the inspector found.
23
- */
24
- const stateWith = (
25
- meta: Record<string, unknown>,
26
- addons: Record<string, unknown> = {}
27
- ) =>
28
- ({
29
- functions: { meta },
30
- rpc: { wireAddonDeclarations: new Map(Object.entries(addons)) },
31
- }) as any
32
-
33
- /** An exposed sessionless function with no gate of any kind — the bad shape. */
34
- const ungatedFunction = (overrides: Record<string, unknown> = {}) => ({
35
- pikkuFuncId: 'credentialGet',
36
- expose: true,
37
- sessionless: true,
38
- ...overrides,
39
- })
40
-
41
- const run = (state: any) => {
42
- validateExposedFunctionsGated(logger, state)
43
- return diagnostics
44
- }
45
-
46
- const warning = () => {
47
- const found = diagnostics.find(
48
- (d) => d.code === ErrorCode.EXPOSED_FUNCTION_HAS_NO_GATE
49
- )
50
- return found
51
- }
52
-
53
- beforeEach(() => {
54
- diagnostics = []
55
- })
56
-
57
- describe('validateExposedFunctionsGated', () => {
58
- test('warns about an exposed sessionless function with no gate', () => {
59
- run(stateWith({ credentialGet: ungatedFunction() }))
60
-
61
- const found = warning()
62
- assert.ok(found, 'expected a diagnostic')
63
- assert.equal(found.severity, 'warn')
64
- assert.match(found.message, /credentialGet/)
65
- })
66
-
67
- test('names every ungated function, not just a count', () => {
68
- run(
69
- stateWith({
70
- credentialGet: ungatedFunction(),
71
- installAddon: ungatedFunction({ pikkuFuncId: 'installAddon' }),
72
- })
73
- )
74
-
75
- assert.match(warning()!.message, /credentialGet/)
76
- assert.match(warning()!.message, /installAddon/)
77
- })
78
-
79
- test('stays silent for a function that is not exposed', () => {
80
- run(stateWith({ credentialGet: ungatedFunction({ expose: undefined }) }))
81
-
82
- assert.equal(warning(), undefined)
83
- })
84
-
85
- test('stays silent for a pikkuFunc, which always requires a session', () => {
86
- run(stateWith({ credentialGet: ungatedFunction({ sessionless: false }) }))
87
-
88
- assert.equal(warning(), undefined)
89
- })
90
-
91
- test('stays silent for a scenario step, which rpcExposed refuses anyway', () => {
92
- run(stateWith({ step: ungatedFunction({ scenarioStep: true }) }))
93
-
94
- assert.equal(warning(), undefined)
95
- })
96
-
97
- describe('a function that gates itself', () => {
98
- test('is silent when it declares auth', () => {
99
- run(stateWith({ credentialGet: ungatedFunction({ auth: true }) }))
100
-
101
- assert.equal(warning(), undefined)
102
- })
103
-
104
- test('is silent when it declares it authenticates in its own body', () => {
105
- // A webhook receiver verifying a signature has a real gate this check
106
- // cannot see. Without a way to say so the warning would fire forever on
107
- // functions that are fine, and a warning that is usually wrong is one
108
- // nobody reads.
109
- run(
110
- stateWith({
111
- stripeWebhook: ungatedFunction({ permissionsInBody: true }),
112
- })
113
- )
114
-
115
- assert.equal(warning(), undefined)
116
- })
117
-
118
- test('still warns when the declaration is explicitly false', () => {
119
- run(
120
- stateWith({
121
- credentialGet: ungatedFunction({ permissionsInBody: false }),
122
- })
123
- )
124
-
125
- assert.ok(warning())
126
- })
127
-
128
- test('is silent when it declares scopes', () => {
129
- run(stateWith({ credentialGet: ungatedFunction({ scopes: ['admin'] }) }))
130
-
131
- assert.equal(warning(), undefined)
132
- })
133
-
134
- test('is silent when it declares permissions', () => {
135
- run(
136
- stateWith({
137
- credentialGet: ungatedFunction({
138
- permissions: [{ type: 'wire', name: 'isAdmin' }],
139
- }),
140
- })
141
- )
142
-
143
- assert.equal(warning(), undefined)
144
- })
145
-
146
- test('still warns when scopes is present but empty', () => {
147
- run(stateWith({ credentialGet: ungatedFunction({ scopes: [] }) }))
148
-
149
- assert.ok(warning(), 'an empty scopes array gates nothing')
150
- })
151
- })
152
-
153
- describe('a function gated by its addon', () => {
154
- test('is silent when the addon declares scopes', () => {
155
- run(
156
- stateWith(
157
- {
158
- credentialGet: ungatedFunction({ packageName: ADDON_PACKAGE }),
159
- },
160
- { console: { package: ADDON_PACKAGE, scopes: ['admin'] } }
161
- )
162
- )
163
-
164
- assert.equal(warning(), undefined)
165
- })
166
-
167
- test('is silent when the addon declares auth', () => {
168
- run(
169
- stateWith(
170
- {
171
- credentialGet: ungatedFunction({ packageName: ADDON_PACKAGE }),
172
- },
173
- { console: { package: ADDON_PACKAGE, auth: true } }
174
- )
175
- )
176
-
177
- assert.equal(warning(), undefined)
178
- })
179
-
180
- test('warns when the addon is wired without any gate', () => {
181
- run(
182
- stateWith(
183
- {
184
- credentialGet: ungatedFunction({ packageName: ADDON_PACKAGE }),
185
- },
186
- { console: { package: ADDON_PACKAGE } }
187
- )
188
- )
189
-
190
- assert.ok(warning(), 'wireAddon with no scopes or auth gates nothing')
191
- })
192
-
193
- test('warns when the gated addon is a different package', () => {
194
- run(
195
- stateWith(
196
- {
197
- credentialGet: ungatedFunction({ packageName: ADDON_PACKAGE }),
198
- },
199
- { other: { package: '@addon/other', scopes: ['admin'] } }
200
- )
201
- )
202
-
203
- assert.ok(warning())
204
- })
205
-
206
- test('is silent when any one instance of the package is gated', () => {
207
- // resolveAddonScopes unions across every instance of the package, so a
208
- // second ungated namespace does not open the first.
209
- run(
210
- stateWith(
211
- {
212
- credentialGet: ungatedFunction({ packageName: ADDON_PACKAGE }),
213
- },
214
- {
215
- console: { package: ADDON_PACKAGE, scopes: ['admin'] },
216
- consoleReadonly: { package: ADDON_PACKAGE },
217
- }
218
- )
219
- )
220
-
221
- assert.equal(warning(), undefined)
222
- })
223
- })
224
-
225
- test('stays silent when nothing is exposed', () => {
226
- run(stateWith({}))
227
-
228
- assert.equal(diagnostics.length, 0)
229
- })
230
- })
@@ -1,103 +0,0 @@
1
- import { ErrorCode } from '../error-codes.js'
2
- import type { InspectorLogger, InspectorState } from '../types.js'
3
-
4
- /**
5
- * A function reachable through the generated `POST /rpc/:rpcName` dispatcher
6
- * that nothing will stop.
7
- *
8
- * `rpc.exposed` refuses anything without `expose: true`, so the population is
9
- * small and deliberate — someone typed it. What makes one dangerous is the
10
- * combination: exposed, sessionless, and carrying no gate of its own or from
11
- * the addon it belongs to. The dispatcher cannot help, because it does not know
12
- * what it is dispatching to.
13
- *
14
- * knowledge: decisions/security/console-addon-privileged-functions-gate-themselves.md
15
- */
16
- export function validateExposedFunctionsGated(
17
- logger: InspectorLogger,
18
- state: InspectorState
19
- ): void {
20
- const ungated: string[] = []
21
-
22
- for (const [funcName, meta] of Object.entries(state.functions.meta)) {
23
- if (!meta.expose) continue
24
-
25
- // A pikkuFunc always requires a session, on every path.
26
- if (meta.sessionless === false) continue
27
-
28
- // Scenario steps are refused by rpcExposed regardless of `expose`.
29
- if (meta.scenarioStep) continue
30
-
31
- // The author declared that the body authorizes its own callers — a gate
32
- // this check has no way to see. Taking the claim at face value is the
33
- // point: without it the warning fires forever on functions that are fine,
34
- // and a warning that is usually wrong stops being read.
35
- if (meta.permissionsInBody === true) continue
36
-
37
- // The function gates itself.
38
- if (meta.auth === true) continue
39
- if (meta.scopes && meta.scopes.length > 0) continue
40
- if (meta.permissions && meta.permissions.length > 0) continue
41
-
42
- if (isGatedByItsAddon(state, meta.packageName)) continue
43
-
44
- ungated.push(funcName)
45
- }
46
-
47
- if (ungated.length === 0) return
48
-
49
- const shown = ungated.slice(0, 10)
50
- const rest = ungated.length - shown.length
51
-
52
- const one = ungated.length === 1
53
-
54
- // Every function here is sessionless — that is the population, not the
55
- // finding, so the message names it as given rather than reporting it as a
56
- // defect. The remedies are the ones that can actually apply to an anonymous
57
- // caller: `scopes` cannot, because `verifyScopes` fails closed on a session
58
- // that does not exist, and telling someone to add them sends them to a
59
- // MissingScopeError on every public request.
60
- logger.diagnostic({
61
- severity: 'warn',
62
- code: ErrorCode.EXPOSED_FUNCTION_HAS_NO_GATE,
63
- message:
64
- `${ungated.length} exposed sessionless function${one ? '' : 's'} ` +
65
- `carr${one ? 'ies' : 'y'} no permission and no addon gate, so ` +
66
- `${one ? 'it is' : 'they are'} reachable by anyone through ` +
67
- `POST /rpc/:rpcName: ${shown.join(', ')}` +
68
- (rest > 0 ? `, and ${rest} more` : '') +
69
- `. Add permissions to the function, set \`auth: true\` if a session is ` +
70
- `required after all, gate the whole addon with ` +
71
- `wireAddon({ auth: true }), or drop \`expose: true\` if ` +
72
- `${one ? 'it was' : 'they were'} not meant to be callable from outside.`,
73
- })
74
- }
75
-
76
- /**
77
- * Whether every function in this package is already gated by its `wireAddon`.
78
- * Those gates are applied by `runPikkuFunc` on every wiring path, so a function
79
- * with no gate of its own is still covered by them.
80
- *
81
- * An addon whose `scopes`/`auth` were not statically knowable reads as
82
- * unknown, and unknown is treated as gated — a false negative here costs a
83
- * missing warning, a false positive costs trust in every warning.
84
- *
85
- * knowledge: decisions/security/addon-scopes-are-resolved-where-the-function-runs.md
86
- */
87
- function isGatedByItsAddon(
88
- state: InspectorState,
89
- packageName: string | undefined
90
- ): boolean {
91
- if (!packageName) return false
92
-
93
- const declarations = state.rpc?.wireAddonDeclarations
94
- if (!declarations) return false
95
-
96
- for (const declaration of declarations.values()) {
97
- if (declaration.package !== packageName) continue
98
- if (declaration.auth === true) return true
99
- if (declaration.scopes && declaration.scopes.length > 0) return true
100
- }
101
-
102
- return false
103
- }
@@ -1,108 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { describe, test, beforeEach } from 'node:test'
3
- import { ErrorCode } from '../error-codes.js'
4
- import { validateTagsResolveToMiddleware } from './validate-tags-resolve-to-middleware.js'
5
-
6
- let diagnostics: Array<{ severity: string; code: string; message: string }>
7
-
8
- const logger = {
9
- debug: () => {},
10
- info: () => {},
11
- warn: () => {},
12
- error: () => {},
13
- critical: () => {},
14
- diagnostic: (d: any) => diagnostics.push(d),
15
- hasCriticalErrors: () => false,
16
- } as any
17
-
18
- /**
19
- * The three pieces of state the check reads: the addon declarations that carry
20
- * tags, and the two registries a tag can resolve against.
21
- */
22
- const stateWith = (
23
- addons: Record<string, { tags?: string[] }>,
24
- httpTags: string[] = [],
25
- channelTags: string[] = []
26
- ) =>
27
- ({
28
- rpc: { wireAddonDeclarations: new Map(Object.entries(addons)) },
29
- middleware: { tagMiddleware: new Map(httpTags.map((t) => [t, []])) },
30
- channelMiddleware: {
31
- tagMiddleware: new Map(channelTags.map((t) => [t, []])),
32
- },
33
- }) as any
34
-
35
- const run = (state: any) => {
36
- validateTagsResolveToMiddleware(logger, state)
37
- return diagnostics.filter(
38
- (d) => d.code === ErrorCode.TAG_RESOLVES_TO_NO_MIDDLEWARE
39
- )
40
- }
41
-
42
- beforeEach(() => {
43
- diagnostics = []
44
- })
45
-
46
- describe('validateTagsResolveToMiddleware', () => {
47
- test('warns about an addon tag no middleware is registered for', () => {
48
- const found = run(stateWith({ console: { tags: ['admin'] } }))
49
- assert.equal(found.length, 1)
50
- assert.match(found[0]!.message, /console/)
51
- assert.match(found[0]!.message, /admin/)
52
- })
53
-
54
- test('warns rather than fails the build', () => {
55
- // The tag may be registered by host code the inspector never sees, so this
56
- // has to stay advisory — a false positive must not break codegen.
57
- const found = run(stateWith({ console: { tags: ['admin'] } }))
58
- assert.equal(found[0]!.severity, 'warn')
59
- })
60
-
61
- test('stays quiet when http middleware is registered for the tag', () => {
62
- assert.deepEqual(
63
- run(stateWith({ console: { tags: ['admin'] } }, ['admin'])),
64
- []
65
- )
66
- })
67
-
68
- test('stays quiet when only channel middleware is registered for the tag', () => {
69
- assert.deepEqual(
70
- run(stateWith({ console: { tags: ['admin'] } }, [], ['admin'])),
71
- []
72
- )
73
- })
74
-
75
- test('reports each unresolved tag on an addon separately', () => {
76
- const found = run(
77
- stateWith({ console: { tags: ['admin', 'audited'] } }, ['admin'])
78
- )
79
- assert.equal(found.length, 1)
80
- assert.match(found[0]!.message, /audited/)
81
- })
82
-
83
- test('reports the same tag once per addon that declares it', () => {
84
- const found = run(
85
- stateWith({ console: { tags: ['admin'] }, billing: { tags: ['admin'] } })
86
- )
87
- assert.equal(found.length, 2)
88
- })
89
-
90
- test('stays quiet for an addon with no tags', () => {
91
- assert.deepEqual(run(stateWith({ console: {} })), [])
92
- })
93
-
94
- test('stays quiet when there are no addons at all', () => {
95
- assert.deepEqual(run(stateWith({})), [])
96
- })
97
-
98
- test('tolerates rpc state being absent', () => {
99
- // Inspection of a package with no RPC surface never populates it.
100
- assert.deepEqual(
101
- run({
102
- middleware: { tagMiddleware: new Map() },
103
- channelMiddleware: { tagMiddleware: new Map() },
104
- } as any),
105
- []
106
- )
107
- })
108
- })
@@ -1,48 +0,0 @@
1
- import { ErrorCode } from '../error-codes.js'
2
- import type { InspectorLogger, InspectorState } from '../types.js'
3
-
4
- /**
5
- * An addon tag naming middleware nobody registered.
6
- *
7
- * `wireAddon({ tags: ['admin'] })` reads like a gate and is applied like one —
8
- * right up until no `addTagMiddleware('admin', …)` exists, at which point it
9
- * resolves to an empty list and every request sails through. Nothing at runtime
10
- * distinguishes "this tag runs three middlewares" from "this tag does nothing".
11
- *
12
- * Only **addon** tags are reported. A tag on a function is just as likely to be
13
- * organizational — grouping, documentation, OpenAPI — and warning about every
14
- * one of those would bury the case that matters. A tag on `wireAddon` is
15
- * different: it is the documented way to apply a gate across a whole addon, so
16
- * an inert one is never decorative. An exposed function relying on a tag it
17
- * has no other gate behind is already reported by
18
- * `validateExposedFunctionsGated`, which does not count tags as a gate.
19
- *
20
- * knowledge: decisions/security/addon-auth-and-tags-only-tighten.md
21
- */
22
- export function validateTagsResolveToMiddleware(
23
- logger: InspectorLogger,
24
- state: InspectorState
25
- ): void {
26
- const registered = new Set<string>([
27
- ...state.middleware.tagMiddleware.keys(),
28
- ...state.channelMiddleware.tagMiddleware.keys(),
29
- ])
30
-
31
- for (const [namespace, declaration] of state.rpc?.wireAddonDeclarations ??
32
- []) {
33
- for (const tag of declaration.tags ?? []) {
34
- if (registered.has(tag)) continue
35
-
36
- logger.diagnostic({
37
- severity: 'warn',
38
- code: ErrorCode.TAG_RESOLVES_TO_NO_MIDDLEWARE,
39
- message:
40
- `wireAddon('${namespace}') declares tag '${tag}', but no ` +
41
- `addTagMiddleware('${tag}', …) registers anything for it. The tag ` +
42
- `resolves to an empty middleware list, so it applies no gate to the ` +
43
- `addon at all. Register middleware for it, or drop the tag if it is ` +
44
- `only meant to group and document.`,
45
- })
46
- }
47
- }
48
- }
@@ -1,178 +0,0 @@
1
- import { strict as assert } from 'assert'
2
- import { describe, test } from 'node:test'
3
- import type { WorkflowStepMeta } from '@pikku/core/workflow'
4
- import { deriveWorkflowPlan } from './derive-workflow-plan.js'
5
-
6
- const rpc = (stepName: string, rpcName = 'rpc.fn'): WorkflowStepMeta =>
7
- ({ type: 'rpc', stepName, rpcName }) as WorkflowStepMeta
8
- const sleep = (stepName: string): WorkflowStepMeta =>
9
- ({ type: 'sleep', stepName }) as WorkflowStepMeta
10
- const inline = (stepName: string): WorkflowStepMeta =>
11
- ({ type: 'inline', stepName }) as WorkflowStepMeta
12
-
13
- describe('deriveWorkflowPlan', () => {
14
- test('linear workflow is deterministic with every step listed in order', () => {
15
- const plan = deriveWorkflowPlan([rpc('a'), sleep('b'), inline('c')])
16
- assert.equal(plan.deterministic, true)
17
- assert.deepEqual(plan.plannedSteps, [
18
- { stepName: 'a' },
19
- { stepName: 'b' },
20
- { stepName: 'c' },
21
- ])
22
- })
23
-
24
- test('parallel group lists each child step', () => {
25
- const plan = deriveWorkflowPlan([
26
- rpc('a'),
27
- {
28
- type: 'parallel',
29
- children: [rpc('p1'), rpc('p2')],
30
- } as WorkflowStepMeta,
31
- ])
32
- assert.equal(plan.deterministic, true)
33
- assert.deepEqual(plan.plannedSteps, [
34
- { stepName: 'a' },
35
- { stepName: 'p1' },
36
- { stepName: 'p2' },
37
- ])
38
- })
39
-
40
- test('branch is loopless: plannedSteps cover every arm but not deterministic', () => {
41
- const plan = deriveWorkflowPlan([
42
- rpc('start'),
43
- {
44
- type: 'branch',
45
- branches: [{ condition: 'x', steps: [rpc('left')] }],
46
- elseSteps: [rpc('right')],
47
- } as WorkflowStepMeta,
48
- rpc('end'),
49
- ])
50
- assert.equal(plan.deterministic, false, 'a branch picks a path at runtime')
51
- assert.deepEqual(plan.plannedSteps, [
52
- { stepName: 'start' },
53
- { stepName: 'left' },
54
- { stepName: 'right' },
55
- { stepName: 'end' },
56
- ])
57
- })
58
-
59
- test('switch is loopless: cases + default contribute steps, not deterministic', () => {
60
- const plan = deriveWorkflowPlan([
61
- {
62
- type: 'switch',
63
- expression: 'kind',
64
- cases: [{ steps: [rpc('caseA')] }, { steps: [rpc('caseB')] }],
65
- defaultSteps: [rpc('fallback')],
66
- } as WorkflowStepMeta,
67
- ])
68
- assert.equal(plan.deterministic, false)
69
- assert.deepEqual(plan.plannedSteps, [
70
- { stepName: 'caseA' },
71
- { stepName: 'caseB' },
72
- { stepName: 'fallback' },
73
- ])
74
- })
75
-
76
- test('fanout (loop) yields no plannedSteps and is not deterministic', () => {
77
- const plan = deriveWorkflowPlan([
78
- rpc('before'),
79
- {
80
- type: 'fanout',
81
- stepName: 'each',
82
- child: rpc('child'),
83
- mode: 'parallel',
84
- } as WorkflowStepMeta,
85
- ])
86
- assert.equal(plan.deterministic, false)
87
- assert.equal(
88
- plan.plannedSteps,
89
- undefined,
90
- 'loop count is runtime-dependent'
91
- )
92
- })
93
-
94
- test('a fanout nested inside a branch still suppresses the plan', () => {
95
- const plan = deriveWorkflowPlan([
96
- {
97
- type: 'branch',
98
- branches: [
99
- {
100
- condition: 'x',
101
- steps: [
102
- {
103
- type: 'fanout',
104
- stepName: 'each',
105
- child: rpc('child'),
106
- mode: 'serial',
107
- } as WorkflowStepMeta,
108
- ],
109
- },
110
- ],
111
- } as WorkflowStepMeta,
112
- ])
113
- assert.equal(plan.deterministic, false)
114
- assert.equal(plan.plannedSteps, undefined)
115
- })
116
-
117
- test('non-named steps (set/return/cancel) are skipped', () => {
118
- const plan = deriveWorkflowPlan([
119
- { type: 'set' } as WorkflowStepMeta,
120
- rpc('a'),
121
- { type: 'return' } as WorkflowStepMeta,
122
- ])
123
- assert.equal(plan.deterministic, true)
124
- assert.deepEqual(plan.plannedSteps, [{ stepName: 'a' }])
125
- })
126
-
127
- test('suspend steps appear in the plan with __workflow_suspend: key and sentence-case displayName', () => {
128
- const plan = deriveWorkflowPlan([
129
- rpc('build'),
130
- { type: 'suspend', reason: 'building' } as WorkflowStepMeta,
131
- rpc('publish'),
132
- { type: 'suspend', reason: 'awaiting_approval' } as WorkflowStepMeta,
133
- { type: 'suspend', reason: 'building-image' } as WorkflowStepMeta,
134
- ])
135
- assert.equal(plan.deterministic, true)
136
- assert.deepEqual(plan.plannedSteps, [
137
- { stepName: 'build' },
138
- { stepName: '__workflow_suspend:building', displayName: 'Building' },
139
- { stepName: 'publish' },
140
- {
141
- stepName: '__workflow_suspend:awaiting_approval',
142
- displayName: 'Awaiting approval',
143
- },
144
- {
145
- stepName: '__workflow_suspend:building-image',
146
- displayName: 'Building image',
147
- },
148
- ])
149
- })
150
-
151
- test('approval steps appear in the plan with __workflow_approval: key and sentence-case displayName', () => {
152
- const plan = deriveWorkflowPlan([
153
- rpc('build'),
154
- { type: 'approval', reason: 'awaiting_approval' } as WorkflowStepMeta,
155
- rpc('publish'),
156
- ])
157
- assert.equal(plan.deterministic, true)
158
- assert.deepEqual(plan.plannedSteps, [
159
- { stepName: 'build' },
160
- {
161
- stepName: '__workflow_approval:awaiting_approval',
162
- displayName: 'Awaiting approval',
163
- },
164
- { stepName: 'publish' },
165
- ])
166
- })
167
-
168
- test('an approval is namespaced apart from a suspend sharing its reason', () => {
169
- const plan = deriveWorkflowPlan([
170
- { type: 'suspend', reason: 'sign_off' } as WorkflowStepMeta,
171
- { type: 'approval', reason: 'sign_off' } as WorkflowStepMeta,
172
- ])
173
- assert.deepEqual(
174
- plan.plannedSteps.map((s) => s.stepName),
175
- ['__workflow_suspend:sign_off', '__workflow_approval:sign_off']
176
- )
177
- })
178
- })