@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.5

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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1191 -816
  3. package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
  4. package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
  5. package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
  6. package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
  7. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
  8. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
  9. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
  10. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
  11. package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
  12. package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
  13. package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
  14. package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
  15. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
  16. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
  17. package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
  18. package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
  19. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
  20. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
  21. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
  22. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
  23. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
  24. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
  25. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
  26. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
  27. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
  28. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
  29. package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
  30. package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
  31. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
  32. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
  33. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
  34. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
  35. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
  36. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
  37. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
  38. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
  39. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
  40. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
  41. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
  42. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
  43. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
  44. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
  45. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
  46. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
  47. package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
  48. package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
  49. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
  50. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
  51. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
  52. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
  53. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
  54. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
  55. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
  56. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
  57. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
  58. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
  59. package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
  60. package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
  61. package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
  62. package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
  63. package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
  64. package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
  65. package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
  66. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
  67. package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
  68. package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
  69. package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
  70. package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
  71. package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
  72. package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
  73. package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
  74. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
  75. package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
  76. package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
  77. package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
  78. package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
  79. package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
  80. package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
  81. package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
  82. package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
  83. package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
  84. package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
  85. package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
  86. package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
  87. package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
  88. package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
  89. package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
  90. package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
  91. package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
  92. package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
  93. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
  94. package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
  95. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
  96. package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
  97. package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
  98. package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
  99. package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
  100. package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
  101. package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
  102. package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
  103. package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
  104. package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
  105. package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
  106. package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
  107. package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
  108. package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
  109. package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
  110. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
  111. package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
  112. package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
  113. package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
  114. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
  115. package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
  116. package/dist/index.d.ts +225 -48
  117. package/dist/index.js +1190 -815
  118. package/node_modules/@code-sentinel/core/index.js +55 -0
  119. package/node_modules/@code-sentinel/core/package.json +6 -0
  120. package/node_modules/@code-sentinel/parsers/index.js +13 -0
  121. package/node_modules/@code-sentinel/parsers/package.json +6 -0
  122. package/package.json +34 -29
  123. package/src/migrations/0000_initial.sql +62 -0
  124. package/src/migrations/0001_add_confidence.sql +7 -0
  125. package/src/migrations/0002_add_ai_stats.sql +21 -0
  126. package/src/migrations/0003_add_fix_recipe.sql +29 -0
  127. package/src/migrations/0004_add_ast_graph.sql +61 -0
  128. package/src/migrations/0005_add_project_id.sql +1 -0
  129. package/src/migrations/0006_add_ai_model.sql +5 -0
  130. package/src/migrations/0006_add_rule_results.sql +1 -0
  131. package/src/migrations/0007_add_finding_metadata.sql +4 -0
  132. package/src/migrations/0008_add_coverage.sql +2 -0
  133. package/src/migrations/0009_run_provenance.sql +5 -0
