@code-sentinel-cli/code-sentinel-cli 4.0.9 → 4.0.10

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 (59) hide show
  1. package/dist/bin.js +6037 -523
  2. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -0
  3. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +1 -0
  4. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +1 -0
  5. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.rule.yaml +1 -0
  6. package/dist/builtin-rules/fortify/ai/angular/cross-feature-route-permission-drift.rule.yaml +2 -0
  7. package/dist/builtin-rules/fortify/ai/angular/route-permission-flow.rule.yaml +2 -0
  8. package/dist/builtin-rules/fortify/ai/spring-boot/io-boundary-risk.rule.yaml +1 -0
  9. package/dist/builtin-rules/fortify/ai/spring-boot/security-redirect-risk.rule.yaml +2 -0
  10. package/dist/builtin-rules/fortify/ai/spring-boot/security-sensitive-data-risk.rule.yaml +2 -0
  11. package/dist/builtin-rules/fortify/static/angular/sensitive-input-masking.rule.js +1 -0
  12. package/dist/builtin-rules/fortify/static/general/java-weak-randomness.rule.js +2 -0
  13. package/dist/builtin-rules/fortify/static/general/no-client-identity-header.rule.js +1 -0
  14. package/dist/builtin-rules/fortify/static/general/no-guessable-websql-database-name.rule.js +1 -0
  15. package/dist/builtin-rules/fortify/static/general/no-reflective-access-override.rule.js +1 -0
  16. package/dist/builtin-rules/fortify/static/general/no-sensitive-string-materialization.rule.js +1 -0
  17. package/dist/builtin-rules/fortify/static/spring-boot/no-command-injection.rule.js +2 -0
  18. package/dist/builtin-rules/fortify/static/spring-boot/no-path-traversal.rule.js +8 -1
  19. package/dist/builtin-rules/fortify/static/spring-boot/no-servlet-xss.rule.js +2 -0
  20. package/dist/builtin-rules/fortify/static/spring-boot/no-spel-injection.rule.js +2 -0
  21. package/dist/builtin-rules/fortify/static/spring-boot/no-sql-string-concat.rule.js +2 -0
  22. package/dist/builtin-rules/fortify/static/spring-boot/no-ssrf.rule.js +2 -0
  23. package/dist/builtin-rules/fortify/static/spring-boot/no-trust-boundary-violation.rule.js +43 -0
  24. package/dist/builtin-rules/fortify/static/spring-boot/no-weak-tls-protocol.rule.js +2 -0
  25. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +1 -0
  26. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +1 -0
  27. package/dist/builtin-rules/static/flutter/INVENTORY.md +44 -0
  28. package/dist/builtin-rules/static/flutter/NATIVE-INVENTORY.md +34 -0
  29. package/dist/builtin-rules/static/flutter/android-cleartext-traffic.rule.js +104 -0
  30. package/dist/builtin-rules/static/flutter/android-release-debuggable.rule.js +85 -0
  31. package/dist/builtin-rules/static/flutter/bad-certificate-callback.rule.js +80 -0
  32. package/dist/builtin-rules/static/flutter/biometric-without-crypto-object.rule.js +86 -0
  33. package/dist/builtin-rules/static/flutter/cleartext-http-endpoint.rule.js +76 -0
  34. package/dist/builtin-rules/static/flutter/device-fingerprint-collection.rule.js +73 -0
  35. package/dist/builtin-rules/static/flutter/exported-content-provider-leak.rule.js +118 -0
  36. package/dist/builtin-rules/static/flutter/hardcoded-crypto-key.rule.js +124 -0
  37. package/dist/builtin-rules/static/flutter/hardcoded-oauth-client-secret.rule.js +107 -0
  38. package/dist/builtin-rules/static/flutter/insecure-deep-link.rule.js +153 -0
  39. package/dist/builtin-rules/static/flutter/ios-ats-exception.rule.js +82 -0
  40. package/dist/builtin-rules/static/flutter/ios-pasteboard-leak.rule.js +95 -0
  41. package/dist/builtin-rules/static/flutter/missing-enforced-update.rule.js +80 -0
  42. package/dist/builtin-rules/static/flutter/oauth-missing-pkce.rule.js +74 -0
  43. package/dist/builtin-rules/static/flutter/token-insecure-storage.rule.js +120 -0
  44. package/dist/builtin-rules/static/flutter/tracking-sdk-init.rule.js +75 -0
  45. package/dist/builtin-rules/static/flutter/weak-mobile-crypto-algorithm.rule.js +113 -0
  46. package/dist/builtin-rules/static/flutter/weak-prng-mobile.rule.js +103 -0
  47. package/dist/builtin-rules/static/general/kubernetes-pod-security.rule.js +1 -0
  48. package/dist/builtin-rules/static/general/no-dynamic-code-eval.rule.js +1 -0
  49. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +61 -5
  50. package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +1 -0
  51. package/dist/builtin-rules/static/general/no-unused-export.rule.js +1 -0
  52. package/dist/builtin-rules/static/general/openapi-https-credentials.rule.js +1 -0
  53. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +1 -0
  54. package/dist/builtin-rules/static/spring-boot/no-unzoned-datetime.rule.js +1 -0
  55. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +1 -0
  56. package/dist/index.d.ts +467 -0
  57. package/dist/index.js +6036 -522
  58. package/node_modules/@code-sentinel/parsers/index.js +53 -4
  59. package/package.json +1 -1
