@code-sentinel-cli/code-sentinel-cli 4.0.9 → 4.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +7204 -914
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +1 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +1 -0
- package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.rule.yaml +1 -0
- package/dist/builtin-rules/fortify/ai/angular/cross-feature-route-permission-drift.rule.yaml +2 -0
- package/dist/builtin-rules/fortify/ai/angular/route-permission-flow.rule.yaml +2 -0
- package/dist/builtin-rules/fortify/ai/spring-boot/io-boundary-risk.rule.yaml +1 -0
- package/dist/builtin-rules/fortify/ai/spring-boot/security-redirect-risk.rule.yaml +2 -0
- package/dist/builtin-rules/fortify/ai/spring-boot/security-sensitive-data-risk.rule.yaml +2 -0
- package/dist/builtin-rules/fortify/static/angular/sensitive-input-masking.rule.js +1 -0
- package/dist/builtin-rules/fortify/static/general/java-weak-randomness.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/general/no-client-identity-header.rule.js +1 -0
- package/dist/builtin-rules/fortify/static/general/no-guessable-websql-database-name.rule.js +1 -0
- package/dist/builtin-rules/fortify/static/general/no-reflective-access-override.rule.js +1 -0
- package/dist/builtin-rules/fortify/static/general/no-sensitive-string-materialization.rule.js +1 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-command-injection.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-path-traversal.rule.js +8 -1
- package/dist/builtin-rules/fortify/static/spring-boot/no-servlet-xss.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-spel-injection.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-sql-string-concat.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-ssrf.rule.js +2 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-trust-boundary-violation.rule.js +43 -0
- package/dist/builtin-rules/fortify/static/spring-boot/no-weak-tls-protocol.rule.js +2 -0
- package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +1 -0
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/INVENTORY.md +44 -0
- package/dist/builtin-rules/static/flutter/NATIVE-INVENTORY.md +34 -0
- package/dist/builtin-rules/static/flutter/android-cleartext-traffic.rule.js +105 -0
- package/dist/builtin-rules/static/flutter/android-debug-certificate-risk.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/android-minsdk-low.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/android-release-debuggable.rule.js +86 -0
- package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/bad-certificate-callback.rule.js +81 -0
- package/dist/builtin-rules/static/flutter/biometric-without-crypto-object.rule.js +87 -0
- package/dist/builtin-rules/static/flutter/cleartext-http-endpoint.rule.js +77 -0
- package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +12 -3
- package/dist/builtin-rules/static/flutter/device-fingerprint-collection.rule.js +74 -0
- package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/exported-content-provider-leak.rule.js +119 -0
- package/dist/builtin-rules/static/flutter/hardcoded-crypto-key.rule.js +125 -0
- package/dist/builtin-rules/static/flutter/hardcoded-oauth-client-secret.rule.js +108 -0
- package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/insecure-deep-link.rule.js +154 -0
- package/dist/builtin-rules/static/flutter/ios-ats-exception.rule.js +83 -0
- package/dist/builtin-rules/static/flutter/ios-pasteboard-leak.rule.js +96 -0
- package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/missing-enforced-update.rule.js +81 -0
- package/dist/builtin-rules/static/flutter/oauth-missing-pkce.rule.js +75 -0
- package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +1 -0
- package/dist/builtin-rules/static/flutter/token-insecure-storage.rule.js +121 -0
- package/dist/builtin-rules/static/flutter/tracking-sdk-init.rule.js +76 -0
- package/dist/builtin-rules/static/flutter/weak-mobile-crypto-algorithm.rule.js +114 -0
- package/dist/builtin-rules/static/flutter/weak-prng-mobile.rule.js +104 -0
- package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +1 -0
- package/dist/builtin-rules/static/general/dockerfile-dependency-confusion.rule.js +5 -4
- package/dist/builtin-rules/static/general/dockerfile-no-root-user.rule.js +1 -0
- package/dist/builtin-rules/static/general/kubernetes-pod-security.rule.js +1 -0
- package/dist/builtin-rules/static/general/no-dynamic-code-eval.rule.js +1 -0
- package/dist/builtin-rules/static/general/no-empty-encryption-key.rule.js +16 -1
- package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +72 -9
- package/dist/builtin-rules/static/general/no-insecure-external-link.rule.js +1 -0
- package/dist/builtin-rules/static/general/no-insecure-password-submission.rule.js +34 -2
- package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +1 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +1 -0
- package/dist/builtin-rules/static/general/openapi-https-credentials.rule.js +1 -0
- package/dist/builtin-rules/static/general/sensitive-exception-response.rule.js +1 -0
- package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +1 -0
- package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +1 -0
- package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +1 -0
- package/dist/builtin-rules/static/spring-boot/no-unzoned-datetime.rule.js +1 -0
- package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +1 -0
- package/dist/index.d.ts +467 -0
- package/dist/index.js +7203 -913
- package/node_modules/@code-sentinel/parsers/index.js +81 -4
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
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/hardcoded-crypto-key.rule.ts
|
|
25
|
+
var SENSITIVE_KEY_SUFFIXES = ["Key", "Secret", "Password", "Passwd", "Iv"];
|
|
26
|
+
var isSensitiveKeyName = (identifier) => {
|
|
27
|
+
const words = identifier.replace(/[$_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/ +/).filter(Boolean);
|
|
28
|
+
if (words.length === 0) return false;
|
|
29
|
+
const last = words[words.length - 1] ?? "";
|
|
30
|
+
return SENSITIVE_KEY_SUFFIXES.some(
|
|
31
|
+
(suffix) => last === suffix || last.toLowerCase() === suffix.toLowerCase()
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
var BYTE_ARRAY_RE = /[[{][\s0-9xA-Fa-f,]+[\]}]/;
|
|
35
|
+
var BASE64_OR_HEX_STRING_RE = /['"][A-Za-z0-9+/=_-]{16,}['"]/;
|
|
36
|
+
var isSufficientLiteral = (literal) => {
|
|
37
|
+
if (BYTE_ARRAY_RE.test(literal)) {
|
|
38
|
+
const elements = (literal.match(/0x[0-9A-Fa-f]+|\d+/g) ?? []).length;
|
|
39
|
+
if (elements >= 16) return true;
|
|
40
|
+
}
|
|
41
|
+
if (BASE64_OR_HEX_STRING_RE.test(literal)) {
|
|
42
|
+
const m = literal.match(/['"]([A-Za-z0-9+/=_-]{16,})['"]/);
|
|
43
|
+
if (m && (m[1] ?? "").length >= 16) return true;
|
|
44
|
+
}
|
|
45
|
+
const strLen = literal.match(/['"]([^'"]{32,})['"]/);
|
|
46
|
+
if (strLen) return true;
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
var ASSIGN_KEY_RE = /(?:final\s+|val\s+|let\s+|var\s+|const\s+)?(\w+)\s*[:=]{1,2}\s*(['"][^'"]+['"]|\[[\s0-9xA-Fa-f,]+\]|\{[\s0-9xA-Fa-f,]+\});?/;
|
|
50
|
+
var CRYPTO_LITERAL_SINK_RE = /\b(?:KeyParameter|SecretKey|AesCbc|AesGcmSiv|AESCrypt|encrypt|decrypt|Cipher\.init|init| CryptoBox)\s*\([^;]*\bkey\s*[:,=]?\s*['"][^'"]+['"]/i;
|
|
51
|
+
var NON_SUFFICIENT_VALUE_RE = /(?:public|example|demo|test|sample|placeholder)/i;
|
|
52
|
+
var IGNORE_COMMENT_RE = /\/\/\s*secure-ignored\b/i;
|
|
53
|
+
var TEST_DEBUG_PATH_RE = /(?:^|\/)(?:test|debug)\//i;
|
|
54
|
+
var rule = {
|
|
55
|
+
id: "flutter/hardcoded-crypto-key",
|
|
56
|
+
version: 1,
|
|
57
|
+
kind: "static-ts",
|
|
58
|
+
title: "Kh\xF4ng hardcode key/secret/password/IV crypto trong source",
|
|
59
|
+
description: "Ph\xE1t hi\u1EC7n key material (AES key, secret, password, IV) ho\u1EB7c literal truy\u1EC1n v\xE0o `KeyParameter(...)`/`SecretKey(...)`/`AesCbc(...)`/`encrypt(...,key: '<literal>')` \u0111\u01B0\u1EE3c hardcode trong source mobile (Dart/Java/Kotlin/Swift). Key nh\xFAng trong app c\xF3 th\u1EC3 tr\xEDch ra kh\u1ECFi APK/IPA.",
|
|
60
|
+
severity: "error",
|
|
61
|
+
category: "mobile-security",
|
|
62
|
+
languages: ["dart", "java", "kotlin", "swift"],
|
|
63
|
+
scope: "flutter",
|
|
64
|
+
requires: "text",
|
|
65
|
+
masvsControlIds: ["MASVS-CRYPTO-2"],
|
|
66
|
+
baseConfidence: 90,
|
|
67
|
+
check(ctx) {
|
|
68
|
+
if (TEST_DEBUG_PATH_RE.test(ctx.file.path)) return [];
|
|
69
|
+
const lines = ctx.file.content.split(/\r?\n/);
|
|
70
|
+
const out = [];
|
|
71
|
+
let offset = 0;
|
|
72
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
73
|
+
const line = lines[i] ?? "";
|
|
74
|
+
if (IGNORE_COMMENT_RE.test(line)) {
|
|
75
|
+
offset += line.length + 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const assign = ASSIGN_KEY_RE.exec(line);
|
|
79
|
+
if (assign) {
|
|
80
|
+
const varName = assign[1] ?? "";
|
|
81
|
+
const literal = assign[2] ?? "";
|
|
82
|
+
if (isSensitiveKeyName(varName) && isSufficientLiteral(literal)) {
|
|
83
|
+
if (!NON_SUFFICIENT_VALUE_RE.test(literal)) {
|
|
84
|
+
out.push(
|
|
85
|
+
finding(
|
|
86
|
+
ctx.file,
|
|
87
|
+
offset,
|
|
88
|
+
`Key material \`${varName}\` hardcode literal trong source mobile \u2014 key c\xF3 th\u1EC3 tr\xEDch ra kh\u1ECFi APK/IPA (MASVS-CRYPTO-1; ATTT #85/#40).`,
|
|
89
|
+
"Kh\xF4ng nh\xFAng key trong source/asset: l\u01B0u key trong Android Keystore / iOS Keychain, t\u1EA3i t\u1EEB backend qua k\xEAnh TLS c\xF3 x\xE1c th\u1EF1c, ho\u1EB7c derive t\u1EEB passphrase d\xF9ng PBKDF2/Argon2 v\u1EDBi salt ng\u1EABu nhi\xEAn. Tr\xE1nh key default trong sample/demo production.",
|
|
90
|
+
{
|
|
91
|
+
snippet: line.trim(),
|
|
92
|
+
rootCauseKey: "hardcoded-crypto-key",
|
|
93
|
+
tags: ["crypto", "secrets", "masvs-crypto"]
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
offset += line.length + 1;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (CRYPTO_LITERAL_SINK_RE.test(line)) {
|
|
103
|
+
out.push(
|
|
104
|
+
finding(
|
|
105
|
+
ctx.file,
|
|
106
|
+
offset,
|
|
107
|
+
"Key/IV literal truy\u1EC1n tr\u1EF1c ti\u1EBFp v\xE0o API m\xE3 h\xF3a trong source mobile \u2014 key c\xF3 th\u1EC3 tr\xEDch ra kh\u1ECFi APK/IPA (MASVS-CRYPTO-1; ATTT #85/#40).",
|
|
108
|
+
"Kh\xF4ng nh\xFAng key trong source: d\xF9ng Android Keystore / iOS Keychain cho key storage, derive key t\u1EEB passphrase (PBKDF2/Argon2) ho\u1EB7c t\u1EA3i key qua k\xEAnh TLS c\xF3 x\xE1c th\u1EF1c; bi\u1EBFn key l\u1EA5y t\u1EEB runtime, kh\xF4ng ph\u1EA3i literal.",
|
|
109
|
+
{
|
|
110
|
+
snippet: line.trim(),
|
|
111
|
+
rootCauseKey: "hardcoded-crypto-key",
|
|
112
|
+
tags: ["crypto", "secrets", "masvs-crypto"]
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
offset += line.length + 1;
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { rule };
|
|
124
|
+
//# sourceMappingURL=hardcoded-crypto-key.rule.js.map
|
|
125
|
+
//# sourceMappingURL=hardcoded-crypto-key.rule.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
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/hardcoded-oauth-client-secret.rule.ts
|
|
25
|
+
var SECRET_LABEL_RE = /(?:clientSecret|ClientSecret|client_secret|CLIENT_SECRET)\b/;
|
|
26
|
+
var JSON_KEY_RE = /['"]client_secret['"]\s*:\s*/;
|
|
27
|
+
var WINDOW = 3;
|
|
28
|
+
var TEMPLATE_RE = /\$\{|#\{|\\\(|\{[A-Z][A-Z0-9_]{1,}\}|<[^>]{1,40}>|process\.env|System\.getenv|getenv\s*\(|Platform\.environment|Environment\.getenv|\bENV\b/i;
|
|
29
|
+
var PLACEHOLDER_WORDS_RE = /\b(?:example|demo|test|tests|testing|placeholder|sample|dummy|your_?secret|changeme|redacted|xxxx+)\b/i;
|
|
30
|
+
var WELL_KNOWN_DUMMY_SECRET_RE = /\.apps\.googleusercontent\.com|GOCSPX-/i;
|
|
31
|
+
var extractStringValues = (line) => {
|
|
32
|
+
const out = [];
|
|
33
|
+
const re = /['"]([^'"]{0,256})['"]/g;
|
|
34
|
+
while (true) {
|
|
35
|
+
const match = re.exec(line);
|
|
36
|
+
if (match === null) break;
|
|
37
|
+
if (match[1] !== void 0) out.push(match[1]);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
41
|
+
var isLiteralSecret = (value) => {
|
|
42
|
+
if (value.length < 8) return false;
|
|
43
|
+
if (TEMPLATE_RE.test(value)) return false;
|
|
44
|
+
if (PLACEHOLDER_WORDS_RE.test(value)) return false;
|
|
45
|
+
if (WELL_KNOWN_DUMMY_SECRET_RE.test(value)) return false;
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
var rule = {
|
|
49
|
+
id: "flutter/hardcoded-oauth-client-secret",
|
|
50
|
+
version: 1,
|
|
51
|
+
kind: "static-ts",
|
|
52
|
+
title: "Kh\xF4ng hardcode OAuth/OIDC client secret trong source mobile",
|
|
53
|
+
description: 'Ph\xE1t hi\u1EC7n OAuth/OIDC client secret g\u1EAFn literal string cho bi\u1EBFn `*ClientSecret*`/`client_secret`, key JSON `"client_secret":"..."` ho\u1EB7c c\u1EA5u h\xECnh `GoogleSignIn/AppAuth/OAuthConfig` k\xE8m secret literal \u2014 app mobile c\xF3 th\u1EC3 b\u1ECB d\u1ECBch ng\u01B0\u1EE3c v\xE0 r\xF2 r\u1EC9 secret.',
|
|
54
|
+
severity: "error",
|
|
55
|
+
category: "mobile-security",
|
|
56
|
+
languages: ["dart", "kotlin", "swift", "java"],
|
|
57
|
+
scope: "flutter",
|
|
58
|
+
requires: "text",
|
|
59
|
+
masvsControlIds: ["MASVS-AUTH-1"],
|
|
60
|
+
baseConfidence: 92,
|
|
61
|
+
check(ctx) {
|
|
62
|
+
const lines = ctx.file.content.split(/\r?\n/);
|
|
63
|
+
const out = [];
|
|
64
|
+
let offset = 0;
|
|
65
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
66
|
+
const line = lines[i] ?? "";
|
|
67
|
+
const literals = extractStringValues(line).filter(isLiteralSecret);
|
|
68
|
+
if (literals.length === 0) {
|
|
69
|
+
offset += line.length + 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const from = Math.max(0, i - WINDOW);
|
|
73
|
+
const to = Math.min(lines.length - 1, i + WINDOW);
|
|
74
|
+
const windowText = lines.slice(from, to + 1).join("\n");
|
|
75
|
+
const hasLabel = SECRET_LABEL_RE.test(windowText) || JSON_KEY_RE.test(windowText);
|
|
76
|
+
if (!hasLabel) {
|
|
77
|
+
offset += line.length + 1;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const onLine = literals.find((value) => {
|
|
81
|
+
const idx = line.indexOf(`'${value}'`) >= 0 ? line.indexOf(`'${value}'`) : line.indexOf(`"${value}"`);
|
|
82
|
+
if (idx < 0) return false;
|
|
83
|
+
const before = line.slice(0, idx);
|
|
84
|
+
return SECRET_LABEL_RE.test(before) || JSON_KEY_RE.test(before);
|
|
85
|
+
});
|
|
86
|
+
const secretValue = onLine ?? literals[0] ?? "";
|
|
87
|
+
out.push(
|
|
88
|
+
finding(
|
|
89
|
+
ctx.file,
|
|
90
|
+
offset,
|
|
91
|
+
`\`client_secret\` c\u1EE7a OAuth/OIDC c\xF3 v\u1EBB b\u1ECB hardcode literal (\`${secretValue.slice(0, 4)}\u2026${secretValue.slice(-2)}\`) trong source mobile.`,
|
|
92
|
+
"Kh\xF4ng nh\xFAng `client_secret` v\xE0o app mobile (n\xF3 c\xF3 th\u1EC3 b\u1ECB d\u1ECBch ng\u01B0\u1EE3c). D\xF9ng PKCE/code flow kh\xF4ng c\u1EA7n secret tr\xEAn client, ho\u1EB7c gi\u1EEF backend trung gian \u0111\u1EC3 trao \u0111\u1ED5i authorization code \u2014 `client_secret` ch\u1EC9 s\u1ED1ng \u1EDF backend.",
|
|
93
|
+
{
|
|
94
|
+
snippet: line.trim(),
|
|
95
|
+
rootCauseKey: "hardcoded-oauth-client-secret",
|
|
96
|
+
tags: ["auth", "secrets", "oauth"]
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
offset += line.length + 1;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export { rule };
|
|
107
|
+
//# sourceMappingURL=hardcoded-oauth-client-secret.rule.js.map
|
|
108
|
+
//# sourceMappingURL=hardcoded-oauth-client-secret.rule.js.map
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
masvsControlIds: ["MASVS-PLATFORM-1"],
|
|
77
|
+
baseConfidence: 83,
|
|
78
|
+
check(ctx) {
|
|
79
|
+
const file = ctx.file;
|
|
80
|
+
if (isDebugOrTestPath(file.path)) return [];
|
|
81
|
+
const out = [];
|
|
82
|
+
if (isPath(file, "androidmanifest.xml")) {
|
|
83
|
+
const content = file.content;
|
|
84
|
+
for (const { block, index } of intentFilterBlocks(content)) {
|
|
85
|
+
const schemes = schemesInBlock(block);
|
|
86
|
+
if (schemes.length === 0) continue;
|
|
87
|
+
if (isLauncherOnly(block)) continue;
|
|
88
|
+
const hasAutoVerify = attrValue(block, "android:autoVerify") === "true";
|
|
89
|
+
if (schemes.some((scheme) => scheme.includes("*"))) {
|
|
90
|
+
out.push(
|
|
91
|
+
finding(
|
|
92
|
+
file,
|
|
93
|
+
index,
|
|
94
|
+
`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.`,
|
|
95
|
+
'\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).',
|
|
96
|
+
{
|
|
97
|
+
severity: "warning",
|
|
98
|
+
confidence: 82,
|
|
99
|
+
rootCauseKey: "insecure-deep-link-wildcard",
|
|
100
|
+
snippet: block.split(/\r?\n/)[0]?.trim(),
|
|
101
|
+
tags: ["deep-link", "platform-security"]
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (!hasAutoVerify) {
|
|
108
|
+
out.push(
|
|
109
|
+
finding(
|
|
110
|
+
file,
|
|
111
|
+
index,
|
|
112
|
+
`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).`,
|
|
113
|
+
'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).',
|
|
114
|
+
{
|
|
115
|
+
severity: "error",
|
|
116
|
+
confidence: 86,
|
|
117
|
+
rootCauseKey: "insecure-deep-link-no-autoverify",
|
|
118
|
+
snippet: block.split(/\r?\n/)[0]?.trim(),
|
|
119
|
+
tags: ["deep-link", "platform-security"]
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
if (isPath(file, "info.plist")) {
|
|
128
|
+
const content = file.content;
|
|
129
|
+
const hasCustomScheme = /CFBundleURLTypes|CFBundleURLSchemes/i.test(content);
|
|
130
|
+
if (!hasCustomScheme) return out;
|
|
131
|
+
const hasUniversalLinksHint = /applinks:/i.test(content);
|
|
132
|
+
out.push(
|
|
133
|
+
finding(
|
|
134
|
+
file,
|
|
135
|
+
firstPlistKeyIndex(content, "CFBundleURLTypes"),
|
|
136
|
+
"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).",
|
|
137
|
+
"\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).",
|
|
138
|
+
{
|
|
139
|
+
severity: "warning",
|
|
140
|
+
confidence: hasUniversalLinksHint ? 72 : 80,
|
|
141
|
+
rootCauseKey: "insecure-deep-link-ios-custom-scheme",
|
|
142
|
+
tags: ["deep-link", "platform-security"]
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { rule };
|
|
153
|
+
//# sourceMappingURL=insecure-deep-link.rule.js.map
|
|
154
|
+
//# sourceMappingURL=insecure-deep-link.rule.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
masvsControlIds: ["MASVS-NETWORK-1"],
|
|
47
|
+
languages: ["plist"],
|
|
48
|
+
scope: "flutter",
|
|
49
|
+
requires: "text",
|
|
50
|
+
baseConfidence: 90,
|
|
51
|
+
check(ctx) {
|
|
52
|
+
const file = ctx.file;
|
|
53
|
+
const out = [];
|
|
54
|
+
if (!isPath(file, "info.plist")) return out;
|
|
55
|
+
if (isDebugOrTestPath(file.path.replace(/\\/g, "/"))) return out;
|
|
56
|
+
const content = file.content;
|
|
57
|
+
const atsIndex = firstIndex(content, /<key>\s*NSAppTransportSecurity\s*<\/key>/i);
|
|
58
|
+
if (atsIndex < 0) return out;
|
|
59
|
+
const arbitraryIndex = firstIndex(content, ARBITRARY_LOADS_TRUE);
|
|
60
|
+
if (arbitraryIndex < 0) return out;
|
|
61
|
+
const hasLocalNetworking = LOCAL_NETWORKING_TRUE.test(content);
|
|
62
|
+
const hasExceptionDomains = /<key>\s*NSExceptionDomains\s*<\/key>/i.test(content);
|
|
63
|
+
const narrowed = hasLocalNetworking || hasExceptionDomains;
|
|
64
|
+
out.push(
|
|
65
|
+
finding(
|
|
66
|
+
file,
|
|
67
|
+
arbitraryIndex,
|
|
68
|
+
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.",
|
|
69
|
+
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.",
|
|
70
|
+
{
|
|
71
|
+
severity: "warning",
|
|
72
|
+
confidence: narrowed ? 75 : 90,
|
|
73
|
+
rootCauseKey: "ats-arbitrary-loads"
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { rule };
|
|
82
|
+
//# sourceMappingURL=ios-ats-exception.rule.js.map
|
|
83
|
+
//# sourceMappingURL=ios-ats-exception.rule.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
masvsControlIds: ["MASVS-STORAGE-2"],
|
|
49
|
+
languages: ["swift", "objective-c"],
|
|
50
|
+
scope: "flutter",
|
|
51
|
+
requires: "text",
|
|
52
|
+
baseConfidence: 80,
|
|
53
|
+
check(ctx) {
|
|
54
|
+
const file = ctx.file;
|
|
55
|
+
const content = file.content;
|
|
56
|
+
const out = [];
|
|
57
|
+
const lines = content.split(/\r?\n/);
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
60
|
+
const line = lines[i] ?? "";
|
|
61
|
+
if (PASTEBOARD_SINK.test(line)) {
|
|
62
|
+
const from = Math.max(0, i - WINDOW);
|
|
63
|
+
const to = Math.min(lines.length - 1, i + WINDOW);
|
|
64
|
+
const windowText = lines.slice(from, to + 1).join("\n");
|
|
65
|
+
if (SENSITIVE_VALUE.test(windowText)) {
|
|
66
|
+
const hasPublicComment = PUBLIC_COMMENT_RE.test(windowText);
|
|
67
|
+
const directValue = directAssignedIdentifier(line);
|
|
68
|
+
const isPublicPayload = directValue !== null && PUBLIC_PAYLOAD_VALUE_RE.test(directValue);
|
|
69
|
+
const isPublicIntent = hasPublicComment || isPublicPayload;
|
|
70
|
+
if (!isPublicIntent) {
|
|
71
|
+
out.push(
|
|
72
|
+
finding(
|
|
73
|
+
file,
|
|
74
|
+
offset,
|
|
75
|
+
"Ghi gi\xE1 tr\u1ECB c\xF3 th\u1EC3 nh\u1EA1y c\u1EA3m l\xEAn system pasteboard (`UIPasteboard.general`).",
|
|
76
|
+
"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.",
|
|
77
|
+
{
|
|
78
|
+
severity: "warning",
|
|
79
|
+
confidence: 80,
|
|
80
|
+
snippet: line.trim(),
|
|
81
|
+
rootCauseKey: "pasteboard-sensitive-set"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
offset += line.length + 1;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { rule };
|
|
95
|
+
//# sourceMappingURL=ios-pasteboard-leak.rule.js.map
|
|
96
|
+
//# sourceMappingURL=ios-pasteboard-leak.rule.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
masvsControlIds: ["MASVS-RESILIENCE-1"],
|
|
41
|
+
baseConfidence: 65,
|
|
42
|
+
check(ctx) {
|
|
43
|
+
const lines = ctx.file.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
|
+
if (!UPDATE_REF_RE.test(line) || NAMING_ONLY_RE.test(line)) {
|
|
49
|
+
offset += line.length + 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const from = Math.max(0, i - WINDOW);
|
|
53
|
+
const to = Math.min(lines.length - 1, i + WINDOW);
|
|
54
|
+
const windowText = lines.slice(from, to + 1).join("\n");
|
|
55
|
+
if (HANDLED_RE.test(windowText)) {
|
|
56
|
+
offset += line.length + 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
out.push(
|
|
60
|
+
finding(
|
|
61
|
+
ctx.file,
|
|
62
|
+
offset,
|
|
63
|
+
"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.",
|
|
64
|
+
"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.",
|
|
65
|
+
{
|
|
66
|
+
snippet: line.trim(),
|
|
67
|
+
confidence: 65,
|
|
68
|
+
rootCauseKey: "missing-enforced-update-handling",
|
|
69
|
+
tags: ["build", "update-enforcement", "resilience"]
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
offset += line.length + 1;
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { rule };
|
|
80
|
+
//# sourceMappingURL=missing-enforced-update.rule.js.map
|
|
81
|
+
//# sourceMappingURL=missing-enforced-update.rule.js.map
|