@starci/eslint-canon-be 3.8.19 → 3.9.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 (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -6,165 +6,181 @@ import path from 'node:path';
6
6
  import { machineKit } from './machine-ast.mjs';
7
7
  import { fromConfig, importedFrom, jwtPolicyProblems, reportAt, unwrap } from './jwt-ast.mjs';
8
8
  import { accessName } from '../../lib/ts-ast.mjs';
9
-
10
9
  const PASSPORT_SLOT = 'be.integrations.passport';
11
10
  const BE_JWT_VERIFIED = 'BE_AUTH_JWT_OWN_JWKS';
12
-
13
11
  /** The rule ids the back-end identity machine reports. */
14
12
  export const IDENTITY_RULE_IDS = Object.freeze(['BE_AUTH_JWT_OWN_JWKS', 'BE_JWT_ALG_PINNED']);
15
13
  const JWT_MODULES = new Set(['jose', 'jsonwebtoken', 'jwt-decode']);
16
14
  const CLAIM_NAMES = new Set(['role', 'roles', 'membership', 'memberships']);
17
-
18
15
  const objectLiteral = (kit, checker, node) => {
19
- const current = unwrap(kit.ts, node);
20
- if (kit.ts.isObjectLiteralExpression(current)) return current;
21
- if (!kit.ts.isIdentifier(current)) return null;
22
- for (const declaration of kit.declarationsOf(checker, current)) {
23
- if (kit.ts.isVariableDeclaration(declaration) && declaration.initializer) {
24
- const value = unwrap(kit.ts, declaration.initializer);
25
- if (kit.ts.isObjectLiteralExpression(value)) return value;
16
+ const current = unwrap(kit.ts, node);
17
+ if (!current)
18
+ return null;
19
+ if (kit.ts.isObjectLiteralExpression(current))
20
+ return current;
21
+ if (!kit.ts.isIdentifier(current))
22
+ return null;
23
+ for (const declaration of kit.declarationsOf(checker, current)) {
24
+ if (kit.ts.isVariableDeclaration(declaration) && declaration.initializer) {
25
+ const value = unwrap(kit.ts, declaration.initializer);
26
+ if (kit.ts.isObjectLiteralExpression(value))
27
+ return value;
28
+ }
26
29
  }
27
- }
28
- return null;
30
+ return null;
29
31
  };
30
-
31
32
  const staticStrings = (kit, checker, node) => {
32
- const current = unwrap(kit.ts, node);
33
- if (kit.ts.isStringLiteralLike(current)) return [current.text];
34
- if (kit.ts.isArrayLiteralExpression(current) && current.elements.every((element) => kit.ts.isStringLiteralLike(element))) return current.elements.map((element) => element.text);
35
- const value = kit.stringValue(checker, current);
36
- return value === null ? null : [value];
33
+ const current = unwrap(kit.ts, node);
34
+ if (kit.ts.isStringLiteralLike(current))
35
+ return [current.text];
36
+ if (kit.ts.isArrayLiteralExpression(current)) {
37
+ const literals = current.elements.filter((element) => kit.ts.isStringLiteralLike(element));
38
+ if (literals.length === current.elements.length)
39
+ return literals.map((element) => element.text);
40
+ }
41
+ const value = kit.stringValue(checker, current);
42
+ return value === null ? null : [value];
37
43
  };
38
-
39
44
  const jwksArgument = (kit, checker, node) => {
40
- const current = unwrap(kit.ts, node);
41
- if (kit.ts.isCallExpression(current)) return importedFrom(kit, checker, current.expression, new Set(['jose']), new Set(['createLocalJWKSet']));
42
- if (!kit.ts.isIdentifier(current)) return false;
43
- return kit.declarationsOf(checker, current).some((declaration) => kit.ts.isVariableDeclaration(declaration) && declaration.initializer
44
- && jwksArgument(kit, checker, declaration.initializer));
45
+ const current = unwrap(kit.ts, node);
46
+ if (!current)
47
+ return false;
48
+ if (kit.ts.isCallExpression(current))
49
+ return importedFrom(kit, checker, current.expression, new Set(['jose']), new Set(['createLocalJWKSet']));
50
+ if (!kit.ts.isIdentifier(current))
51
+ return false;
52
+ return kit.declarationsOf(checker, current).some((declaration) => kit.ts.isVariableDeclaration(declaration) && declaration.initializer
53
+ && jwksArgument(kit, checker, declaration.initializer));
45
54
  };
46
-
47
55
  const importedCall = (kit, checker, call) => {
48
- const direct = kit.importBinding(checker, call.expression);
49
- if (direct?.module === 'jwt-decode' && direct.name === 'default') return { module: direct.module, name: 'jwtDecode' };
50
- if (direct) return direct;
51
- if (!kit.ts.isPropertyAccessExpression(call.expression) || !kit.ts.isIdentifier(call.expression.expression)) return null;
52
- const owner = kit.importBinding(checker, call.expression.expression);
53
- return owner?.name === 'default' ? { module: owner.module, name: call.expression.name.text } : null;
56
+ const direct = kit.importBinding(checker, call.expression);
57
+ if (direct?.module === 'jwt-decode' && direct.name === 'default')
58
+ return { module: direct.module, name: 'jwtDecode' };
59
+ if (direct)
60
+ return direct;
61
+ if (!kit.ts.isPropertyAccessExpression(call.expression) || !kit.ts.isIdentifier(call.expression.expression))
62
+ return null;
63
+ const owner = kit.importBinding(checker, call.expression.expression);
64
+ return owner?.name === 'default' ? { module: owner.module, name: call.expression.name.text } : null;
54
65
  };
55
-
56
66
  const requestLike = (ts, node) => {
57
- const current = unwrap(ts, node);
58
- if (ts.isIdentifier(current)) return /^(?:req|request)$/iu.test(current.text);
59
- return (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) && accessName(ts, current) === 'request';
67
+ const current = unwrap(ts, node);
68
+ if (ts.isIdentifier(current))
69
+ return /^(?:req|request)$/iu.test(current.text);
70
+ return (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) && accessName(ts, current) === 'request';
60
71
  };
61
-
62
72
  const fromRequestBody = (kit, checker, node, seen = new Set()) => {
63
- const current = unwrap(kit.ts, node);
64
- if (!current || seen.has(current)) return false;
65
- seen.add(current);
66
- if (kit.ts.isPropertyAccessExpression(current) || kit.ts.isElementAccessExpression(current)) {
67
- if (accessName(kit.ts, current) === 'body' && requestLike(kit.ts, current.expression)) return true;
68
- return fromRequestBody(kit, checker, current.expression, seen);
69
- }
70
- if (!kit.ts.isIdentifier(current)) return false;
71
- return kit.declarationsOf(checker, current).some(declaration => kit.ts.isVariableDeclaration(declaration) && declaration.initializer
72
- && fromRequestBody(kit, checker, declaration.initializer, seen));
73
+ const current = unwrap(kit.ts, node);
74
+ if (!current || seen.has(current))
75
+ return false;
76
+ seen.add(current);
77
+ if (kit.ts.isPropertyAccessExpression(current) || kit.ts.isElementAccessExpression(current)) {
78
+ if (accessName(kit.ts, current) === 'body' && requestLike(kit.ts, current.expression))
79
+ return true;
80
+ return fromRequestBody(kit, checker, current.expression, seen);
81
+ }
82
+ if (!kit.ts.isIdentifier(current))
83
+ return false;
84
+ return kit.declarationsOf(checker, current).some(declaration => kit.ts.isVariableDeclaration(declaration) && declaration.initializer
85
+ && fromRequestBody(kit, checker, declaration.initializer, seen));
73
86
  };
74
-
75
87
  function verifyJwtCall(kit, checker, file, node, counters, violations) {
76
- counters.verifyCalls += 1;
77
- if (file.slot !== PASSPORT_SLOT) {
78
- reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `jwtVerify is called outside ${PASSPORT_SLOT}; the integration is the one token verifier.`);
79
- return true;
80
- }
81
- const options = objectLiteral(kit, checker, node.arguments[2]);
82
- const property = name => options ? kit.propertyOf(options, name) : null;
83
- const values = name => {
84
- const entry = property(name);
85
- return entry ? staticStrings(kit, checker, kit.valueOfProperty(entry)) : null;
86
- };
87
- const issuer = property('issuer');
88
- const audience = values('audience');
89
- const algorithms = values('algorithms');
90
- // The audience is pinned by a literal or, as R260 accepts, by typed configuration (the skeleton's TokenOptions.audience).
91
- const audienceEntry = property('audience');
92
- const pinnedAudience = (audience !== null && audience.length > 0)
93
- || (audienceEntry != null && fromConfig(kit.ts, checker, kit.valueOfProperty(audienceEntry)));
94
- const good = jwksArgument(kit, checker, node.arguments[1]) && issuer != null && pinnedAudience
95
- && algorithms !== null && algorithms.length > 0;
96
- if (!good) {
97
- reportAt(violations, kit, BE_JWT_VERIFIED, file, node, 'jwtVerify must check the app\'s own key set (createLocalJWKSet(...) over the keys integrations/passport signs with) and pin issuer, audience and a non-empty algorithms list; jwtVerify then enforces signature and exp.');
98
- } else counters.verifiedCalls += 1;
99
- return false;
88
+ counters.verifyCalls += 1;
89
+ if (file.slot !== PASSPORT_SLOT) {
90
+ reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `jwtVerify is called outside ${PASSPORT_SLOT}; the integration is the one token verifier.`);
91
+ return true;
92
+ }
93
+ const options = objectLiteral(kit, checker, node.arguments[2]);
94
+ const property = (name) => options ? kit.propertyOf(options, name) : null;
95
+ const values = (name) => {
96
+ const entry = property(name);
97
+ return entry ? staticStrings(kit, checker, kit.valueOfProperty(entry)) : null;
98
+ };
99
+ const issuer = property('issuer');
100
+ const audience = values('audience');
101
+ const algorithms = values('algorithms');
102
+ // The audience is pinned by a literal or, as R260 accepts, by typed configuration (the skeleton's TokenOptions.audience).
103
+ const audienceEntry = property('audience');
104
+ const pinnedAudience = (audience !== null && audience.length > 0)
105
+ || (audienceEntry != null && fromConfig(kit.ts, checker, kit.valueOfProperty(audienceEntry)));
106
+ const good = jwksArgument(kit, checker, node.arguments[1]) && issuer != null && pinnedAudience
107
+ && algorithms !== null && algorithms.length > 0;
108
+ if (!good) {
109
+ reportAt(violations, kit, BE_JWT_VERIFIED, file, node, 'jwtVerify must check the app\'s own key set (createLocalJWKSet(...) over the keys integrations/passport signs with) and pin issuer, audience and a non-empty algorithms list; jwtVerify then enforces signature and exp.');
110
+ }
111
+ else
112
+ counters.verifiedCalls += 1;
113
+ return false;
100
114
  }
