@pikku/inspector 0.12.50 → 0.12.52
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.
- package/CHANGELOG.md +441 -0
- package/OPTIMIZATION-PLAN.md +9 -3
- package/dist/add/add-auth.d.ts +1 -1
- package/dist/add/add-auth.js +1 -1
- package/dist/add/add-cli.js +7 -0
- package/dist/add/add-credential.js +1 -1
- package/dist/add/add-functions.js +156 -7
- package/dist/add/add-http-route.js +16 -6
- package/dist/add/add-middleware.js +46 -3
- package/dist/add/add-personas.d.ts +13 -0
- package/dist/add/add-personas.js +210 -0
- package/dist/add/add-scope.js +1 -1
- package/dist/add/add-secret.js +1 -1
- package/dist/add/add-system-role.d.ts +2 -0
- package/dist/add/add-system-role.js +102 -0
- package/dist/add/add-variable.js +1 -1
- package/dist/add/add-wire-addon.js +31 -0
- package/dist/error-codes.d.ts +10 -1
- package/dist/error-codes.js +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/inspector.js +33 -1
- package/dist/types.d.ts +46 -2
- package/dist/utils/annotate-http-route-auth.d.ts +22 -0
- package/dist/utils/annotate-http-route-auth.js +48 -0
- package/dist/utils/extract-function-name.js +13 -4
- package/dist/utils/extract-function-node.js +18 -1
- package/dist/utils/extract-secret-usage.d.ts +9 -0
- package/dist/utils/extract-secret-usage.js +61 -0
- package/dist/utils/literal-properties.d.ts +22 -0
- package/dist/utils/literal-properties.js +69 -0
- package/dist/utils/load-addon-functions-meta.js +26 -1
- package/dist/utils/permissions.js +8 -0
- package/dist/utils/post-process.d.ts +68 -3
- package/dist/utils/post-process.js +243 -13
- package/dist/utils/secret-alias-services.d.ts +8 -0
- package/dist/utils/secret-alias-services.js +45 -0
- package/dist/utils/secret-brokers.d.ts +2 -0
- package/dist/utils/secret-brokers.js +9 -0
- package/dist/utils/serialize-inspector-state.d.ts +10 -0
- package/dist/utils/serialize-inspector-state.js +18 -0
- package/dist/utils/serialize-middleware-groups-meta.js +3 -0
- package/dist/utils/validate-exposed-functions-gated.d.ts +14 -0
- package/dist/utils/validate-exposed-functions-gated.js +85 -0
- package/dist/utils/validate-tags-resolve-to-middleware.d.ts +20 -0
- package/dist/utils/validate-tags-resolve-to-middleware.js +41 -0
- package/dist/visit.js +4 -0
- package/package.json +3 -3
- package/src/add/add-auth.test.ts +5 -3
- package/src/add/add-auth.ts +1 -1
- package/src/add/add-cli.ts +8 -0
- package/src/add/add-credential.ts +1 -1
- package/src/add/add-functions.test.ts +263 -1
- package/src/add/add-functions.ts +219 -9
- package/src/add/add-http-route.ts +20 -7
- package/src/add/add-middleware.test.ts +196 -0
- package/src/add/add-middleware.ts +64 -4
- package/src/add/add-personas.test.ts +268 -0
- package/src/add/add-personas.ts +276 -0
- package/src/add/add-scenario-step.test.ts +49 -3
- package/src/add/add-scope.test.ts +30 -30
- package/src/add/add-scope.ts +1 -1
- package/src/add/add-secret.ts +1 -1
- package/src/add/add-subject-scenario-steps.test.ts +161 -0
- package/src/add/add-system-role.test.ts +214 -0
- package/src/add/add-system-role.ts +164 -0
- package/src/add/add-variable.ts +1 -1
- package/src/add/add-wire-addon.test.ts +111 -0
- package/src/add/add-wire-addon.ts +29 -0
- package/src/add/addon-bans.test.ts +4 -4
- package/src/add/config-value-metadata.test.ts +11 -11
- package/src/add/wire-name-literal.test.ts +2 -2
- package/src/error-codes.ts +13 -0
- package/src/index.ts +4 -1
- package/src/inspector.ts +39 -0
- package/src/types.ts +47 -2
- package/src/utils/annotate-http-route-auth.test.ts +163 -0
- package/src/utils/annotate-http-route-auth.ts +52 -0
- package/src/utils/extract-function-name.ts +14 -4
- package/src/utils/extract-function-node.ts +18 -6
- package/src/utils/extract-secret-usage.test.ts +81 -0
- package/src/utils/extract-secret-usage.ts +73 -0
- package/src/utils/literal-properties.ts +97 -0
- package/src/utils/load-addon-functions-meta.ts +32 -2
- package/src/utils/permissions-shorthand.test.ts +79 -0
- package/src/utils/permissions.ts +7 -0
- package/src/utils/post-process.test.ts +133 -0
- package/src/utils/post-process.ts +310 -12
- package/src/utils/secret-alias-services.test.ts +146 -0
- package/src/utils/secret-alias-services.ts +58 -0
- package/src/utils/secret-brokers.test.ts +53 -0
- package/src/utils/secret-brokers.ts +11 -0
- package/src/utils/serialize-inspector-state.ts +28 -0
- package/src/utils/serialize-middleware-groups-meta.ts +3 -0
- package/src/utils/validate-exposed-functions-gated.test.ts +230 -0
- package/src/utils/validate-exposed-functions-gated.ts +94 -0
- package/src/utils/validate-tags-resolve-to-middleware.test.ts +105 -0
- package/src/utils/validate-tags-resolve-to-middleware.ts +48 -0
- package/src/visit.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
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(run(stateWith({ console: { tags: ['admin'] } }, ['admin'])), [])
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('stays quiet when only channel middleware is registered for the tag', () => {
|
|
66
|
+
assert.deepEqual(
|
|
67
|
+
run(stateWith({ console: { tags: ['admin'] } }, [], ['admin'])),
|
|
68
|
+
[]
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('reports each unresolved tag on an addon separately', () => {
|
|
73
|
+
const found = run(
|
|
74
|
+
stateWith({ console: { tags: ['admin', 'audited'] } }, ['admin'])
|
|
75
|
+
)
|
|
76
|
+
assert.equal(found.length, 1)
|
|
77
|
+
assert.match(found[0]!.message, /audited/)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('reports the same tag once per addon that declares it', () => {
|
|
81
|
+
const found = run(
|
|
82
|
+
stateWith({ console: { tags: ['admin'] }, billing: { tags: ['admin'] } })
|
|
83
|
+
)
|
|
84
|
+
assert.equal(found.length, 2)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('stays quiet for an addon with no tags', () => {
|
|
88
|
+
assert.deepEqual(run(stateWith({ console: {} })), [])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('stays quiet when there are no addons at all', () => {
|
|
92
|
+
assert.deepEqual(run(stateWith({})), [])
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('tolerates rpc state being absent', () => {
|
|
96
|
+
// Inspection of a package with no RPC surface never populates it.
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
run({
|
|
99
|
+
middleware: { tagMiddleware: new Map() },
|
|
100
|
+
channelMiddleware: { tagMiddleware: new Map() },
|
|
101
|
+
} as any),
|
|
102
|
+
[]
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
}
|
package/src/visit.ts
CHANGED
|
@@ -28,6 +28,8 @@ import { addAuth } from './add/add-auth.js'
|
|
|
28
28
|
import { addSecret } from './add/add-secret.js'
|
|
29
29
|
import { addCredential } from './add/add-credential.js'
|
|
30
30
|
import { addScope } from './add/add-scope.js'
|
|
31
|
+
import { addSystemRole } from './add/add-system-role.js'
|
|
32
|
+
import { addPersonas } from './add/add-personas.js'
|
|
31
33
|
import { addVariable } from './add/add-variable.js'
|
|
32
34
|
import { addWorkflowGraph } from './add/add-workflow-graph.js'
|
|
33
35
|
import { addFeature } from './add/add-feature.js'
|
|
@@ -152,6 +154,8 @@ export const visitRoutes = (
|
|
|
152
154
|
addSecret(logger, node, checker, state, nextOptions)
|
|
153
155
|
addCredential(logger, node, checker, state, nextOptions)
|
|
154
156
|
addScope(logger, node, checker, state, nextOptions)
|
|
157
|
+
addSystemRole(logger, node, checker, state, nextOptions)
|
|
158
|
+
addPersonas(logger, node, checker, state, nextOptions)
|
|
155
159
|
addVariable(logger, node, checker, state, nextOptions)
|
|
156
160
|
|
|
157
161
|
addHTTPRoute(logger, node, checker, state, nextOptions)
|