@code-sentinel-cli/code-sentinel-cli 4.0.8 → 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.
- package/dist/bin.js +7352 -1072
- 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 +104 -0
- package/dist/builtin-rules/static/flutter/android-release-debuggable.rule.js +85 -0
- package/dist/builtin-rules/static/flutter/bad-certificate-callback.rule.js +80 -0
- package/dist/builtin-rules/static/flutter/biometric-without-crypto-object.rule.js +86 -0
- package/dist/builtin-rules/static/flutter/cleartext-http-endpoint.rule.js +76 -0
- package/dist/builtin-rules/static/flutter/device-fingerprint-collection.rule.js +73 -0
- package/dist/builtin-rules/static/flutter/exported-content-provider-leak.rule.js +118 -0
- package/dist/builtin-rules/static/flutter/hardcoded-crypto-key.rule.js +124 -0
- package/dist/builtin-rules/static/flutter/hardcoded-oauth-client-secret.rule.js +107 -0
- package/dist/builtin-rules/static/flutter/insecure-deep-link.rule.js +153 -0
- package/dist/builtin-rules/static/flutter/ios-ats-exception.rule.js +82 -0
- package/dist/builtin-rules/static/flutter/ios-pasteboard-leak.rule.js +95 -0
- package/dist/builtin-rules/static/flutter/missing-enforced-update.rule.js +80 -0
- package/dist/builtin-rules/static/flutter/oauth-missing-pkce.rule.js +74 -0
- package/dist/builtin-rules/static/flutter/token-insecure-storage.rule.js +120 -0
- package/dist/builtin-rules/static/flutter/tracking-sdk-init.rule.js +75 -0
- package/dist/builtin-rules/static/flutter/weak-mobile-crypto-algorithm.rule.js +113 -0
- package/dist/builtin-rules/static/flutter/weak-prng-mobile.rule.js +103 -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-hardcoded-secret.rule.js +61 -5
- 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 +27 -0
- package/dist/builtin-rules/static/general/openapi-https-credentials.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 +7351 -1071
- package/node_modules/@code-sentinel/parsers/index.js +53 -4
- package/package.json +1 -1
|
@@ -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/bad-certificate-callback.rule.ts
|
|
25
|
+
var BAD_CERT_CALLBACK_RE = /badCertificateCallback/;
|
|
26
|
+
var ACCEPT_TRUE_RE = /(?:=>\s*true\b|return\s+true\s*;?)/;
|
|
27
|
+
var CERT_CHECK_RE = /cert\.type|\.issuer\b|Issuer\b|fingerprint|SHA-?256|sha256|publicKey|SPKI|own\s*C\s*A|trustedCert|allowedCert|isCertValid|verifyCert|pinned/i;
|
|
28
|
+
var CONDITIONAL_RE = /\bif\s*\(/;
|
|
29
|
+
var firstAcceptTrueIndex = (text) => ACCEPT_TRUE_RE.exec(text)?.index ?? -1;
|
|
30
|
+
var rule = {
|
|
31
|
+
id: "flutter/bad-certificate-callback",
|
|
32
|
+
version: 1,
|
|
33
|
+
kind: "static-ts",
|
|
34
|
+
title: "Kh\xF4ng ch\u1EA5p nh\u1EADn m\u1ECDi ch\u1EE9ng ch\u1EC9 TLS b\u1EB1ng badCertificateCallback => true",
|
|
35
|
+
description: "Ph\xE1t hi\u1EC7n `badCertificateCallback` tr\u1EA3 `true` v\xF4 \u0111i\u1EC1u ki\u1EC7n \u2014 ch\u1EA1y trong release s\u1EBD ch\u1EA5p nh\u1EADn m\u1ECDi ch\u1EE9ng ch\u1EC9 (k\u1EC3 c\u1EA3 MITM) v\xE0 v\xF4 hi\u1EC7u h\xF3a x\xE1c th\u1EF1c TLS.",
|
|
36
|
+
severity: "error",
|
|
37
|
+
category: "mobile-security",
|
|
38
|
+
languages: ["dart"],
|
|
39
|
+
scope: "flutter",
|
|
40
|
+
requires: "text",
|
|
41
|
+
baseConfidence: 92,
|
|
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 (BAD_CERT_CALLBACK_RE.test(line)) {
|
|
49
|
+
const following = lines.slice(i + 1, Math.min(lines.length, i + 6)).join("\n");
|
|
50
|
+
const windowText = [line, following].join("\n");
|
|
51
|
+
const acceptIndex = firstAcceptTrueIndex(windowText);
|
|
52
|
+
const isAcceptAll = acceptIndex >= 0;
|
|
53
|
+
const upToAccept = acceptIndex >= 0 ? windowText.slice(0, acceptIndex) : "";
|
|
54
|
+
const hasCertCheck = CERT_CHECK_RE.test(upToAccept);
|
|
55
|
+
const hasConditional = acceptIndex >= 0 && CONDITIONAL_RE.test(upToAccept);
|
|
56
|
+
if (isAcceptAll && !hasCertCheck && !hasConditional) {
|
|
57
|
+
out.push(
|
|
58
|
+
finding(
|
|
59
|
+
ctx.file,
|
|
60
|
+
offset,
|
|
61
|
+
"`badCertificateCallback` tr\u1EA3 `true` v\xF4 \u0111i\u1EC1u ki\u1EC7n \u2014 app s\u1EBD ch\u1EA5p nh\u1EADn m\u1ECDi ch\u1EE9ng ch\u1EC9 TLS (k\u1EC3 c\u1EA3 ch\u1EE9ng ch\u1EC9 MITM) trong release.",
|
|
62
|
+
"Kh\xF4ng tr\u1EA3 `true` v\xF4 \u0111i\u1EC1u ki\u1EC7n trong `badCertificateCallback`. V\u1EDBi server d\xF9ng self-signed/own CA, ki\u1EC3m tra fingerprint/SPKI ho\u1EB7c CA c\u1EE7a ch\u1EE9ng ch\u1EC9 tr\u01B0\u1EDBc khi tr\u1EA3 `true`; v\u1EDBi server c\xF4ng khai, b\u1ECF callback n\xE0y v\xE0 d\xF9ng x\xE1c th\u1EF1c CA m\u1EB7c \u0111\u1ECBnh c\u1EE7a h\u1EC7 th\u1ED1ng.",
|
|
63
|
+
{
|
|
64
|
+
snippet: line.trim(),
|
|
65
|
+
rootCauseKey: "trust-all-certificate-callback",
|
|
66
|
+
tags: ["network", "tls"]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
offset += line.length + 1;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { rule };
|
|
79
|
+
//# sourceMappingURL=bad-certificate-callback.rule.js.map
|
|
80
|
+
//# sourceMappingURL=bad-certificate-callback.rule.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
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/biometric-without-crypto-object.rule.ts
|
|
25
|
+
var PROMPT_RE = /\bBiometricPrompt\b|LocalAuthentication\.authenticate\s*\(|evaluatePolicy\s*\(/;
|
|
26
|
+
var WINDOW = 5;
|
|
27
|
+
var CRYPTO_BOUND_RE = /\bCryptoObject\b|Cipher\b|Signature\b|signingKey\b|KeyStore\b|cryptoObject\b|initSign\b|doFinal\b/i;
|
|
28
|
+
var IOS_KEY_BOUND_RE = /\bSecAccessControl\b|kSecAttrAccessibleWhenUnlockedThisDeviceOnly\b|kSecAttrAccessible\b|keychain\b|SecItemAdd\b/i;
|
|
29
|
+
var rule = {
|
|
30
|
+
id: "flutter/biometric-without-crypto-object",
|
|
31
|
+
version: 1,
|
|
32
|
+
kind: "static-ts",
|
|
33
|
+
title: "Sinh tr\u1EAFc h\u1ECDc ph\u1EA3i r\xE0ng bu\u1ED9c CryptoObject/Cipher, kh\xF4ng ch\u1EC9 check UI",
|
|
34
|
+
description: "Ph\xE1t hi\u1EC7n `BiometricPrompt.authenticate(...)`, `LocalAuthentication.authenticate(...)` ho\u1EB7c `LAContext.evaluatePolicy(...)` m\xE0 c\u1EEDa s\u1ED5 xung quanh KH\xD4NG c\xF3 `CryptoObject`/`Cipher`/`Sign`/keychain \u2014 t\u1EE9c sinh tr\u1EAFc ch\u1EC9 l\xE0m n\xFAt OK (MASWE-0022), kh\xF4ng m\u1EDF kho\xE1 th\u1EADt.",
|
|
35
|
+
severity: "warning",
|
|
36
|
+
category: "mobile-security",
|
|
37
|
+
languages: ["kotlin", "java", "dart", "swift"],
|
|
38
|
+
scope: "flutter",
|
|
39
|
+
requires: "text",
|
|
40
|
+
baseConfidence: 75,
|
|
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 (!PROMPT_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 (CRYPTO_BOUND_RE.test(windowText)) {
|
|
55
|
+
offset += line.length + 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (/evaluatePolicy/.test(line) && IOS_KEY_BOUND_RE.test(windowText)) {
|
|
59
|
+
offset += line.length + 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const isIos = /evaluatePolicy|LAContext|localizedReason/.test(windowText);
|
|
63
|
+
const suggestion = isIos ? "\u0110\u0103ng k\xFD kho\xE1 qua `SecAccessControlCreateWithFlags` v\u1EDBi c\u1EDD `.biometryCurrentSet` r\u1ED3i d\xF9ng khi `evaluatePolicy` tr\u1EA3 OK \u2014 kho\xE1 ph\u1EA3i n\u1EB1m trong Keychain r\xE0ng bu\u1ED9c sinh tr\u1EAFc, kh\xF4ng ch\u1EC9 check OK r\u1ED3i m\u1EDF kho\xE1 t\xE1ch r\u1EDDi." : "Truy\u1EC1n `BiometricPrompt.CryptoObject` (ch\u1EE5p `Cipher`/`Signature`/`Mac`) v\xE0o `authenticate`, ho\u1EB7c v\u1EDBi Flutter `local_auth` d\xF9ng `AuthMessages` + kh\u1EDFi t\u1EA1o cipher ri\xEAng v\xE0 m\u1EDF kho\xE1 T\u1EA0I l\xFAc sinh tr\u1EAFc th\xE0nh c\xF4ng \u2014 kh\xF4ng ch\u1EC9 d\xF9ng k\u1EBFt qu\u1EA3 bool.";
|
|
64
|
+
out.push(
|
|
65
|
+
finding(
|
|
66
|
+
ctx.file,
|
|
67
|
+
offset,
|
|
68
|
+
"Sinh tr\u1EAFc h\u1ECDc ch\u1EC9 ki\u1EC3m tra UI bool m\xE0 kh\xF4ng c\xF3 `CryptoObject`/`Cipher`/key r\xE0ng bu\u1ED9c \u2014 kh\xF4ng ch\u1EE9ng minh ng\u01B0\u1EDDi d\xF9ng h\u1EE3p l\u1EC7 n\u1EAFm kho\xE1 (MASWE-0022).",
|
|
69
|
+
suggestion,
|
|
70
|
+
{
|
|
71
|
+
snippet: line.trim(),
|
|
72
|
+
confidence: 75,
|
|
73
|
+
rootCauseKey: "biometric-without-crypto-object",
|
|
74
|
+
tags: ["auth", "biometric", "crypto-protocol"]
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
offset += line.length + 1;
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { rule };
|
|
85
|
+
//# sourceMappingURL=biometric-without-crypto-object.rule.js.map
|
|
86
|
+
//# sourceMappingURL=biometric-without-crypto-object.rule.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
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/cleartext-http-endpoint.rule.ts
|
|
25
|
+
var CLEARTEXT_URL_RE = /['"(]http:\/\/([^'"\s)]+)['")]?/;
|
|
26
|
+
var DEV_HOST_RE = /^(?:localhost|127\.\d{1,3}\.\d{1,3}\.\d{1,3}|0\.0\.0\.0|\[?::1\]?|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}|169\.254\.\d{1,3}\.\d{1,3}|[A-Za-z0-9._-]*\.(?:internal|local))(?::\d+)?(?:[/?#].*)?$/i;
|
|
27
|
+
var IGNORE_COMMENT_RE = /\/\/\s*ignore:\s*cleartext\b/i;
|
|
28
|
+
var hostOf = (url) => url.replace(/^http:\/\//i, "").split(/[/?#]/, 1)[0] ?? "";
|
|
29
|
+
var rule = {
|
|
30
|
+
id: "flutter/cleartext-http-endpoint",
|
|
31
|
+
version: 1,
|
|
32
|
+
kind: "static-ts",
|
|
33
|
+
title: "Kh\xF4ng d\xF9ng endpoint HTTP cleartext (http://) trong code Flutter",
|
|
34
|
+
description: "Ph\xE1t hi\u1EC7n URL `http://` literal (k\u1EC3 c\u1EA3 `baseUrl` c\u1EE7a Dio) trong code Dart \u2014 d\u1EEF li\u1EC7u \u0111i qua HTTP cleartext c\xF3 th\u1EC3 b\u1ECB nghe l\xE9n/s\u1EEDa \u0111\u1ED5i tr\xEAn \u0111\u01B0\u1EDDng truy\u1EC1n.",
|
|
35
|
+
severity: "warning",
|
|
36
|
+
category: "mobile-security",
|
|
37
|
+
languages: ["dart"],
|
|
38
|
+
scope: "flutter",
|
|
39
|
+
requires: "text",
|
|
40
|
+
baseConfidence: 88,
|
|
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
|
+
const match = CLEARTEXT_URL_RE.exec(line);
|
|
48
|
+
if (match && !IGNORE_COMMENT_RE.test(line)) {
|
|
49
|
+
const url = `http://${match[1] ?? ""}`;
|
|
50
|
+
const host = hostOf(url);
|
|
51
|
+
const isDevHost = DEV_HOST_RE.test(host);
|
|
52
|
+
if (!isDevHost) {
|
|
53
|
+
out.push(
|
|
54
|
+
finding(
|
|
55
|
+
ctx.file,
|
|
56
|
+
offset,
|
|
57
|
+
`Endpoint HTTP cleartext \`${url}\` \u2014 d\u1EEF li\u1EC7u g\u1EEDi/nh\u1EADn kh\xF4ng \u0111\u01B0\u1EE3c m\xE3 h\xF3a tr\xEAn \u0111\u01B0\u1EDDng truy\u1EC1n (ATTT #22).`,
|
|
58
|
+
"Chuy\u1EC3n endpoint sang `https://`; v\u1EDBi backend ch\u01B0a c\xF3 TLS h\u1EE3p l\u1EC7, d\xF9ng dev host n\u1ED9i b\u1ED9 (localhost/private IP) t\xE1ch theo flavor v\xE0 th\xEAm `// ignore: cleartext` k\xE8m l\xFD do n\u1EBFu c\u1EA7n gi\u1EEF t\u1EA1m.",
|
|
59
|
+
{
|
|
60
|
+
snippet: line.trim(),
|
|
61
|
+
rootCauseKey: "cleartext-http-url",
|
|
62
|
+
tags: ["network", "tls"]
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
offset += line.length + 1;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { rule };
|
|
75
|
+
//# sourceMappingURL=cleartext-http-endpoint.rule.js.map
|
|
76
|
+
//# sourceMappingURL=cleartext-http-endpoint.rule.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
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/device-fingerprint-collection.rule.ts
|
|
25
|
+
var FINGERPRINT_RE = /(\bBuild\.SERIAL\b|\bANDROID_ID\b|Settings\.Secure\.getString\([^)]*ANDROID_ID|getDeviceId\s*\(\s*\)|getImei\s*\(|getMeid\s*\(|identifierForVendor|advertisingIdentifier|MediaDrm.*Widevine| WidevineDeviceId)/;
|
|
26
|
+
var DIAGNOSTIC_CONTEXT_RE = /(recordException|recordError|log\.|logger\.|Crashlytics\.|CrashReporting\.|setUserId|printStackTrace|firebaseCrashlytics|Sentry\.)/i;
|
|
27
|
+
var rule = {
|
|
28
|
+
id: "flutter/device-fingerprint-collection",
|
|
29
|
+
version: 1,
|
|
30
|
+
kind: "static-ts",
|
|
31
|
+
title: "Thu th\u1EADp hardware/device identifier \u1ED5n \u0111\u1ECBnh (device fingerprint)",
|
|
32
|
+
description: "Build.SERIAL / ANDROID_ID / Widevine device id / IMEI / identifierForVendor / IDFA d\xF9ng ngo\xE0i lu\u1ED3ng l\u1ED7i-diagnostic cho ph\xE9p fingerprint thi\u1EBFt b\u1ECB (MASVS-PRIVACY-2/MASWE-0067).",
|
|
33
|
+
severity: "warning",
|
|
34
|
+
category: "mobile-privacy",
|
|
35
|
+
languages: ["kotlin", "java", "swift", "dart"],
|
|
36
|
+
scope: "flutter",
|
|
37
|
+
requires: "text",
|
|
38
|
+
baseConfidence: 78,
|
|
39
|
+
check(ctx) {
|
|
40
|
+
if (/(?:^|\/)(?:debug|test|__tests__)\//i.test(ctx.file.path)) return [];
|
|
41
|
+
const lines = ctx.file.content.split(/\r?\n/);
|
|
42
|
+
const out = [];
|
|
43
|
+
let offset = 0;
|
|
44
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
45
|
+
const line = lines[i] ?? "";
|
|
46
|
+
if (!FINGERPRINT_RE.test(line)) {
|
|
47
|
+
offset += line.length + 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const window = lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 4)).join("\n");
|
|
51
|
+
const isDiagnostic = DIAGNOSTIC_CONTEXT_RE.test(window);
|
|
52
|
+
out.push(
|
|
53
|
+
finding(
|
|
54
|
+
ctx.file,
|
|
55
|
+
offset,
|
|
56
|
+
isDiagnostic ? "Hardware identifier d\xF9ng trong lu\u1ED3ng diagnostic \u2014 v\u1EABn n\xEAn anonymize hash (gi\u1EA3m confidence v\xEC context h\u1EE3p l\u1EC7)." : "Hardware/device identifier \u1ED5n \u0111\u1ECBnh \u0111\u01B0\u1EE3c thu th\u1EADp; c\xF3 th\u1EC3 d\xF9ng fingerprint thi\u1EBFt b\u1ECB.",
|
|
57
|
+
"D\xF9ng UUID random m\u1ED7i c\xE0i \u0111\u1EB7t, ho\u1EB7c hash SHA-256 + salt thay cho raw identifier; kh\xF4ng g\u1EEDi identifierForVendor/SERIAL/IMEI/IDFA qua network/storage.",
|
|
58
|
+
{
|
|
59
|
+
snippet: line.trim(),
|
|
60
|
+
rootCauseKey: isDiagnostic ? "device-fingerprint-diagnostic-context" : "device-fingerprint-collection",
|
|
61
|
+
tags: ["privacy", "fingerprint"]
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
offset += line.length + 1;
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { rule };
|
|
72
|
+
//# sourceMappingURL=device-fingerprint-collection.rule.js.map
|
|
73
|
+
//# sourceMappingURL=device-fingerprint-collection.rule.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
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/exported-content-provider-leak.rule.ts
|
|
30
|
+
var isDebugOrTestPath = (path) => {
|
|
31
|
+
const normalized = path.replace(/\\/g, "/").toLowerCase();
|
|
32
|
+
return normalized.includes("/debug/") || normalized.includes("/test/");
|
|
33
|
+
};
|
|
34
|
+
var SYSTEM_AUTHORITY_RE = /^com\.android\.providers\./;
|
|
35
|
+
var providerBlocks = (content) => {
|
|
36
|
+
const out = [];
|
|
37
|
+
const openRe = /<provider\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 = "</provider>";
|
|
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 hasPermissionGuard = (block) => attrValue(block, "android:permission") !== null || attrValue(block, "android:readPermission") !== null || attrValue(block, "android:writePermission") !== null;
|
|
54
|
+
var rule = {
|
|
55
|
+
id: "flutter/exported-content-provider-leak",
|
|
56
|
+
version: 1,
|
|
57
|
+
kind: "static-ts",
|
|
58
|
+
title: "Content provider b\u1ECB export ph\u1EA3i c\xF3 permission/pathPermission guard",
|
|
59
|
+
description: 'Ph\xE1t hi\u1EC7n `<provider android:exported="true"` thi\u1EBFu `android:permission` (leak d\u1EEF li\u1EC7u ra app kh\xE1c), v\xE0 `<provider android:grantUriPermissions="true"` thi\u1EBFu `android:pathPermission` (URI permission to\xE0n scope). B\u1ECF qua provider h\u1EC7 th\u1ED1ng `com.android.providers.*`.',
|
|
60
|
+
severity: "warning",
|
|
61
|
+
category: "mobile-security",
|
|
62
|
+
languages: ["xml"],
|
|
63
|
+
scope: "flutter",
|
|
64
|
+
requires: "text",
|
|
65
|
+
baseConfidence: 82,
|
|
66
|
+
check(ctx) {
|
|
67
|
+
const file = ctx.file;
|
|
68
|
+
if (!isPath(file, "androidmanifest.xml") || isDebugOrTestPath(file.path)) return [];
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const { block, index } of providerBlocks(file.content)) {
|
|
71
|
+
const authorities = attrValue(block, "android:authorities") ?? "";
|
|
72
|
+
if (SYSTEM_AUTHORITY_RE.test(authorities)) continue;
|
|
73
|
+
const exported = attrValue(block, "android:exported") === "true";
|
|
74
|
+
const grantUri = attrValue(block, "android:grantUriPermissions") === "true";
|
|
75
|
+
const guarded = hasPermissionGuard(block);
|
|
76
|
+
const hasPathPermission = /<path-permission\b/i.test(block) || attrValue(block, "android:pathPermission") !== null;
|
|
77
|
+
if (exported && !guarded) {
|
|
78
|
+
out.push(
|
|
79
|
+
finding(
|
|
80
|
+
file,
|
|
81
|
+
index,
|
|
82
|
+
`Provider exports d\u1EEF li\u1EC7u (\`android:exported="true"\`) m\xE0 kh\xF4ng c\xF3 \`android:permission\` \u2014 app kh\xE1c c\xF9ng tr\xECnh t\u1EF1 \u01B0u ti\xEAn c\xF3 th\u1EC3 truy v\u1EA5n/insert.\`${authorities ? ` (authorities: \`${authorities}\`)` : ""}\``,
|
|
83
|
+
'Th\xEAm `android:permission` khai margin protection (custom permission + c\u1EA5p cho client h\u1EE3p l\u1EC7), ho\u1EB7c \u0111\u1EB7t `android:exported="false"` n\u1EBFu kh\xF4ng c\u1EA7n m\u1EDF ra ngo\xE0i app; c\xE2n nh\u1EAFc `android:readPermission`/`writePermission` t\xE1ch quy\u1EC1n (ATTT #44, #71).',
|
|
84
|
+
{
|
|
85
|
+
severity: "warning",
|
|
86
|
+
confidence: 80,
|
|
87
|
+
rootCauseKey: "exported-provider-no-permission",
|
|
88
|
+
snippet: block.split(/\r?\n/)[0]?.trim(),
|
|
89
|
+
tags: ["content-provider", "platform-security"]
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (grantUri && !hasPathPermission && !guarded) {
|
|
95
|
+
out.push(
|
|
96
|
+
finding(
|
|
97
|
+
file,
|
|
98
|
+
index,
|
|
99
|
+
'Provider b\u1EADt `android:grantUriPermissions="true"` m\xE0 kh\xF4ng gi\u1EDBi h\u1EA1n b\u1EB1ng `android:pathPermission` / `<path-permission>` \u2014 client \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n t\u1EA1m c\xF3 th\u1EC3 \u0111\u1EE5ng to\xE0n scope URI c\u1EE7a provider (g\xE2y l\u1ED9/gia t\u0103ng quy\u1EC1n cho URI ngo\xE0i \xFD \u0111\u1ECBnh).',
|
|
100
|
+
"Gi\u1EDBi h\u1EA1n b\u1EB1ng `android:pathPermission` / `<path-permission>` cho t\u1EEBng prefix/pattern URI, ho\u1EB7c t\u1EAFt `android:grantUriPermissions` n\u1EBFu kh\xF4ng c\u1EA7n (ATTT #44, #71).",
|
|
101
|
+
{
|
|
102
|
+
severity: "error",
|
|
103
|
+
confidence: 85,
|
|
104
|
+
rootCauseKey: "grant-uri-no-pathpermission",
|
|
105
|
+
snippet: block.split(/\r?\n/)[0]?.trim(),
|
|
106
|
+
tags: ["content-provider", "platform-security"]
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { rule };
|
|
117
|
+
//# sourceMappingURL=exported-content-provider-leak.rule.js.map
|
|
118
|
+
//# sourceMappingURL=exported-content-provider-leak.rule.js.map
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
baseConfidence: 90,
|
|
66
|
+
check(ctx) {
|
|
67
|
+
if (TEST_DEBUG_PATH_RE.test(ctx.file.path)) return [];
|
|
68
|
+
const lines = ctx.file.content.split(/\r?\n/);
|
|
69
|
+
const out = [];
|
|
70
|
+
let offset = 0;
|
|
71
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
72
|
+
const line = lines[i] ?? "";
|
|
73
|
+
if (IGNORE_COMMENT_RE.test(line)) {
|
|
74
|
+
offset += line.length + 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const assign = ASSIGN_KEY_RE.exec(line);
|
|
78
|
+
if (assign) {
|
|
79
|
+
const varName = assign[1] ?? "";
|
|
80
|
+
const literal = assign[2] ?? "";
|
|
81
|
+
if (isSensitiveKeyName(varName) && isSufficientLiteral(literal)) {
|
|
82
|
+
if (!NON_SUFFICIENT_VALUE_RE.test(literal)) {
|
|
83
|
+
out.push(
|
|
84
|
+
finding(
|
|
85
|
+
ctx.file,
|
|
86
|
+
offset,
|
|
87
|
+
`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).`,
|
|
88
|
+
"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.",
|
|
89
|
+
{
|
|
90
|
+
snippet: line.trim(),
|
|
91
|
+
rootCauseKey: "hardcoded-crypto-key",
|
|
92
|
+
tags: ["crypto", "secrets", "masvs-crypto"]
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
offset += line.length + 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (CRYPTO_LITERAL_SINK_RE.test(line)) {
|
|
102
|
+
out.push(
|
|
103
|
+
finding(
|
|
104
|
+
ctx.file,
|
|
105
|
+
offset,
|
|
106
|
+
"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).",
|
|
107
|
+
"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.",
|
|
108
|
+
{
|
|
109
|
+
snippet: line.trim(),
|
|
110
|
+
rootCauseKey: "hardcoded-crypto-key",
|
|
111
|
+
tags: ["crypto", "secrets", "masvs-crypto"]
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
offset += line.length + 1;
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export { rule };
|
|
123
|
+
//# sourceMappingURL=hardcoded-crypto-key.rule.js.map
|
|
124
|
+
//# sourceMappingURL=hardcoded-crypto-key.rule.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
baseConfidence: 92,
|
|
60
|
+
check(ctx) {
|
|
61
|
+
const lines = ctx.file.content.split(/\r?\n/);
|
|
62
|
+
const out = [];
|
|
63
|
+
let offset = 0;
|
|
64
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
65
|
+
const line = lines[i] ?? "";
|
|
66
|
+
const literals = extractStringValues(line).filter(isLiteralSecret);
|
|
67
|
+
if (literals.length === 0) {
|
|
68
|
+
offset += line.length + 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const from = Math.max(0, i - WINDOW);
|
|
72
|
+
const to = Math.min(lines.length - 1, i + WINDOW);
|
|
73
|
+
const windowText = lines.slice(from, to + 1).join("\n");
|
|
74
|
+
const hasLabel = SECRET_LABEL_RE.test(windowText) || JSON_KEY_RE.test(windowText);
|
|
75
|
+
if (!hasLabel) {
|
|
76
|
+
offset += line.length + 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const onLine = literals.find((value) => {
|
|
80
|
+
const idx = line.indexOf(`'${value}'`) >= 0 ? line.indexOf(`'${value}'`) : line.indexOf(`"${value}"`);
|
|
81
|
+
if (idx < 0) return false;
|
|
82
|
+
const before = line.slice(0, idx);
|
|
83
|
+
return SECRET_LABEL_RE.test(before) || JSON_KEY_RE.test(before);
|
|
84
|
+
});
|
|
85
|
+
const secretValue = onLine ?? literals[0] ?? "";
|
|
86
|
+
out.push(
|
|
87
|
+
finding(
|
|
88
|
+
ctx.file,
|
|
89
|
+
offset,
|
|
90
|
+
`\`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.`,
|
|
91
|
+
"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.",
|
|
92
|
+
{
|
|
93
|
+
snippet: line.trim(),
|
|
94
|
+
rootCauseKey: "hardcoded-oauth-client-secret",
|
|
95
|
+
tags: ["auth", "secrets", "oauth"]
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
offset += line.length + 1;
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { rule };
|
|
106
|
+
//# sourceMappingURL=hardcoded-oauth-client-secret.rule.js.map
|
|
107
|
+
//# sourceMappingURL=hardcoded-oauth-client-secret.rule.js.map
|