101
-
102
115
  function inspectJwtCall(kit, checker, file, node, counters, violations) {
103
- const binding = importedCall(kit, checker, node);
104
- if (binding && JWT_MODULES.has(binding.module) && ['decode', 'decodeJwt', 'jwtDecode'].includes(binding.name)) {
105
- reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${binding.module}.${binding.name} decodes a token without proving its signature; verify it through integrations/passport.`, { module: binding.module, method: binding.name });
106
- }
107
- if (binding?.module === 'jose' && binding.name === 'jwtVerify') return verifyJwtCall(kit, checker, file, node, counters, violations);
108
- return false;
116
+ const binding = importedCall(kit, checker, node);
117
+ if (binding && JWT_MODULES.has(binding.module) && ['decode', 'decodeJwt', 'jwtDecode'].includes(binding.name)) {
118
+ reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${binding.module}.${binding.name} decodes a token without proving its signature; verify it through integrations/passport.`, { module: binding.module, method: binding.name });
119
+ }
120
+ if (binding?.module === 'jose' && binding.name === 'jwtVerify')
121
+ return verifyJwtCall(kit, checker, file, node, counters, violations);
122
+ return false;
109
123
  }
110
-
111
124
  function inspectRequestClaims(kit, file, node, checker, violations) {
112
- const { ts } = kit;
113
- if ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && CLAIM_NAMES.has(accessName(ts, node))) {
125
+ const { ts } = kit;
114
126
  const claim = accessName(ts, node);
115
- if (fromRequestBody(kit, checker, node.expression)) reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${claim} is read from the request body; authorization claims come only from the verified token or the database.`, { claim });
116
- }
117
- if (ts.isVariableDeclaration(node) && ts.isObjectBindingPattern(node.name) && node.initializer && fromRequestBody(kit, checker, node.initializer)) {
118
- for (const element of node.name.elements) {
119
- const property = element.propertyName ?? element.name;
120
- if (ts.isIdentifier(property) && CLAIM_NAMES.has(property.text)) reportAt(violations, kit, BE_JWT_VERIFIED, file, element, `${property.text} is destructured from the request body; authorization claims come only from the verified token or the database.`, { claim: property.text });
127
+ if ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && claim !== null && CLAIM_NAMES.has(claim)) {
128
+ if (fromRequestBody(kit, checker, node.expression))
129
+ reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${claim} is read from the request body; authorization claims come only from the verified token or the database.`, { claim });
130
+ }
131
+ if (ts.isVariableDeclaration(node) && ts.isObjectBindingPattern(node.name) && node.initializer && fromRequestBody(kit, checker, node.initializer)) {
132
+ for (const element of node.name.elements) {
133
+ const property = element.propertyName ?? element.name;
134
+ if (ts.isIdentifier(property) && CLAIM_NAMES.has(property.text))
135
+ reportAt(violations, kit, BE_JWT_VERIFIED, file, element, `${property.text} is destructured from the request body; authorization claims come only from the verified token or the database.`, { claim: property.text });
136
+ }
121
137
  }