@@ -0,0 +1,153 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var attrValue = (xml, attr) => {
24
+ const escaped = attr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
+ return new RegExp(`${escaped}\\s*=\\s*["']([^"']+)["']`).exec(xml)?.[1] ?? null;
26
+ };
27
+ var isPath = (file, suffix) => file.path.replace(/\\/g, "/").toLowerCase().endsWith(suffix.toLowerCase());
28
+
29
+ // builtin-rules/static/flutter/insecure-deep-link.rule.ts
30
+ var isDebugOrTestPath = (path) => {
31
+ const normalized = path.replace(/\\/g, "/").toLowerCase();
32
+ return normalized.includes("/debug/") || normalized.includes("/test/");
33
+ };
34
+ var isLauncherOnly = (block) => /android\.intent\.action\.MAIN/.test(block) && /android\.intent\.category\.LAUNCHER/.test(block);
35
+ var intentFilterBlocks = (content) => {
36
+ const out = [];
37
+ const openRe = /<intent-filter\b[^>]*>/gi;
38
+ for (const open of content.matchAll(openRe)) {
39
+ const startTag = open[0];
40
+ const startIndex = open.index ?? 0;
41
+ if (startTag.endsWith("/>")) {
42
+ out.push({ block: startTag, index: startIndex });
43
+ continue;
44
+ }
45
+ const close = "</intent-filter>";
46
+ const closeIndex = content.indexOf(close, startIndex + startTag.length);
47
+ out.push(
48
+ closeIndex >= 0 ? { block: content.slice(startIndex, closeIndex + close.length), index: startIndex } : { block: content.slice(startIndex), index: startIndex }
49
+ );
50
+ }
51
+ return out;
52
+ };
53
+ var schemesInBlock = (block) => {
54
+ const schemes = [];
55
+ for (const data of block.matchAll(/<data\b[^>]*>/gi)) {
56
+ const scheme = attrValue(data[0], "android:scheme");
57
+ if (scheme) schemes.push(scheme);
58
+ }
59
+ return schemes;
60
+ };
61
+ function firstPlistKeyIndex(content, key) {
62
+ const match = new RegExp(`<key>\\s*${key}\\s*</key>`, "i").exec(content);
63
+ return match?.index ?? 0;
64
+ }
65
+ var rule = {
66
+ id: "flutter/insecure-deep-link",
67
+ version: 1,
68
+ kind: "static-ts",
69
+ title: "Deep link / App Link ph\u1EA3i c\xF3 autoVerify ho\u1EB7c h\u1EA1 r\u1EE7i ro wildcard scheme",
70
+ description: 'Ph\xE1t hi\u1EC7n intent-filter Android khai b\xE1o scheme (deep link) nh\u01B0ng thi\u1EBFu `android:autoVerify="true"` (kh\xF4ng ph\u1EA3i App Link \u0111\xE3 x\xE1c minh), scheme wildcard m\u1EDF qu\xE1 r\u1ED9ng, ho\u1EB7c iOS custom URL scheme thi\u1EBFu Associated Domains (universal links).',
71
+ severity: "warning",
72
+ category: "mobile-security",
73
+ languages: ["xml", "plist"],
74
+ scope: "flutter",
75
+ requires: "text",
76
+ baseConfidence: 83,
77
+ check(ctx) {
78
+ const file = ctx.file;
79
+ if (isDebugOrTestPath(file.path)) return [];
80
+ const out = [];
81
+ if (isPath(file, "androidmanifest.xml")) {
82
+ const content = file.content;
83
+ for (const { block, index } of intentFilterBlocks(content)) {
84
+ const schemes = schemesInBlock(block);
85
+ if (schemes.length === 0) continue;
86
+ if (isLauncherOnly(block)) continue;
87
+ const hasAutoVerify = attrValue(block, "android:autoVerify") === "true";
88
+ if (schemes.some((scheme) => scheme.includes("*"))) {
89
+ out.push(
90
+ finding(
91
+ file,
92
+ index,
93
+ `Intent-filter khai b\xE1o scheme wildcard (\`${schemes.find((s) => s.includes("*")) ?? "*"}\`) \u2192 ch\u1EA5p nh\u1EADn deep link t\u1EEB scheme b\u1EA5t k\u1EF3, r\u1EE7i ro hijack route.`,
94
+ '\u0110\u1EB7c t\u1EA3 scheme c\u1ED1 \u0111\u1ECBnh (kh\xF4ng d\xF9ng `*`) v\xE0 \xE1p d\u1EE5ng `android:autoVerify="true"` cho App Links \u0111\xE3 x\xE1c minh (ATTT #100).',
95
+ {
96
+ severity: "warning",
97
+ confidence: 82,
98
+ rootCauseKey: "insecure-deep-link-wildcard",
99
+ snippet: block.split(/\r?\n/)[0]?.trim(),
100
+ tags: ["deep-link", "platform-security"]
101
+ }
102
+ )
103
+ );
104
+ continue;
105
+ }
106
+ if (!hasAutoVerify) {
107
+ out.push(
108
+ finding(
109
+ file,
110
+ index,
111
+ `Intent-filter khai b\xE1o scheme \`${schemes.join("`, `")}\` nh\u01B0ng thi\u1EBFu \`android:autoVerify="true"\` \u2014 deep link ch\u01B0a x\xE1c minh ch\u1EE7 s\u1EDF h\u1EEFu, d\u1EC5 b\u1ECB app kh\xE1c \u0111\u0103ng k\xFD tr\xF9ng scheme (hijack).`,
112
+ 'Th\xEAm `android:autoVerify="true"` + `.well-known/assetlinks.json` cho App Links, ho\u1EB7c gi\u1EDBi h\u1EA1n scheme/intent v\xE0 ki\u1EC3m tra d\u1EEF li\u1EC7u \u0111\u1EA7u v\xE0o t\u1EEB deep link (ATTT #100).',
113
+ {
114
+ severity: "error",
115
+ confidence: 86,
116
+ rootCauseKey: "insecure-deep-link-no-autoverify",
117
+ snippet: block.split(/\r?\n/)[0]?.trim(),
118
+ tags: ["deep-link", "platform-security"]
119
+ }
120
+ )
121
+ );
122
+ }
123
+ }
124
+ return out;
125
+ }
126
+ if (isPath(file, "info.plist")) {
127
+ const content = file.content;
128
+ const hasCustomScheme = /CFBundleURLTypes|CFBundleURLSchemes/i.test(content);
129
+ if (!hasCustomScheme) return out;
130
+ const hasUniversalLinksHint = /applinks:/i.test(content);
131
+ out.push(
132
+ finding(
133
+ file,
134
+ firstPlistKeyIndex(content, "CFBundleURLTypes"),
135
+ "Info.plist khai b\xE1o custom URL scheme (`CFBundleURLTypes`) \u2014 scheme n\xE0y kh\xF4ng x\xE1c minh ch\u1EE7 s\u1EDF h\u1EEFu, app kh\xE1c c\xF3 th\u1EC3 \u0111\u0103ng k\xFD tr\xF9ng (hijack).",
136
+ "\u01AFu ti\xEAn Universal Links: th\xEAm entitlement `com.apple.developer.associated-domains` v\u1EDBi `applinks:<host>` + host ph\u1EE5c v\u1EE5 `apple-app-site-association`. N\u1EBFu gi\u1EEF custom scheme, validate tuy\u1EC7t \u0111\u1ED1i d\u1EEF li\u1EC7u \u0111\u1EA7u v\xE0o (ATTT #100).",
137
+ {
138
+ severity: "warning",
139
+ confidence: hasUniversalLinksHint ? 72 : 80,
140
+ rootCauseKey: "insecure-deep-link-ios-custom-scheme",
141
+ tags: ["deep-link", "platform-security"]
142
+ }
143
+ )
144
+ );
145
+ return out;
146
+ }
147
+ return out;
148
+ }
149
+ };
150
+
151
+ export { rule };
152
+ //# sourceMappingURL=insecure-deep-link.rule.js.map
153
+ //# sourceMappingURL=insecure-deep-link.rule.js.map
@@ -0,0 +1,82 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+ var isPath = (file, suffix) => file.path.replace(/\\/g, "/").toLowerCase().endsWith(suffix.toLowerCase());
29
+
30
+ // builtin-rules/static/flutter/ios-ats-exception.rule.ts
31
+ var KEY_TRUE = (key) => new RegExp(`<key>\\s*${key}\\s*</key>\\s*<true\\s*/>`, "i");
32
+ var ARBITRARY_LOADS_TRUE = KEY_TRUE("NSAllowsArbitraryLoads");
33
+ var LOCAL_NETWORKING_TRUE = KEY_TRUE("NSAllowsLocalNetworking");
34
+ var isDebugOrTestPath = (path) => {
35
+ const normalized = path.replace(/\\/g, "/").toLowerCase();
36
+ return normalized.includes("/debug/") || normalized.includes("/test/");
37
+ };
38
+ var rule = {
39
+ id: "ios/ats-exception",
40
+ version: 1,
41
+ kind: "static-ts",
42
+ title: "iOS ATS t\u1EAFt h\xE0ng lo\u1EA1t qua NSAllowsArbitraryLoads",
43
+ description: "Ph\xE1t hi\u1EC7n dictionary `NSAppTransportSecurity` b\u1EADt `NSAllowsArbitraryLoads=true` trong Info.plist; gi\u1EA3m confidence khi \u0111i k\xE8m `NSAllowsLocalNetworking`/`NSExceptionDomains` (ph\u1EA1m vi h\u1EB9p h\u01A1n).",
44
+ severity: "warning",
45
+ category: "mobile-security",
46
+ languages: ["plist"],
47
+ scope: "flutter",
48
+ requires: "text",
49
+ baseConfidence: 90,
50
+ check(ctx) {
51
+ const file = ctx.file;
52
+ const out = [];
53
+ if (!isPath(file, "info.plist")) return out;
54
+ if (isDebugOrTestPath(file.path.replace(/\\/g, "/"))) return out;
55
+ const content = file.content;
56
+ const atsIndex = firstIndex(content, /<key>\s*NSAppTransportSecurity\s*<\/key>/i);
57
+ if (atsIndex < 0) return out;
58
+ const arbitraryIndex = firstIndex(content, ARBITRARY_LOADS_TRUE);
59
+ if (arbitraryIndex < 0) return out;
60
+ const hasLocalNetworking = LOCAL_NETWORKING_TRUE.test(content);
61
+ const hasExceptionDomains = /<key>\s*NSExceptionDomains\s*<\/key>/i.test(content);
62
+ const narrowed = hasLocalNetworking || hasExceptionDomains;
63
+ out.push(
64
+ finding(
65
+ file,
66
+ arbitraryIndex,
67
+ narrowed ? "ATS b\u1EADt `NSAllowsArbitraryLoads=true` d\xF9 \u0111\xE3 c\xF3 `NSExceptionDomains`/`NSAllowsLocalNetworking` thu h\u1EB9p ph\u1EA1m vi." : "ATS b\u1EADt `NSAllowsArbitraryLoads=true`, t\u1EAFt m\u1EB7c \u0111\u1ECBnh an to\xE0n cho to\xE0n \u1EE9ng d\u1EE5ng.",
68
+ narrowed ? "G\u1EE1 `NSAllowsArbitraryLoads`; gi\u1EEF `NSExceptionDomains` cho domain c\u1EA7n HTTP v\xE0 `NSAllowsLocalNetworking` cho n\u1ED9i b\u1ED9." : "G\u1EE1 `NSAllowsArbitraryLoads` v\xE0 ch\u1EC9 exception theo domain qua `NSExceptionDomains` khi th\u1EADt s\u1EF1 c\u1EA7n HTTP.",
69
+ {
70
+ severity: "warning",
71
+ confidence: narrowed ? 75 : 90,
72
+ rootCauseKey: "ats-arbitrary-loads"
73
+ }
74
+ )
75
+ );
76
+ return out;
77
+ }
78
+ };
79
+
80
+ export { rule };
81
+ //# sourceMappingURL=ios-ats-exception.rule.js.map
82
+ //# sourceMappingURL=ios-ats-exception.rule.js.map
@@ -0,0 +1,95 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+
24
+ // builtin-rules/static/flutter/ios-pasteboard-leak.rule.ts
25
+ var PASTEBOARD_SINK = /UIPasteboard\s*\.\s*general\s*\.\s*string\s*=|UIPasteboard\s*\.\s*general\s*\.\s*setValue\s*\(|UIPasteboard\s*\.\s*general\s*\.\s*setObjects\s*\(|\[\s*UIPasteboard\s*\.\s*general\s+(?:setValue\s*:[\s\S]*?forKey\s*:\s*@"string"|setObjects\s*:)/;
26
+ var SENSITIVE_VALUE = /\b\w*(?:token|password|passwd|secret|jwt|authToken|accessToken|refreshToken|apiKey|api_key)\w*\b/i;
27
+ var PUBLIC_COMMENT_RE = /\/\/\s*public|\/\*\s*public/i;
28
+ var PUBLIC_PAYLOAD_VALUE_RE = /\b(?:public_?share_?link|public_?link|share_?url|invite_?code)\b/i;
29
+ var directAssignedIdentifier = (line) => {
30
+ const assign = /\.string\s*=\s*([A-Za-z_]\w*)/.exec(line);
31
+ if (assign?.[1]) return assign[1];
32
+ const sinkAt = Math.max(0, line.indexOf("UIPasteboard"));
33
+ const setter = /\.\s*(?:setValue|setObjects)\s*\(\s*([A-Za-z_]\w*)\s*[,]?\s*\)|setValue\s*:\s*([A-Za-z_]\w*)/.exec(
34
+ line.slice(sinkAt)
35
+ );
36
+ if (setter) return setter[1] ?? setter[2] ?? null;
37
+ return null;
38
+ };
39
+ var WINDOW = 3;
40
+ var rule = {
41
+ id: "ios/pasteboard-leak",
42
+ version: 1,
43
+ kind: "static-ts",
44
+ title: "iOS pasteboard ghi gi\xE1 tr\u1ECB c\xF3 th\u1EC3 nh\u1EA1y c\u1EA3m",
45
+ description: "Ph\xE1t hi\u1EC7n `UIPasteboard.general` ghi string/objects m\xE0 gi\xE1 tr\u1ECB c\xF3 d\u1EA5u hi\u1EC7u nh\u1EA1y c\u1EA3m (token/password/secret/jwt); b\u1ECF qua intent chia s\u1EBB c\xF4ng khai v\xE0 thao t\xE1c ch\u1EC9 \u0111\u1ECDc.",
46
+ severity: "warning",
47
+ category: "mobile-security",
48
+ languages: ["swift", "objective-c"],
49
+ scope: "flutter",
50
+ requires: "text",
51
+ baseConfidence: 80,
52
+ check(ctx) {
53
+ const file = ctx.file;
54
+ const content = file.content;
55
+ const out = [];
56
+ const lines = content.split(/\r?\n/);
57
+ let offset = 0;
58
+ for (let i = 0; i < lines.length; i += 1) {
59
+ const line = lines[i] ?? "";
60
+ if (PASTEBOARD_SINK.test(line)) {
61
+ const from = Math.max(0, i - WINDOW);
62
+ const to = Math.min(lines.length - 1, i + WINDOW);
63
+ const windowText = lines.slice(from, to + 1).join("\n");
64
+ if (SENSITIVE_VALUE.test(windowText)) {
65
+ const hasPublicComment = PUBLIC_COMMENT_RE.test(windowText);
66
+ const directValue = directAssignedIdentifier(line);
67
+ const isPublicPayload = directValue !== null && PUBLIC_PAYLOAD_VALUE_RE.test(directValue);
68
+ const isPublicIntent = hasPublicComment || isPublicPayload;
69
+ if (!isPublicIntent) {
70
+ out.push(
71
+ finding(
72
+ file,
73
+ offset,
74
+ "Ghi gi\xE1 tr\u1ECB c\xF3 th\u1EC3 nh\u1EA1y c\u1EA3m l\xEAn system pasteboard (`UIPasteboard.general`).",
75
+ "Tr\xE1nh ghi token/secret l\xEAn system pasteboard; n\u1EBFu c\u1EA7n chia s\u1EBB, d\xF9ng share sheet, ho\u1EB7c \u0111\u1EB7t th\u1EDDi \u0111i\u1EC3m h\u1EBFt h\u1EA1n v\xE0 xo\xE1 n\u1ED9i dung sau khi d\xF9ng.",
76
+ {
77
+ severity: "warning",
78
+ confidence: 80,
79
+ snippet: line.trim(),
80
+ rootCauseKey: "pasteboard-sensitive-set"
81
+ }
82
+ )
83
+ );
84
+ }
85
+ }
86
+ }
87
+ offset += line.length + 1;
88
+ }
89
+ return out;
90
+ }
91
+ };
92
+
93
+ export { rule };
94
+ //# sourceMappingURL=ios-pasteboard-leak.rule.js.map
95
+ //# sourceMappingURL=ios-pasteboard-leak.rule.js.map
@@ -0,0 +1,80 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+
24
+ // builtin-rules/static/flutter/missing-enforced-update.rule.ts
25
+ var UPDATE_REF_RE = /\bInAppUpdate\b|\bAppUpdateManager\b|\bAppUpdateManagerImpl\b|\bupdateAvailability\b|com\.google\.android\.play\.core\.appupdate/i;
26
+ var HANDLED_RE = /\bappUpdateType\b|\bIMMEDIATE\b|\bFLEXIBLE\b|\bAppUpdateResult\b|\bAppUpdateType\b|\bgetResult\s*\(\s*\)|\bcompleteUpdate\b|\bresumeUpdate\b/i;
27
+ var NAMING_ONLY_RE = /\b(?:findbugs|spotbugs|lint|example)\b/i;
28
+ var WINDOW = 8;
29
+ var rule = {
30
+ id: "flutter/missing-enforced-update",
31
+ version: 1,
32
+ kind: "static-ts",
33
+ title: "Kh\xF4ng b\u1ECF l\u1EEDng k\u1EBFt qu\u1EA3 In-App Update (MASVS-CODE-2)",
34
+ description: "Ph\xE1t hi\u1EC7n `InAppUpdate`/`AppUpdateManager`/`updateAvailability` m\xE0 c\u1EEDa s\u1ED5 xung quanh KH\xD4NG c\xF3 `appUpdateType`/`IMMEDIATE`/`FLEXIBLE`/`AppUpdateResult` \u2014 app ch\u1EC9 \u0111\u1ECDc tr\u1EA1ng th\xE1i c\xF3 update r\u1ED3i \u0111\u1EC3 user ti\u1EBFp t\u1EE5c ch\u1EA1y b\u1EA3n c\u0169, kh\xF4ng enforce.",
35
+ severity: "warning",
36
+ category: "mobile-security",
37
+ languages: ["kotlin", "java", "swift"],
38
+ scope: "flutter",
39
+ requires: "text",
40
+ baseConfidence: 65,
41
+ check(ctx) {
42
+ const lines = ctx.file.content.split(/\r?\n/);
43
+ const out = [];
44
+ let offset = 0;
45
+ for (let i = 0; i < lines.length; i += 1) {
46
+ const line = lines[i] ?? "";
47
+ if (!UPDATE_REF_RE.test(line) || NAMING_ONLY_RE.test(line)) {
48
+ offset += line.length + 1;
49
+ continue;
50
+ }
51
+ const from = Math.max(0, i - WINDOW);
52
+ const to = Math.min(lines.length - 1, i + WINDOW);
53
+ const windowText = lines.slice(from, to + 1).join("\n");
54
+ if (HANDLED_RE.test(windowText)) {
55
+ offset += line.length + 1;
56
+ continue;
57
+ }
58
+ out.push(
59
+ finding(
60
+ ctx.file,
61
+ offset,
62
+ "Tham chi\u1EBFu In-App Update nh\u01B0ng c\u1EEDa s\u1ED5 xung quanh kh\xF4ng th\u1EA5y `appUpdateType`/`IMMEDIATE`/`FLEXIBLE`/`AppUpdateResult` \u2014 k\u1EBFt qu\u1EA3 update c\xF3 th\u1EC3 b\u1ECB b\u1ECF l\u1EEDng.",
63
+ "Khi `updateAvailability == UPDATE_AVAILABLE`, g\u1ECDi `appUpdateManager.startUpdateFlowForResult(...)` v\u1EDBi `AppUpdateType.IMMEDIATE` (ch\u1EB7n b\u1EA3n c\u0169 khi l\u1ED7 h\u1ED5ng nghi\xEAm tr\u1ECDng) ho\u1EB7c `FLEXIBLE` k\xE8m theo `AppUpdateResult`/listener \u0111\u1EC3 log/\u0103n ch\u1EB7n k\u1EBFt qu\u1EA3; kh\xF4ng ch\u1EC9 \u0111\u1ECDc tr\u1EA1ng th\xE1i r\u1ED3i ti\u1EBFp t\u1EE5c ch\u1EA1y b\u1EA3n c\u0169.",
64
+ {
65
+ snippet: line.trim(),
66
+ confidence: 65,
67
+ rootCauseKey: "missing-enforced-update-handling",
68
+ tags: ["build", "update-enforcement", "resilience"]
69
+ }
70
+ )
71
+ );
72
+ offset += line.length + 1;
73
+ }
74
+ return out;
75
+ }
76
+ };
77
+
78
+ export { rule };
79
+ //# sourceMappingURL=missing-enforced-update.rule.js.map
80
+ //# sourceMappingURL=missing-enforced-update.rule.js.map
@@ -0,0 +1,74 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+
24
+ // builtin-rules/static/flutter/oauth-missing-pkce.rule.ts
25
+ var OAUTH_REQUEST_RE = /(AuthorizationTokenRequest|AuthorizationRequest|OIDAuthorizationRequest|AuthorizationService\.|AppAuth|flutter_appauth)/;
26
+ var PKCE_PRESENT_RE = /(codeChallenge|code_challenge|codeVerifier|code_verifier|PkceS256|PkcePlain|pkceMethod|PKCE)/i;
27
+ var rule = {
28
+ id: "flutter/oauth-missing-pkce",
29
+ version: 1,
30
+ kind: "static-ts",
31
+ title: "OAuth/OIDC tr\xEAn mobile public client c\u1EA7n PKCE",
32
+ description: "M\u1ED9t authorization request qua AppAuth/flutter_appauth/OIDAuthorizationRequest m\xE0 kh\xF4ng khai codeChallenge/codeVerifier (PKCE) cho ph\xE9p k\u1EBB t\u1EA5n c\xF4ng \u0111\xE1nh c\u1EAFp authorization code qua custom-scheme redirect.",
33
+ severity: "warning",
34
+ category: "mobile-security",
35
+ languages: ["dart", "kotlin", "swift", "java"],
36
+ scope: "flutter",
37
+ requires: "text",
38
+ baseConfidence: 75,
39
+ check(ctx) {
40
+ const content = ctx.file.content;
41
+ if (!OAUTH_REQUEST_RE.test(content)) return [];
42
+ if (PKCE_PRESENT_RE.test(content)) return [];
43
+ const lines = content.split(/\r?\n/);
44
+ const out = [];
45
+ let offset = 0;
46
+ for (let i = 0; i < lines.length; i += 1) {
47
+ const line = lines[i] ?? "";
48
+ const oauthCall = /(AuthorizationTokenRequest|AuthorizationRequest|OIDAuthorizationRequest)\s*\(/.test(
49
+ line
50
+ ) || /AuthorizationService\.\w*Token/.test(line);
51
+ if (oauthCall) {
52
+ out.push(
53
+ finding(
54
+ ctx.file,
55
+ offset,
56
+ "Mobile OAuth/OIDC request kh\xF4ng c\xF3 PKCE (codeChallenge/codeVerifier).",
57
+ "Th\xEAm PKCE: Flutter AppAuth `codeChallenge`/`codeVerifier`; AppAuth Android/iOS thi\u1EBFt l\u1EADp `setCodeVerifier`/`additionalParameters` PKCE S256; kh\xF4ng bao gi\u1EDD thay PKCE b\u1EB1ng client_secret nh\xFAng trong app.",
58
+ {
59
+ snippet: line.trim(),
60
+ rootCauseKey: "oauth-pkce-missing",
61
+ tags: ["authentication", "oauth", "pkce"]
62
+ }
63
+ )
64
+ );
65
+ }
66
+ offset += line.length + 1;
67
+ }
68
+ return out;
69
+ }
70
+ };
71
+
72
+ export { rule };
73
+ //# sourceMappingURL=oauth-missing-pkce.rule.js.map
74
+ //# sourceMappingURL=oauth-missing-pkce.rule.js.map
@@ -0,0 +1,120 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+
24
+ // builtin-rules/static/flutter/token-insecure-storage.rule.ts
25
+ var SETTER_RE = /\b(?:setString|setInt|setBool|setDouble|setStringList|writeAsString(?:Sync|Lines)?|writeAsBytes(?:Sync)?|setData)\b|Clipboard\.setData/;
26
+ var SENSITIVE_WORDS = /* @__PURE__ */ new Set([
27
+ "token",
28
+ "tokens",
29
+ "password",
30
+ "passwords",
31
+ "passwd",
32
+ "secret",
33
+ "secrets",
34
+ "credential",
35
+ "credentials",
36
+ "jwt"
37
+ ]);
38
+ var SENSITIVE_COMPOUNDS = /* @__PURE__ */ new Set([
39
+ "apikey",
40
+ "apisecret",
41
+ "authkey",
42
+ "secretkey",
43
+ "clientsecret",
44
+ "signingsecret",
45
+ "refreshtoken",
46
+ "accesstoken",
47
+ "authtoken",
48
+ "idtoken"
49
+ ]);
50
+ var SENSITIVE_SUFFIXES = ["token", "password", "passwd", "secret", "credential"];
51
+ var SECURE_SINK_RE = /FlutterSecureStorage|flutter_secure_storage|EncryptedSharedPreferences|Keychain|Keystore|SecureStorage/;
52
+ var NON_SENSITIVE_NAME_RE = /\b(?:public|device|locale|theme|lang)[\w$]*\b/i;
53
+ var splitIdentifierWords = (identifier) => identifier.replace(/[$_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/ +/).filter((word) => word.length > 0);
54
+ var isSensitiveIdentifier = (identifier) => {
55
+ if (NON_SENSITIVE_NAME_RE.test(identifier)) return false;
56
+ const words = splitIdentifierWords(identifier).map((word) => word.toLowerCase());
57
+ if (words.some((word) => SENSITIVE_WORDS.has(word))) return true;
58
+ if (words.some((word) => SENSITIVE_SUFFIXES.some((suffix) => word.endsWith(suffix)))) {
59
+ return true;
60
+ }
61
+ return words.some((_, i) => {
62
+ const next = words[i + 1];
63
+ return next !== void 0 && SENSITIVE_COMPOUNDS.has(words[i] + next);
64
+ });
65
+ };
66
+ var firstSensitiveIdentifier = (text) => {
67
+ for (const match of text.matchAll(/[$\w]{2,}/g)) {
68
+ const identifier = match[0];
69
+ if (identifier && isSensitiveIdentifier(identifier)) return identifier;
70
+ }
71
+ return null;
72
+ };
73
+ var rule = {
74
+ id: "flutter/token-insecure-storage",
75
+ version: 1,
76
+ kind: "static-ts",
77
+ title: "Token/m\u1EADt kh\u1EA9u ph\u1EA3i l\u01B0u trong secure storage, kh\xF4ng ph\u1EA3i SharedPreferences/file/clipboard",
78
+ description: "Ph\xE1t hi\u1EC7n token/password/secret/credential ghi v\xE0o SharedPreferences, file storage ho\u1EB7c clipboard thay v\xEC flutter_secure_storage (Keychain/Keystore).",
79
+ severity: "error",
80
+ category: "mobile-security",
81
+ languages: ["dart"],
82
+ scope: "flutter",
83
+ requires: "text",
84
+ baseConfidence: 85,
85
+ check(ctx) {
86
+ const lines = ctx.file.content.split(/\r?\n/);
87
+ const out = [];
88
+ let offset = 0;
89
+ for (let i = 0; i < lines.length; i += 1) {
90
+ const line = lines[i] ?? "";
91
+ const hasSetter = SETTER_RE.test(line);
92
+ const hasSecureSink = SECURE_SINK_RE.test(line);
93
+ if (hasSetter && !hasSecureSink) {
94
+ const windowText = lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 4)).join("\n");
95
+ const sensitiveName = firstSensitiveIdentifier(line) ?? firstSensitiveIdentifier(windowText);
96
+ if (sensitiveName) {
97
+ out.push(
98
+ finding(
99
+ ctx.file,
100
+ offset,
101
+ `D\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m \`${sensitiveName}\` c\xF3 th\u1EC3 \u0111\u01B0\u1EE3c ghi v\xE0o storage kh\xF4ng m\xE3 h\xF3a (SharedPreferences/file/clipboard).`,
102
+ "Kh\xF4ng l\u01B0u token/password/secret/credential trong SharedPreferences, file plaintext ho\u1EB7c clipboard; d\xF9ng flutter_secure_storage (iOS Keychain / Android Keystore) ho\u1EB7c encrypted storage (ATTT #26, #51, #86).",
103
+ {
104
+ snippet: line.trim(),
105
+ rootCauseKey: "sensitive-token-insecure-storage",
106
+ tags: ["storage", "sensitive-data"]
107
+ }
108
+ )
109
+ );
110
+ }
111
+ }
112
+ offset += line.length + 1;
113
+ }
114
+ return out;
115
+ }
116
+ };
117
+
118
+ export { rule };
119
+ //# sourceMappingURL=token-insecure-storage.rule.js.map
120
+ //# sourceMappingURL=token-insecure-storage.rule.js.map