@@ -0,0 +1,105 @@
1
+ import { asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/angular/image-control-alt-required.rule.ts
4
+ var OPENING_TAGS = /* @__PURE__ */ new Set(["start_tag", "self_closing_tag"]);
5
+ var ALT_PROVIDING_ATTRS = /* @__PURE__ */ new Set([
6
+ "alt",
7
+ "aria-label",
8
+ "aria-labelledby",
9
+ "title",
10
+ "aria-hidden"
11
+ ]);
12
+ function* walkOpeningTags(node) {
13
+ const stack = [node];
14
+ while (stack.length > 0) {
15
+ const cur = stack.pop();
16
+ if (!cur) continue;
17
+ if (OPENING_TAGS.has(cur.type)) yield cur;
18
+ for (let i = cur.namedChildCount - 1; i >= 0; i--) {
19
+ const child = cur.namedChild(i);
20
+ if (child) stack.push(child);
21
+ }
22
+ }
23
+ }
24
+ function namedChildOfType(node, type) {
25
+ for (let i = 0; i < node.namedChildCount; i++) {
26
+ const child = node.namedChild(i);
27
+ if (child?.type === type) return child;
28
+ }
29
+ return null;
30
+ }
31
+ function tagName(tag) {
32
+ const n = namedChildOfType(tag, "tag_name");
33
+ return n ? n.text.toLowerCase() : null;
34
+ }
35
+ function normalizeAttrName(name) {
36
+ let inner = name;
37
+ const bracket = /^\[(.+)\]$/.exec(inner);
38
+ if (bracket?.[1]) inner = bracket[1];
39
+ else if (inner.startsWith("bind-")) inner = inner.slice("bind-".length);
40
+ return inner.replace(/^attr\./i, "").toLowerCase();
41
+ }
42
+ function attributeValue(attr) {
43
+ const quoted = namedChildOfType(attr, "quoted_attribute_value");
44
+ const value = quoted ? namedChildOfType(quoted, "attribute_value") : null;
45
+ return value?.text ?? "";
46
+ }
47
+ function collectAttrs(tag) {
48
+ const names = /* @__PURE__ */ new Set();
49
+ let staticType = null;
50
+ for (let i = 0; i < tag.namedChildCount; i++) {
51
+ const attr = tag.namedChild(i);
52
+ if (attr?.type !== "attribute") continue;
53
+ const nameNode = namedChildOfType(attr, "attribute_name");
54
+ if (!nameNode) continue;
55
+ const raw = nameNode.text;
56
+ names.add(normalizeAttrName(raw));
57
+ if (raw.toLowerCase() === "type") staticType = attributeValue(attr).trim().toLowerCase();
58
+ }
59
+ return { names, staticType };
60
+ }
61
+ var hasTextAlternative = (names) => {
62
+ for (const n of names) if (ALT_PROVIDING_ATTRS.has(n)) return true;
63
+ return false;
64
+ };
65
+ var rule = {
66
+ id: "angular/image-control-alt-required",
67
+ version: 1,
68
+ kind: "static-ts",
69
+ title: '`<input type="image">` / `<area>` ph\u1EA3i c\xF3 text alternative (`alt`)',
70
+ description: '`<input type="image">` (n\xFAt submit b\u1EB1ng \u1EA3nh) v\xE0 `<area>` (v\xF9ng click c\u1EE7a image map) truy\u1EC1n \u0111\u1EA1t \xFD ngh\u0129a qua h\xECnh \u1EA3nh \u2014 thi\u1EBFu text alternative l\xE0 l\u1ED7i WCAG 1.1.1 (Level A) / 4.1.2: ng\u01B0\u1EDDi d\xF9ng screen-reader kh\xF4ng bi\u1EBFt control l\xE0m g\xEC. Th\xEAm `alt` m\xF4 t\u1EA3 h\xE0nh \u0111\u1ED9ng. Rule b\u1ECF qua khi \u0111\xE3 c\xF3 `alt`/`aria-label`/`aria-labelledby`/`title`/`aria-hidden`. T\u01B0\u01A1ng \u0111\u01B0\u01A1ng axe-core `input-image-alt` / `area-alt`. Sibling c\u1EE7a `angular/img-alt-required`.',
71
+ severity: "warning",
72
+ category: "accessibility",
73
+ languages: ["html"],
74
+ scope: "angular",
75
+ requires: "syntactic",
76
+ baseConfidence: 80,
77
+ check(ctx) {
78
+ const tree = asTreeSitterTree(ctx.parsed);
79
+ const findings = [];
80
+ for (const tag of walkOpeningTags(tree.rootNode)) {
81
+ const name = tagName(tag);
82
+ if (name !== "input" && name !== "area") continue;
83
+ const { names, staticType } = collectAttrs(tag);
84
+ const isImageInput = name === "input" && staticType === "image";
85
+ const isLinkedArea = name === "area" && names.has("href");
86
+ if (!isImageInput && !isLinkedArea) continue;
87
+ if (hasTextAlternative(names)) continue;
88
+ const what = isImageInput ? '`<input type="image">`' : "`<area>` (image map)";
89
+ findings.push({
90
+ message: `${what} thi\u1EBFu text alternative \u2014 screen-reader kh\xF4ng m\xF4 t\u1EA3 \u0111\u01B0\u1EE3c control (l\u1ED7i WCAG 1.1.1 Level A). Th\xEAm \`alt\` m\xF4 t\u1EA3 h\xE0nh \u0111\u1ED9ng.`,
91
+ file: ctx.file.path,
92
+ range: {
93
+ line: tag.startPosition.row + 1,
94
+ column: tag.startPosition.column + 1
95
+ },
96
+ suggestion: 'Th\xEAm `alt="m\xF4 t\u1EA3 h\xE0nh \u0111\u1ED9ng"` (ho\u1EB7c `[alt]="expr"`); ho\u1EB7c d\xF9ng `aria-label`/`aria-labelledby` \u0111\u1EC3 cung c\u1EA5p t\xEAn cho control.'
97
+ });
98
+ }
99
+ return findings;
100
+ }
101
+ };
102
+
103
+ export { rule };
104
+ //# sourceMappingURL=image-control-alt-required.rule.js.map
105
+ //# sourceMappingURL=image-control-alt-required.rule.js.map
@@ -0,0 +1,96 @@
1
+ import { asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/angular/img-alt-required.rule.ts
4
+ var OPENING_TAGS = /* @__PURE__ */ new Set(["start_tag", "self_closing_tag"]);
5
+ var ALT_PROVIDING_ATTRS = /* @__PURE__ */ new Set([
6
+ "alt",
7
+ "aria-label",
8
+ "aria-labelledby",
9
+ "title",
10
+ "aria-hidden"
11
+ ]);
12
+ var DECORATIVE_ROLES = /* @__PURE__ */ new Set(["presentation", "none"]);
13
+ function* walkOpeningTags(node) {
14
+ const stack = [node];
15
+ while (stack.length > 0) {
16
+ const cur = stack.pop();
17
+ if (!cur) continue;
18
+ if (OPENING_TAGS.has(cur.type)) yield cur;
19
+ for (let i = cur.namedChildCount - 1; i >= 0; i--) {
20
+ const child = cur.namedChild(i);
21
+ if (child) stack.push(child);
22
+ }
23
+ }
24
+ }
25
+ function namedChildOfType(node, type) {
26
+ for (let i = 0; i < node.namedChildCount; i++) {
27
+ const child = node.namedChild(i);
28
+ if (child?.type === type) return child;
29
+ }
30
+ return null;
31
+ }
32
+ function tagName(tag) {
33
+ const n = namedChildOfType(tag, "tag_name");
34
+ return n ? n.text.toLowerCase() : null;
35
+ }
36
+ function normalizeAttrName(name) {
37
+ let inner = name;
38
+ const bracket = /^\[(.+)\]$/.exec(inner);
39
+ if (bracket?.[1]) inner = bracket[1];
40
+ else if (inner.startsWith("bind-")) inner = inner.slice("bind-".length);
41
+ return inner.replace(/^attr\./i, "").toLowerCase();
42
+ }
43
+ function attributeValue(attr) {
44
+ const quoted = namedChildOfType(attr, "quoted_attribute_value");
45
+ const value = quoted ? namedChildOfType(quoted, "attribute_value") : null;
46
+ return value?.text ?? "";
47
+ }
48
+ function hasTextAlternative(tag) {
49
+ for (let i = 0; i < tag.namedChildCount; i++) {
50
+ const child = tag.namedChild(i);
51
+ if (child?.type !== "attribute") continue;
52
+ const nameNode = namedChildOfType(child, "attribute_name");
53
+ if (!nameNode) continue;
54
+ const prop = normalizeAttrName(nameNode.text);
55
+ if (ALT_PROVIDING_ATTRS.has(prop)) return true;
56
+ if (prop === "role" && DECORATIVE_ROLES.has(attributeValue(child).trim().toLowerCase())) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+ var rule = {
63
+ id: "angular/img-alt-required",
64
+ version: 1,
65
+ kind: "static-ts",
66
+ title: "`<img>` ph\u1EA3i c\xF3 text alternative (`alt`) \u0111\u1EC3 \u0111\u1EA3m b\u1EA3o accessibility",
67
+ description: 'Th\u1EBB `<img>` thi\u1EBFu text alternative l\xE0 l\u1ED7i WCAG 1.1.1 (Level A): ng\u01B0\u1EDDi d\xF9ng screen-reader kh\xF4ng nh\u1EADn \u0111\u01B0\u1EE3c th\xF4ng tin g\xEC, nhi\u1EC1u tr\xECnh duy\u1EC7t \u0111\u1ECDc lu\xF4n t\xEAn file trong `src`. Th\xEAm `alt` m\xF4 t\u1EA3 n\u1ED9i dung \u1EA3nh; n\u1EBFu \u1EA3nh ch\u1EC9 trang tr\xED th\xEC d\xF9ng `alt=""` (khai b\xE1o r\xF5 l\xE0 decorative). \u1EA2nh \u0111\u1ED9ng c\u0169ng c\xF3 th\u1EC3 d\xF9ng `[alt]="\u2026"`. Rule b\u1ECF qua khi `<img>` \u0111\xE3 c\xF3 `alt`/`aria-label`/`aria-labelledby`/`title`/`aria-hidden` ho\u1EB7c `role="presentation"|"none"`.',
68
+ severity: "warning",
69
+ category: "accessibility",
70
+ languages: ["html"],
71
+ scope: "angular",
72
+ requires: "syntactic",
73
+ baseConfidence: 80,
74
+ check(ctx) {
75
+ const tree = asTreeSitterTree(ctx.parsed);
76
+ const findings = [];
77
+ for (const tag of walkOpeningTags(tree.rootNode)) {
78
+ if (tagName(tag) !== "img") continue;
79
+ if (hasTextAlternative(tag)) continue;
80
+ findings.push({
81
+ message: '`<img>` thi\u1EBFu `alt` \u2014 screen-reader kh\xF4ng m\xF4 t\u1EA3 \u0111\u01B0\u1EE3c \u1EA3nh (l\u1ED7i WCAG 1.1.1 Level A). Th\xEAm `alt` m\xF4 t\u1EA3 n\u1ED9i dung, ho\u1EB7c `alt=""` n\u1EBFu \u1EA3nh ch\u1EC9 trang tr\xED.',
82
+ file: ctx.file.path,
83
+ range: {
84
+ line: tag.startPosition.row + 1,
85
+ column: tag.startPosition.column + 1
86
+ },
87
+ suggestion: 'Th\xEAm `alt="m\xF4 t\u1EA3 \u1EA3nh"` (ho\u1EB7c `[alt]="expr"`); \u1EA3nh trang tr\xED d\xF9ng `alt=""` ho\u1EB7c `role="presentation"`; n\u1EBFu c\u1EA7n \u1EA9n kh\u1ECFi screen-reader d\xF9ng `aria-hidden="true"`.'
88
+ });
89
+ }
90
+ return findings;
91
+ }
92
+ };
93
+
94
+ export { rule };
95
+ //# sourceMappingURL=img-alt-required.rule.js.map
96
+ //# sourceMappingURL=img-alt-required.rule.js.map
@@ -0,0 +1,47 @@
1
+ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/angular/inject-pattern.rule.ts
4
+ var ANGULAR_DI_DECORATORS = /* @__PURE__ */ new Set(["Component", "Directive", "Injectable", "Pipe"]);
5
+ var hasAngularDecorator = (cls) => {
6
+ for (const d of cls.getDecorators()) {
7
+ if (ANGULAR_DI_DECORATORS.has(d.getName())) return true;
8
+ }
9
+ return false;
10
+ };
11
+ var rule = {
12
+ id: "angular/inject-pattern",
13
+ version: 1,
14
+ kind: "static-ts",
15
+ title: "D\xF9ng inject() thay v\xEC constructor DI (Angular 14+)",
16
+ description: "inject() ch\u1EA1y \u0111\u01B0\u1EE3c trong field initializer, g\u1ECDn h\u01A1n constructor params. C\u0169ng l\xE0 pattern b\u1EAFt bu\u1ED9c cho m\u1ED9t s\u1ED1 functional guards / interceptors. Flag m\u1ECDi constructor c\xF3 param trong class Angular (Component/Directive/Injectable/Pipe).",
17
+ severity: "info",
18
+ category: "angular-best-practice",
19
+ languages: ["typescript"],
20
+ scope: "angular",
21
+ requires: "semantic-ts",
22
+ baseConfidence: 75,
23
+ check(ctx) {
24
+ const sf = asTsMorphSourceFile(ctx.parsed);
25
+ const findings = [];
26
+ for (const cls of sf.getClasses()) {
27
+ if (!hasAngularDecorator(cls)) continue;
28
+ const ctor = cls.getConstructors()[0];
29
+ if (!ctor) continue;
30
+ const params = ctor.getParameters();
31
+ if (params.length === 0) continue;
32
+ const className = cls.getName() ?? "<anonymous>";
33
+ const { line, column } = sf.getLineAndColumnAtPos(ctor.getStart());
34
+ findings.push({
35
+ message: `"${className}" d\xF9ng constructor DI (${params.length} param) \u2014 c\xE2n nh\u1EAFc chuy\u1EC3n sang \`inject()\`.`,
36
+ file: ctx.file.path,
37
+ range: { line, column },
38
+ suggestion: "Thay `constructor(private svc: Svc) {}` b\u1EB1ng `private svc = inject(Svc);` (import `inject` t\u1EEB @angular/core)."
39
+ });
40
+ }
41
+ return findings;
42
+ }
43
+ };
44
+
45
+ export { rule };
46
+ //# sourceMappingURL=inject-pattern.rule.js.map
47
+ //# sourceMappingURL=inject-pattern.rule.js.map
@@ -0,0 +1,59 @@
1
+ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/angular/lifecycle-method-required.rule.ts
4
+ var LIFECYCLE_TO_INTERFACE = {
5
+ ngOnInit: "OnInit",
6
+ ngOnDestroy: "OnDestroy",
7
+ ngOnChanges: "OnChanges",
8
+ ngDoCheck: "DoCheck",
9
+ ngAfterContentInit: "AfterContentInit",
10
+ ngAfterContentChecked: "AfterContentChecked",
11
+ ngAfterViewInit: "AfterViewInit",
12
+ ngAfterViewChecked: "AfterViewChecked"
13
+ };
14
+ var getImplementedInterfaceNames = (cls) => {
15
+ const names = /* @__PURE__ */ new Set();
16
+ for (const impl of cls.getImplements()) {
17
+ const expr = impl.getExpression();
18
+ names.add(expr.getText());
19
+ }
20
+ return names;
21
+ };
22
+ var rule = {
23
+ id: "angular/lifecycle-method-required",
24
+ version: 1,
25
+ kind: "static-ts",
26
+ title: "Class c\xF3 lifecycle method ph\u1EA3i `implements` interface t\u01B0\u01A1ng \u1EE9ng",
27
+ description: "Khi class c\xF3 ngOnInit/ngOnDestroy/... ph\u1EA3i khai b\xE1o `implements OnInit`/etc. Compiler s\u1EBD verify signature; typo (vd `ngOninit`) s\u1EBD b\u1ECB compiler b\u1EAFt thay v\xEC silent fail.",
28
+ severity: "warning",
29
+ category: "angular-correctness",
30
+ languages: ["typescript"],
31
+ scope: "angular",
32
+ requires: "semantic-ts",
33
+ baseConfidence: 85,
34
+ check(ctx) {
35
+ const sf = asTsMorphSourceFile(ctx.parsed);
36
+ const findings = [];
37
+ for (const cls of sf.getClasses()) {
38
+ const implemented = getImplementedInterfaceNames(cls);
39
+ for (const method of cls.getMethods()) {
40
+ const name = method.getName();
41
+ const expectedInterface = LIFECYCLE_TO_INTERFACE[name];
42
+ if (!expectedInterface) continue;
43
+ if (implemented.has(expectedInterface)) continue;
44
+ const { line, column } = sf.getLineAndColumnAtPos(method.getStart());
45
+ findings.push({
46
+ message: `Method "${name}" thi\u1EBFu \`implements ${expectedInterface}\` tr\xEAn class "${cls.getName() ?? "<anonymous>"}".`,
47
+ file: ctx.file.path,
48
+ range: { line, column },
49
+ suggestion: `Th\xEAm \`implements ${expectedInterface}\` (import t\u1EEB \`@angular/core\`) \u0111\u1EC3 compiler verify signature.`
50
+ });
51
+ }
52
+ }
53
+ return findings;
54
+ }
55
+ };
56
+
57
+ export { rule };
58
+ //# sourceMappingURL=lifecycle-method-required.rule.js.map
59
+ //# sourceMappingURL=lifecycle-method-required.rule.js.map
@@ -0,0 +1,55 @@
1
+ id: angular/no-any-type
2
+ # version: 3 → severity calibration warning → info (real benchmark on a Viettel
3
+ # Angular module produced 1414 `any` findings = 42% of the report; a triage
4
+ # confirmed 100% are genuine `any` but they are low-priority style smells that
5
+ # drown out bug/security findings). Detection LOGIC unchanged (still flags every
6
+ # `: any` predefined_type, still ships the safe `any → unknown` auto-fix); only
7
+ # severity dropped so `--min-severity warning` hides them from CI gates/reports.
8
+ # version: 2 added the Phase-14.3 auto-fix recipe.
9
+ version: 3
10
+ kind: static-yaml
11
+ title: "Không dùng kiểu `any` — định nghĩa type cụ thể hoặc dùng `unknown`"
12
+ description: |
13
+ `any` tắt type-checking, biến TypeScript thành JavaScript. Nếu chưa biết
14
+ kiểu, dùng `unknown` + narrowing; nếu là object dạng tự do, dùng
15
+ `Record<string, unknown>`; nếu là API response, định nghĩa interface
16
+ hoặc dùng Zod.
17
+
18
+ Phase 8 đơn giản: flag mọi token `any` xuất hiện như predefined_type
19
+ trong type annotation. Không phân biệt `any` trong type alias vs trong
20
+ parameter — mọi nơi đều flag.
21
+
22
+ Rule này thuộc scope Angular vì Angular project hay dùng `any` cho
23
+ HTTP response, form value — nhưng kỹ thuật áp dụng cho mọi TS project.
24
+ severity: info
25
+ category: type-safety
26
+ languages: [typescript]
27
+ scope: angular
28
+ baseConfidence: 100
29
+ detection:
30
+ type: tree-sitter
31
+ captureName: violation
32
+ query: |
33
+ (predefined_type) @violation
34
+ (#eq? @violation "any")
35
+ message: "Tránh dùng `any` — chuyển sang type cụ thể, interface, hoặc `unknown`."
36
+ suggestion: "Dùng `unknown` + narrowing nếu chưa biết kiểu; định nghĩa interface cho object có shape rõ; `Record<string, unknown>` cho dictionary."
37
+ # Phase 14.3 — auto-fix: SAFE token swap. Replacing `any` with `unknown`
38
+ # preserves runtime semantics and makes the type-checker stricter (every
39
+ # use site must narrow). Cannot introduce a NEW violation because the
40
+ # rule's own query only matches the literal `any` token.
41
+ fix:
42
+ safety: safe
43
+ description: "Replace `any` with `unknown`"
44
+ replacement: unknown
45
+ examples:
46
+ good: |
47
+ function process(value: unknown): string {
48
+ if (typeof value === 'string') return value;
49
+ return String(value);
50
+ }
51
+ interface User { id: number; name: string }
52
+ function getUser(): User { /* ... */ }
53
+ bad: |
54
+ function process(value: any): any { return value; }
55
+ const data: any = await http.get('/api/users');
@@ -0,0 +1,191 @@
1
+ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
2
+ import { SyntaxKind, Node } from 'ts-morph';
3
+
4
+ // builtin-rules/static/angular/no-direct-dom-access.rule.ts
5
+ var REQUIRED_CORE_IMPORTS = ["Renderer2", "inject"];
6
+ var hasComponentDecorator = (cls) => {
7
+ for (const d of cls.getDecorators()) {
8
+ if (d.getName() === "Component") return true;
9
+ }
10
+ return false;
11
+ };
12
+ var toEdit = (sf, filePath, startPos, endPos, newText) => {
13
+ const start = sf.getLineAndColumnAtPos(startPos);
14
+ const end = sf.getLineAndColumnAtPos(endPos);
15
+ return {
16
+ file: filePath,
17
+ startLine: start.line,
18
+ startColumn: start.column,
19
+ endLine: end.line,
20
+ endColumn: end.column,
21
+ newText
22
+ };
23
+ };
24
+ var findAngularCoreImport = (sf) => sf.getImportDeclarations().find((imp) => imp.getModuleSpecifierValue() === "@angular/core");
25
+ var buildCoreImportEdits = (sf, filePath) => {
26
+ const coreImport = findAngularCoreImport(sf);
27
+ if (coreImport) {
28
+ const namedImports = coreImport.getNamedImports();
29
+ if (namedImports.length > 0) {
30
+ const existingNames = new Set(namedImports.map((named) => named.getName()));
31
+ const missing = REQUIRED_CORE_IMPORTS.filter((name) => !existingNames.has(name));
32
+ if (missing.length === 0) return [];
33
+ const first = namedImports[0];
34
+ const last = namedImports[namedImports.length - 1];
35
+ if (!first || !last) return [];
36
+ return [
37
+ toEdit(
38
+ sf,
39
+ filePath,
40
+ first.getStart(),
41
+ last.getEnd(),
42
+ [...namedImports.map((named) => named.getText()), ...missing].join(", ")
43
+ )
44
+ ];
45
+ }
46
+ }
47
+ const imports = sf.getImportDeclarations();
48
+ const lastImport = imports[imports.length - 1];
49
+ if (!lastImport) {
50
+ return [toEdit(sf, filePath, 0, 0, "import { Renderer2, inject } from '@angular/core';\n")];
51
+ }
52
+ return [
53
+ toEdit(
54
+ sf,
55
+ filePath,
56
+ lastImport.getEnd(),
57
+ lastImport.getEnd(),
58
+ "\nimport { Renderer2, inject } from '@angular/core';"
59
+ )
60
+ ];
61
+ };
62
+ var hasRendererBinding = (cls) => {
63
+ for (const member of cls.getMembers()) {
64
+ if ((Node.isPropertyDeclaration(member) || Node.isMethodDeclaration(member) || Node.isGetAccessorDeclaration(member) || Node.isSetAccessorDeclaration(member)) && member.getName() === "renderer") {
65
+ return true;
66
+ }
67
+ }
68
+ return /\b(private|protected|public)\s+(readonly\s+)?renderer\s*[:=]/.test(cls.getText());
69
+ };
70
+ var detectMemberIndent = (cls) => {
71
+ const firstMember = cls.getMembers()[0];
72
+ if (!firstMember) return " ";
73
+ const fullText = firstMember.getFullText();
74
+ const match = /\n([ \t]*)\S/.exec(fullText);
75
+ return match?.[1] ?? " ";
76
+ };
77
+ var buildRendererFieldEdit = (sf, filePath, cls) => {
78
+ const classText = cls.getText();
79
+ const openBraceInClass = classText.indexOf("{");
80
+ if (openBraceInClass === -1) return void 0;
81
+ const insertPos = cls.getStart() + openBraceInClass + 1;
82
+ const indent = detectMemberIndent(cls);
83
+ return toEdit(
84
+ sf,
85
+ filePath,
86
+ insertPos,
87
+ insertPos,
88
+ `
89
+ ${indent}private readonly renderer = inject(Renderer2);`
90
+ );
91
+ };
92
+ var literalText = (call) => {
93
+ const args = call.getArguments();
94
+ if (args.length !== 1) return void 0;
95
+ const arg = args[0];
96
+ if (!arg) return void 0;
97
+ if (Node.isStringLiteral(arg) || Node.isNoSubstitutionTemplateLiteral(arg)) {
98
+ return arg.getLiteralText();
99
+ }
100
+ return void 0;
101
+ };
102
+ var buildCallReplacement = (access, call) => {
103
+ const selector = literalText(call);
104
+ if (selector === void 0) return void 0;
105
+ if (access.getName() === "getElementById") {
106
+ return `this.renderer.selectRootElement(${JSON.stringify(`#${selector}`)}, true)`;
107
+ }
108
+ if (access.getName() === "querySelector") {
109
+ return `this.renderer.selectRootElement(${JSON.stringify(selector)}, true)`;
110
+ }
111
+ return void 0;
112
+ };
113
+ var directCallForAccess = (access) => {
114
+ const parent = access.getParent();
115
+ if (!Node.isCallExpression(parent)) return void 0;
116
+ return parent.getExpression().getStart() === access.getStart() ? parent : void 0;
117
+ };
118
+ var buildFix = (args) => {
119
+ if (!args.call) return void 0;
120
+ if (hasRendererBinding(args.cls)) return void 0;
121
+ const replacement = buildCallReplacement(args.access, args.call);
122
+ if (replacement === void 0) return void 0;
123
+ const rendererFieldEdit = buildRendererFieldEdit(args.sf, args.filePath, args.cls);
124
+ if (!rendererFieldEdit) return void 0;
125
+ return {
126
+ safety: "unsafe",
127
+ description: "Replace simple document lookup with Renderer2 selection",
128
+ edits: [
129
+ ...buildCoreImportEdits(args.sf, args.filePath),
130
+ rendererFieldEdit,
131
+ toEdit(args.sf, args.filePath, args.call.getStart(), args.call.getEnd(), replacement)
132
+ ]
133
+ };
134
+ };
135
+ var isDirectDomAccess = (access, sf) => {
136
+ const target = access.getExpression();
137
+ if (!Node.isIdentifier(target)) return false;
138
+ const name = target.getText();
139
+ if (name !== "document" && name !== "window") return false;
140
+ const declarations = target.getSymbol()?.getDeclarations() ?? [];
141
+ for (const decl of declarations) {
142
+ if (decl.getSourceFile() === sf) return false;
143
+ }
144
+ return true;
145
+ };
146
+ var rule = {
147
+ id: "angular/no-direct-dom-access",
148
+ // v3 (Quality Roadmap A2): a local variable / parameter / field named
149
+ // `document` or `window` shadows the DOM global — no longer flagged (it is
150
+ // not global access). Fixes the shadow-identifier false positive.
151
+ version: 3,
152
+ kind: "static-ts",
153
+ title: "Avoid direct DOM access in Angular components",
154
+ description: "Direct document/window access in Angular components is not SSR-friendly and is hard to test. Prefer Renderer2, ElementRef, ViewChild, or DOCUMENT injection.",
155
+ severity: "warning",
156
+ category: "angular-best-practice",
157
+ languages: ["typescript"],
158
+ scope: "angular",
159
+ requires: "semantic-ts",
160
+ baseConfidence: 95,
161
+ check(ctx) {
162
+ const sf = asTsMorphSourceFile(ctx.parsed);
163
+ const findings = [];
164
+ for (const cls of sf.getClasses()) {
165
+ if (!hasComponentDecorator(cls)) continue;
166
+ for (const access of cls.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression)) {
167
+ if (!isDirectDomAccess(access, sf)) continue;
168
+ const call = directCallForAccess(access);
169
+ const { line, column } = sf.getLineAndColumnAtPos(access.getStart());
170
+ findings.push({
171
+ message: "Direct `document` / `window` access in Angular component. Prefer Renderer2, ElementRef/ViewChild, or DOCUMENT injection.",
172
+ file: ctx.file.path,
173
+ range: { line, column },
174
+ suggestion: "Use Renderer2/ElementRef for DOM operations, ViewChild for element refs, or inject(DOCUMENT) from @angular/common when document access is unavoidable.",
175
+ fix: buildFix({
176
+ sf,
177
+ filePath: ctx.file.path,
178
+ cls,
179
+ access,
180
+ call
181
+ })
182
+ });
183
+ }
184
+ }
185
+ return findings;
186
+ }
187
+ };
188
+
189
+ export { rule };
190
+ //# sourceMappingURL=no-direct-dom-access.rule.js.map
191
+ //# sourceMappingURL=no-direct-dom-access.rule.js.map
@@ -0,0 +1,48 @@
1
+ // builtin-rules/static/angular/no-dom-xss.rule.ts
2
+ var DOM_XSS_SINK_IDS = /* @__PURE__ */ new Set([
3
+ "angular/inner-html",
4
+ "angular/insert-adjacent-html",
5
+ "angular/bypass-security-trust"
6
+ ]);
7
+ var SINK_LABEL = {
8
+ "angular/inner-html": "innerHTML / outerHTML",
9
+ "angular/insert-adjacent-html": "insertAdjacentHTML",
10
+ "angular/bypass-security-trust": "bypassSecurityTrust*"
11
+ };
12
+ var rule = {
13
+ id: "angular/no-dom-xss",
14
+ version: 1,
15
+ kind: "static-ts",
16
+ title: "Kh\xF4ng \u0111\u01B0a d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t v\xE0o DOM (innerHTML / bypassSecurityTrust / insertAdjacentHTML)",
17
+ description: 'D\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng (location.search, document.referrer, window.name, \u2026) ch\u1EA3y v\xE0o sink DOM (innerHTML/outerHTML, insertAdjacentHTML, bypassSecurityTrust*) m\xE0 kh\xF4ng qua sanitizer l\xE0 l\u1ED7 h\u1ED5ng DOM-XSS. Rule d\xF9ng taint analysis (Tier-2 li\xEAn h\xE0m/li\xEAn file) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u, k\u1EC3 c\u1EA3 khi gi\xE1 tr\u1ECB \u0111\u01B0\u1EE3c "r\u1EEDa" qua h\xE0m trung gian. Kh\u1EAFc ph\u1EE5c: interpolation `{{ }}` / `[textContent]`, ho\u1EB7c DomSanitizer.sanitize(SecurityContext.HTML, value).',
18
+ severity: "error",
19
+ category: "security",
20
+ languages: ["typescript"],
21
+ scope: "angular",
22
+ requires: "syntactic",
23
+ usesTaint: true,
24
+ usesAstGraph: true,
25
+ baseConfidence: 80,
26
+ check(ctx) {
27
+ const findings = [];
28
+ for (const tf of ctx.taintFindings ?? []) {
29
+ if (!DOM_XSS_SINK_IDS.has(tf.sinkId)) continue;
30
+ const sources = [...new Set(tf.sourceIds)].join(", ");
31
+ const laundered = (tf.path?.length ?? 0) > 0;
32
+ const sinkLabel = SINK_LABEL[tf.sinkId] ?? tf.sinkId;
33
+ const trace = laundered ? " (truy v\u1EBFt li\xEAn h\xE0m/li\xEAn file)" : "";
34
+ findings.push({
35
+ message: `\u26A0 DOM XSS: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ch\u1EA3y v\xE0o ${sinkLabel} m\xE0 kh\xF4ng qua sanitizer \u2014 nguy c\u01A1 Cross-Site Scripting.${trace}`,
36
+ file: ctx.file.path,
37
+ range: { line: tf.line, column: tf.column ?? 1 },
38
+ confidence: laundered ? 75 : 85,
39
+ suggestion: "D\xF9ng interpolation `{{ value }}` ho\u1EB7c property binding `[textContent]`; n\u1EBFu b\u1EAFt bu\u1ED9c render HTML, sanitize qua `DomSanitizer.sanitize(SecurityContext.HTML, value)`. Tr\xE1nh g\xE1n innerHTML / g\u1ECDi bypassSecurityTrust* v\u1EDBi d\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng."
40
+ });
41
+ }
42
+ return findings;
43
+ }
44
+ };
45
+
46
+ export { rule };
47
+ //# sourceMappingURL=no-dom-xss.rule.js.map
48
+ //# sourceMappingURL=no-dom-xss.rule.js.map