122
- }
123
138
  }
124
-
125
139
  function inspectBackendNode(kit, checker, file, node, counters, violations) {
126
- const handled = kit.ts.isCallExpression(node) && inspectJwtCall(kit, checker, file, node, counters, violations);
127
- if (!handled) inspectRequestClaims(kit, file, node, checker, violations);
140
+ const handled = kit.ts.isCallExpression(node) && inspectJwtCall(kit, checker, file, node, counters, violations);
141
+ if (!handled)
142
+ inspectRequestClaims(kit, file, node, checker, violations);
128
143
  }
129
-
130
144
  function checkOwnJwks(input) {
131
- const kit = machineKit(input);
132
- const violations = [];
133
- const integrations = [...input.graph.files.values()].filter((file) => file.slot === PASSPORT_SLOT);
134
- if (!integrations.length) return { violations, coverage: { status: 'not-applicable', integrationFiles: 0, verifiedCalls: 0 } };
135
- const counters = { verifyCalls: 0, verifiedCalls: 0 };
136
- for (const file of input.graph.files.values()) {
137
- const checker = kit.checkerOf(file.sourceFile);
138
- kit.walk(file.sourceFile, node => inspectBackendNode(kit, checker, file, node, counters, violations));
139
- }
140
- if (counters.verifyCalls === 0) {
141
- const anchor = integrations.find((file) => path.posix.basename(file.rel).endsWith('.tokens.ts')) ?? integrations[0];
142
- reportAt(violations, kit, BE_JWT_VERIFIED, anchor, anchor.sourceFile, `${PASSPORT_SLOT} has no jose.jwtVerify call backed by createLocalJWKSet over the app's own keys.`);
143
- }
144
- return { violations, coverage: { status: 'checked', integrationFiles: integrations.length, verifyCalls: counters.verifyCalls, verifiedCalls: counters.verifiedCalls } };
145
+ const kit = machineKit(input);
146
+ const violations = [];
147
+ const integrations = [...input.graph.files.values()].filter((file) => file.slot === PASSPORT_SLOT);
148
+ if (!integrations.length)
149
+ return { violations, coverage: { status: 'not-applicable', integrationFiles: 0, verifiedCalls: 0 } };
150
+ const counters = { verifyCalls: 0, verifiedCalls: 0 };
151
+ for (const file of input.graph.files.values()) {
152
+ const checker = kit.checkerOf(file.sourceFile);
153
+ kit.walk(file.sourceFile, (node) => inspectBackendNode(kit, checker, file, node, counters, violations));
154
+ }
155
+ if (counters.verifyCalls === 0) {
156
+ const anchor = integrations.find((file) => path.posix.basename(file.rel).endsWith('.tokens.ts')) ?? integrations[0];
157
+ if (anchor)
158
+ reportAt(violations, kit, BE_JWT_VERIFIED, anchor, anchor.sourceFile, `${PASSPORT_SLOT} has no jose.jwtVerify call backed by createLocalJWKSet over the app's own keys.`);
159
+ }
160
+ return { violations, coverage: { status: 'checked', integrationFiles: integrations.length, verifyCalls: counters.verifyCalls, verifiedCalls: counters.verifiedCalls } };
145
161
  }
146
-
147
162
  /** R260 BE_JWT_ALG_PINNED: every jose jwtVerify call pins a literal secure algorithm list and a configured issuer, and binds the principal by a configured audience or the authenticated role. */
148
163
  export function checkJwtPolicy(input) {
149
- const kit = machineKit(input);
150
- const violations = [];
151
- let verifyCalls = 0;
152
- for (const file of input.graph.files.values()) {
153
- const checker = kit.checkerOf(file.sourceFile);
154
- kit.walk(file.sourceFile, node => {
155
- if (!kit.ts.isCallExpression(node) || !kit.isImportOf(checker, node.expression, 'jwtVerify', 'jose')) return;
156
- verifyCalls += 1;
157
- const problems = jwtPolicyProblems(kit.ts, checker, node);
158
- if (problems.length) reportAt(violations, kit, 'BE_JWT_ALG_PINNED', file, node, problems.join(' '));
159
- });
160
- }
161
- return { violations, coverage: { status: 'checked', verifyCalls } };
164
+ const kit = machineKit(input);
165
+ const violations = [];
166
+ let verifyCalls = 0;
167
+ for (const file of input.graph.files.values()) {
168
+ const checker = kit.checkerOf(file.sourceFile);
169
+ kit.walk(file.sourceFile, (node) => {
170
+ if (!kit.ts.isCallExpression(node) || !kit.isImportOf(checker, node.expression, 'jwtVerify', 'jose'))
171
+ return;
172
+ verifyCalls += 1;
173
+ const problems = jwtPolicyProblems(kit.ts, checker, node);
174
+ if (problems.length)
175
+ reportAt(violations, kit, 'BE_JWT_ALG_PINNED', file, node, problems.join(' '));
176
+ });
177
+ }
178
+ return { violations, coverage: { status: 'checked', verifyCalls } };
162
179
  }
163
-
164
180
  /** The back-end identity machine: the own-JWKS law where the passport integration exists (lite), the JWT policy everywhere. */
165
181
  export function checkBackendIdentity(input) {
166
- const slot = input.graph.resolver.slot(PASSPORT_SLOT);
167
- const own = slot && input.graph.resolver.slotEnabled(slot) ? checkOwnJwks(input) : { violations: [], coverage: { status: 'not-applicable', reason: 'no passport integration slot (full edition)' } };
168
- const policy = checkJwtPolicy(input);
169
- return { violations: [...own.violations, ...policy.violations], coverage: { status: 'checked', ownJwks: own.coverage, jwtPolicy: policy.coverage } };
182
+ const slot = input.graph.resolver.slot(PASSPORT_SLOT);
183
+ const own = slot && input.graph.resolver.slotEnabled(slot) ? checkOwnJwks(input) : { violations: [], coverage: { status: 'not-applicable', reason: 'no passport integration slot (full edition)' } };
184
+ const policy = checkJwtPolicy(input);
185
+ return { violations: [...own.violations, ...policy.violations], coverage: { status: 'checked', ownJwks: own.coverage, jwtPolicy: policy.coverage } };
170
186
  }