loadwise 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -19
- package/agent/hooks/check-edited-file.mjs +146 -28
- package/dist/bin/github-action.js +3 -74
- package/dist/bin/loadwise.js +12 -12
- package/dist/lib/accessibility/aria-tables.js +10 -6
- package/dist/lib/accessibility/document-reference-rules.js +13 -3
- package/dist/lib/accessibility/jsx-elements.js +34 -16
- package/dist/lib/accessibility/native-interactive.js +51 -13
- package/dist/lib/accessibility/rules.js +4 -2
- package/dist/lib/accessibility/site-fixes/aria-typo.js +65 -0
- package/dist/lib/accessibility/site-fixes/html-language.js +45 -9
- package/dist/lib/accessibility/template-elements.js +5 -3
- package/dist/lib/editor/actions.js +15 -9
- package/dist/lib/editor/diagnostics.js +110 -107
- package/dist/lib/editor/finding-comparison.js +4 -25
- package/dist/lib/editor/hover-markdown.js +104 -0
- package/dist/lib/editor/inline-fix.js +50 -0
- package/dist/lib/editor/inline-recommendation.js +27 -0
- package/dist/lib/editor/language-server.js +94 -18
- package/dist/lib/editor/scan-session.js +2 -1
- package/dist/lib/editor/standalone-performance-examples.js +48 -0
- package/dist/lib/maintainability/analysis/analyze-source.js +2 -0
- package/dist/lib/maintainability/architecture/architecture.js +50 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -5
- package/dist/lib/maintainability/cli/site-fix.js +3 -0
- package/dist/lib/maintainability/cli.js +6 -3
- package/dist/lib/maintainability/examples.js +48 -0
- package/dist/lib/maintainability/quality/modern-node-callbacks.js +188 -0
- package/dist/lib/maintainability/quality/modern-syntax.js +301 -0
- package/dist/lib/maintainability/quality/tsconfig-strict.js +307 -15
- package/dist/lib/maintainability/rule-ids.js +18 -0
- package/dist/lib/maintainability/scan-changed.js +33 -2
- package/dist/lib/maintainability/scan.js +10 -1
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +15 -6
- package/dist/lib/maintainability/unused/module-usage-signatures.js +116 -0
- package/dist/lib/maintainability/unused/module-usage.js +67 -106
- package/dist/lib/maintainability/unused/unused-bindings.js +143 -8
- package/dist/lib/maintainability/unused/unused-dependencies.js +218 -0
- package/dist/lib/maintainability/unused/unused-modules.js +4 -0
- package/dist/lib/performance/analysis/missing-packages.js +3 -0
- package/dist/lib/performance/analysis/source-text.js +2 -2
- package/dist/lib/performance/analyze.js +4 -1
- package/dist/lib/performance/async/floating-promises.js +25 -4
- package/dist/lib/performance/cli/cli-output.js +9 -3
- package/dist/lib/performance/cli/cli-policy.js +25 -2
- package/dist/lib/performance/cli/cli-scan.js +25 -24
- package/dist/lib/performance/cli/scan-outcome.js +19 -1
- package/dist/lib/performance/cli/shared-security-inputs.js +27 -0
- package/dist/lib/performance/cli/watch.js +27 -8
- package/dist/lib/performance/collections/collection-lookups.js +27 -10
- package/dist/lib/performance/collections/collection-reduce.js +32 -2
- package/dist/lib/performance/collections/collections.js +28 -0
- package/dist/lib/performance/collections/repeated.js +25 -1
- package/dist/lib/performance/contracts/cli.js +22 -11
- package/dist/lib/performance/contracts/git-files.js +46 -1
- package/dist/lib/performance/datastores/pooling.js +1 -17
- package/dist/lib/performance/datastores/postgres.js +41 -33
- package/dist/lib/performance/engine/native.js +5 -1
- package/dist/lib/performance/frontend/angular-template-calls.js +187 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +68 -8
- package/dist/lib/performance/frontend/frontend-perf.js +115 -171
- package/dist/lib/performance/frontend/frontend-render-perf.js +7 -3
- package/dist/lib/performance/frontend/jsx-element-perf.js +171 -0
- package/dist/lib/performance/frontend/next-fetch-waterfall.js +346 -29
- package/dist/lib/performance/frontend/rxjs-subscriptions.js +155 -0
- package/dist/lib/performance/frontend/seo/client-fetched-content.js +196 -0
- package/dist/lib/performance/frontend/seo/navigation-without-link.js +116 -0
- package/dist/lib/performance/frontend/seo/next-routes.js +114 -0
- package/dist/lib/performance/frontend/seo/route-metadata.js +158 -0
- package/dist/lib/performance/frontend/seo/seo-rules.js +9 -0
- package/dist/lib/performance/frontend/seo/sitewide-noindex.js +103 -0
- package/dist/lib/performance/frontend/template-tracking.js +86 -2
- package/dist/lib/performance/frontend/vue-options-hooks.js +108 -0
- package/dist/lib/performance/orm/prisma.js +1 -25
- package/dist/lib/performance/projects.js +3 -2
- package/dist/lib/performance/query-loops/service-loops.js +38 -8
- package/dist/lib/performance/request/json-stringify-output.js +82 -4
- package/dist/lib/performance/request/promise-schedulers.js +180 -0
- package/dist/lib/performance/request/request-handlers.js +43 -4
- package/dist/lib/performance/request/unbounded-promise-all.js +13 -52
- package/dist/lib/performance/rule-ids.js +26 -2
- package/dist/lib/performance/site-fix.js +1 -0
- package/dist/lib/reliability/react-bugs.js +9 -0
- package/dist/lib/reliability/react-state-aliases.js +94 -4
- package/dist/lib/reliability/react-state.js +24 -5
- package/dist/lib/security/auth-crypto/secrets.js +121 -16
- package/dist/lib/security/cli.js +1 -1
- package/dist/lib/security/credential-entropy.js +12 -0
- package/dist/lib/security/deps/lockfiles.js +3 -1
- package/dist/lib/security/examples/files.js +110 -0
- package/dist/lib/security/examples/request-forgery.js +1 -1
- package/dist/lib/security/exposure/frontend-security.js +11 -2
- package/dist/lib/security/exposure/prototype-pollution.js +73 -4
- package/dist/lib/security/files/azure-pipelines.js +69 -0
- package/dist/lib/security/files/bitbucket-pipelines.js +32 -0
- package/dist/lib/security/files/ci-platforms.js +16 -0
- package/dist/lib/security/files/ci-shared.js +260 -0
- package/dist/lib/security/files/circleci.js +81 -0
- package/dist/lib/security/files/dockerfile.js +188 -3
- package/dist/lib/security/files/github-actions.js +490 -0
- package/dist/lib/security/files/gitlab-ci.js +90 -0
- package/dist/lib/security/files/hcl.js +264 -0
- package/dist/lib/security/files/hosting-config.js +159 -0
- package/dist/lib/security/files/http-headers.js +65 -0
- package/dist/lib/security/files/index.js +62 -7
- package/dist/lib/security/files/jenkinsfile.js +482 -0
- package/dist/lib/security/files/json-nodes.js +67 -0
- package/dist/lib/security/files/nginx.js +501 -0
- package/dist/lib/security/files/package-scripts.js +175 -0
- package/dist/lib/security/files/rule-ids.js +29 -0
- package/dist/lib/security/files/secret-values.js +31 -5
- package/dist/lib/security/files/secrets.js +44 -13
- package/dist/lib/security/files/terraform.js +345 -0
- package/dist/lib/security/injection/nosql.js +2 -1
- package/dist/lib/security/injection/sql.js +2 -2
- package/dist/lib/security/lexical-declaration.js +28 -0
- package/dist/lib/security/pg-identifier-guards.js +90 -1
- package/dist/lib/security/request-forgery/member-chain.js +41 -0
- package/dist/lib/security/request-forgery/open-redirect.js +45 -8
- package/dist/lib/security/request-forgery/shared.js +18 -3
- package/dist/lib/security/rule-descriptions.js +29 -0
- package/dist/lib/security/rule-ids.js +29 -0
- package/dist/lib/security/taint/original-string-validation.js +229 -0
- package/dist/lib/security/taint/validators.js +1 -1
- package/dist/lib/shared/agent/review-delivery.js +3 -1
- package/dist/lib/shared/analysis/ast-semantics.js +17 -1
- package/dist/lib/shared/analysis/hot-path-graph.js +55 -19
- package/dist/lib/shared/analysis/next-env-config.js +232 -0
- package/dist/lib/shared/analysis/scan-cache-git.js +114 -0
- package/dist/lib/shared/analysis/scan-cache-loadwise-packages.js +54 -0
- package/dist/lib/shared/analysis/scan-cache-project-inputs.js +221 -0
- package/dist/lib/shared/analysis/scan-cache-sources.js +235 -0
- package/dist/lib/shared/analysis/scan-cache-storage.js +24 -0
- package/dist/lib/shared/analysis/scan-cache.js +158 -174
- package/dist/lib/shared/check-watch.js +3 -3
- package/dist/lib/shared/check.js +25 -4
- package/dist/lib/shared/config.js +1 -1
- package/dist/lib/shared/conventional-projects.js +40 -0
- package/dist/lib/shared/fix/fix-command.js +2 -0
- package/dist/lib/shared/fix/fix-usage.js +47 -0
- package/dist/lib/shared/fix/project-file-access.js +43 -20
- package/dist/lib/shared/fix.js +4 -35
- package/dist/lib/shared/formats/security-cwe.js +29 -0
- package/dist/lib/shared/project-root.js +1 -1
- package/dist/lib/shared/reporting/action-comparison.js +78 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +7 -2
- package/dist/lib/shared/reporting/check-text.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +28 -8
- package/dist/lib/shared/reporting/source-report.js +4 -4
- package/dist/lib/shared/system/git.js +31 -16
- package/dist/lib/shared/system/glob.js +146 -19
- package/dist/lib/shared/system/terminal-style.js +2 -2
- package/dist/lib/shared/workspaces.js +6 -1
- package/package.json +4 -1
- package/schema/loadwise.config.schema.json +86 -0
|
@@ -2,12 +2,41 @@
|
|
|
2
2
|
// from the compiler.
|
|
3
3
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
4
4
|
export default {
|
|
5
|
+
'azure-pipelines-script-injection': { needs: 'syntax' },
|
|
6
|
+
'bitbucket-pipelines-script-injection': { needs: 'syntax' },
|
|
7
|
+
'bitbucket-pipelines-unpinned-image': { needs: 'syntax' },
|
|
8
|
+
'circleci-script-injection': { needs: 'syntax' },
|
|
9
|
+
'circleci-unpinned-image': { needs: 'syntax' },
|
|
10
|
+
'circleci-unpinned-orb': { needs: 'syntax' },
|
|
5
11
|
'committed-secret': { needs: 'syntax' },
|
|
6
12
|
'compose-hardcoded-secret': { needs: 'syntax' },
|
|
13
|
+
'config-cors-credentials-any-origin': { needs: 'syntax' },
|
|
14
|
+
'config-unsafe-security-header': { needs: 'syntax' },
|
|
7
15
|
'dockerfile-add-remote-url': { needs: 'syntax' },
|
|
16
|
+
'dockerfile-npm-install': { needs: 'syntax' },
|
|
8
17
|
'dockerfile-runs-as-root': { needs: 'syntax' },
|
|
9
18
|
'dockerfile-secret-in-build': { needs: 'syntax' },
|
|
10
19
|
'dockerfile-unpinned-base-image': { needs: 'syntax' },
|
|
20
|
+
'github-actions-pull-request-target-checkout': { needs: 'syntax' },
|
|
21
|
+
'github-actions-script-injection': { needs: 'syntax' },
|
|
22
|
+
'github-actions-unpinned-action': { needs: 'syntax' },
|
|
23
|
+
'gitlab-ci-script-injection': { needs: 'syntax' },
|
|
24
|
+
'gitlab-ci-unpinned-image': { needs: 'syntax' },
|
|
25
|
+
'gitlab-ci-unpinned-include': { needs: 'syntax' },
|
|
26
|
+
'hosting-redirect-external-wildcard': { needs: 'syntax' },
|
|
27
|
+
'jenkinsfile-credential-interpolation': { needs: 'syntax' },
|
|
28
|
+
'jenkinsfile-script-injection': { needs: 'syntax' },
|
|
11
29
|
'kubernetes-privileged-container': { needs: 'syntax' },
|
|
30
|
+
'nginx-proxy-pass-request-host': { needs: 'syntax' },
|
|
31
|
+
'package-script-remote-code': { needs: 'syntax' },
|
|
32
|
+
'package-script-tls-verification-disabled': { needs: 'syntax' },
|
|
12
33
|
'template-raw-html-binding': { needs: 'syntax' },
|
|
34
|
+
'terraform-admin-port-open-to-world': { needs: 'syntax' },
|
|
35
|
+
'terraform-database-publicly-accessible': { needs: 'syntax' },
|
|
36
|
+
'terraform-hardcoded-credential': { needs: 'syntax' },
|
|
37
|
+
'terraform-storage-bucket-public': { needs: 'syntax' },
|
|
38
|
+
'terraform-storage-encryption-disabled': { needs: 'syntax' },
|
|
39
|
+
'web-server-directory-listing': { needs: 'syntax' },
|
|
40
|
+
'web-server-legacy-tls': { needs: 'syntax' },
|
|
41
|
+
'web-server-version-exposed': { needs: 'syntax' },
|
|
13
42
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// What counts as a secret-looking key and a real (non-placeholder) value, shared by .env,
|
|
2
2
|
// Dockerfile and compose checks.
|
|
3
|
+
import { shannonEntropy } from '../credential-entropy.js';
|
|
3
4
|
const secretWords = new Set(['SECRET', 'TOKEN', 'PASSWORD', 'PASSWD', 'APIKEY', 'CREDENTIALS']);
|
|
4
5
|
const secretWordPairs = new Set(['API_KEY', 'PRIVATE_KEY', 'ACCESS_KEY', 'SECRET_KEY']);
|
|
5
6
|
// A trailing word like these means the key holds a setting about a secret, not the secret itself.
|
|
@@ -74,6 +75,31 @@ function isPlaceholderValue(value, key = '') {
|
|
|
74
75
|
}
|
|
75
76
|
return key !== '' && stripKey(trimmed) === stripKey(key);
|
|
76
77
|
}
|
|
78
|
+
// Templates commonly contain illustrative values. Require substantially more evidence than a secret-like key.
|
|
79
|
+
const minimumTemplateSecretLength = 24;
|
|
80
|
+
const randomTextEntropy = 4.3;
|
|
81
|
+
const hexEntropy = 3.5;
|
|
82
|
+
const sampleSequences = ['0123456789abcdef', 'abcdefghijklmnopqrstuvwxyz', '0123456789'];
|
|
83
|
+
function isSequentialSample(value) {
|
|
84
|
+
const lower = value.toLowerCase();
|
|
85
|
+
return sampleSequences.some((sequence) => {
|
|
86
|
+
const start = sequence.indexOf(lower[0]);
|
|
87
|
+
if (start < 0)
|
|
88
|
+
return false;
|
|
89
|
+
const repeated = sequence.repeat(Math.ceil((start + lower.length) / sequence.length));
|
|
90
|
+
return repeated.startsWith(lower, start);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function isStrongTemplateSecret(value, key = '') {
|
|
94
|
+
if (value.length < minimumTemplateSecretLength ||
|
|
95
|
+
/\s|:\/\//.test(value) ||
|
|
96
|
+
isPlaceholderValue(value, key) ||
|
|
97
|
+
isSequentialSample(value))
|
|
98
|
+
return false;
|
|
99
|
+
if (/^[0-9a-f]{32,}$/i.test(value))
|
|
100
|
+
return shannonEntropy(value) >= hexEntropy;
|
|
101
|
+
return shannonEntropy(value) >= randomTextEntropy;
|
|
102
|
+
}
|
|
77
103
|
// Sample tokens in docs and tests: documented examples, repeated filler, an obvious placeholder, or
|
|
78
104
|
// words only (a random token body of this length always contains a digit).
|
|
79
105
|
function looksLikeSampleToken(token) {
|
|
@@ -82,17 +108,17 @@ function looksLikeSampleToken(token) {
|
|
|
82
108
|
}
|
|
83
109
|
// { local } for a URL that embeds a non-placeholder password; local is true for default credentials
|
|
84
110
|
// on a local host.
|
|
85
|
-
function urlCredentials(value) {
|
|
111
|
+
function urlCredentials(value, strongOnly = false) {
|
|
86
112
|
const match = credentialedUrl.exec(value.trim());
|
|
87
113
|
if (!match)
|
|
88
114
|
return undefined;
|
|
89
115
|
const [, user, password, host] = match;
|
|
90
116
|
const knownDefault = isDefaultPassword(password);
|
|
91
|
-
if (!knownDefault && isPlaceholderValue(password))
|
|
92
|
-
return
|
|
93
|
-
return { local: localHosts.has(host.toLowerCase()) && (knownDefault || user === password) };
|
|
117
|
+
if (strongOnly ? !isStrongTemplateSecret(password) : !knownDefault && isPlaceholderValue(password))
|
|
118
|
+
return;
|
|
119
|
+
return { local: !strongOnly && localHosts.has(host.toLowerCase()) && (knownDefault || user === password) };
|
|
94
120
|
}
|
|
95
121
|
function redactedPrefix(value) {
|
|
96
122
|
return value.slice(0, 4) + '…';
|
|
97
123
|
}
|
|
98
|
-
export { isDefaultPassword, isSecretKey, isPlaceholderValue, looksLikeSampleToken, urlCredentials, redactedPrefix };
|
|
124
|
+
export { isDefaultPassword, isSecretKey, isPlaceholderValue, isStrongTemplateSecret, looksLikeSampleToken, urlCredentials, redactedPrefix, };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// committed-secret: credentials in tracked files. Messages name the key and a four-character
|
|
2
2
|
// prefix, never the value.
|
|
3
3
|
import { testPathKind } from '../../shared/analysis/execution-context.js';
|
|
4
|
+
import { isRecord } from '../../shared/system/is-record.js';
|
|
4
5
|
import { providerCredentialFormats } from '../provider-credentials.js';
|
|
5
|
-
import { isDefaultPassword, isSecretKey, isPlaceholderValue, looksLikeSampleToken, urlCredentials, redactedPrefix, } from './secret-values.js';
|
|
6
|
+
import { isDefaultPassword, isSecretKey, isPlaceholderValue, isStrongTemplateSecret, looksLikeSampleToken, urlCredentials, redactedPrefix, } from './secret-values.js';
|
|
6
7
|
import { isEnvFileName } from './project-files.js';
|
|
7
8
|
const ruleId = 'committed-secret';
|
|
8
9
|
const templateEnvSuffix = /\.(?:example|sample|template|dist)$/i;
|
|
@@ -14,6 +15,9 @@ const envLine = /^\s*(?:export\s+)?([A-Za-z_][\w.]*)\s*=\s*(.*)$/;
|
|
|
14
15
|
const localCredentialsReason = 'Default credentials for a local service.';
|
|
15
16
|
const testEnvReason = 'Test environment file.';
|
|
16
17
|
const developmentEnvReason = 'Local development environment file.';
|
|
18
|
+
const googleApiKey = 'Google API key';
|
|
19
|
+
const firebaseClientConfig = /^(?:VITE|NEXT_PUBLIC|REACT_APP|PUBLIC)_(?:APP_)?FIREBASE_CONFIG$/;
|
|
20
|
+
const firebaseWebReason = 'Firebase Web client configuration. Verify the key is restricted to Firebase services.';
|
|
17
21
|
// High-confidence formats only: each has a fixed prefix and a fixed or long random body.
|
|
18
22
|
const tokenFormats = [
|
|
19
23
|
{ label: 'AWS access key id', pattern: /(?<![A-Za-z0-9])AKIA[0-9A-Z]{16}(?![A-Za-z0-9])/g },
|
|
@@ -21,7 +25,7 @@ const tokenFormats = [
|
|
|
21
25
|
{ label: 'GitHub token', pattern: /(?<![A-Za-z0-9_])github_pat_[A-Za-z0-9_]{22,}(?![A-Za-z0-9_])/g },
|
|
22
26
|
{ label: 'Slack token', pattern: /(?<![A-Za-z0-9])xox[bp]-[0-9A-Za-z-]{10,}/g },
|
|
23
27
|
{ label: 'Stripe live secret key', pattern: /(?<![A-Za-z0-9_])sk_live_[0-9A-Za-z]{24,}(?![A-Za-z0-9])/g },
|
|
24
|
-
{ label:
|
|
28
|
+
{ label: googleApiKey, pattern: /(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g },
|
|
25
29
|
...providerCredentialFormats,
|
|
26
30
|
];
|
|
27
31
|
// A header alone appears in code that parses keys; a base64 body after it is a real key.
|
|
@@ -38,7 +42,7 @@ const tokenSearchPattern = [
|
|
|
38
42
|
'-----BEGIN [A-Z ]*PRIVATE KEY-----',
|
|
39
43
|
...providerCredentialFormats.map(({ body }) => body),
|
|
40
44
|
].join('|');
|
|
41
|
-
function tokenFindings(line, lineNumber) {
|
|
45
|
+
function tokenFindings(line, lineNumber, firebaseKey) {
|
|
42
46
|
const found = [];
|
|
43
47
|
for (const format of tokenFormats) {
|
|
44
48
|
const isPlaceholder = format.isPlaceholder ?? looksLikeSampleToken;
|
|
@@ -49,6 +53,7 @@ function tokenFindings(line, lineNumber) {
|
|
|
49
53
|
line: lineNumber,
|
|
50
54
|
column: match.index + 1,
|
|
51
55
|
message: `${format.label} (${redactedPrefix(match[0])}) is stored in a project file.`,
|
|
56
|
+
...(format.label === googleApiKey && match[0] === firebaseKey && { contextualReason: firebaseWebReason }),
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -80,21 +85,45 @@ function unquote(rawValue) {
|
|
|
80
85
|
}
|
|
81
86
|
return trimmed.replace(/\s+#.*$/, '');
|
|
82
87
|
}
|
|
83
|
-
function
|
|
88
|
+
function firebaseBrowserApiKey(line) {
|
|
89
|
+
const entry = envLine.exec(line);
|
|
90
|
+
if (!entry || !firebaseClientConfig.test(entry[1]))
|
|
91
|
+
return;
|
|
92
|
+
let config;
|
|
93
|
+
try {
|
|
94
|
+
config = JSON.parse(unquote(entry[2]));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!isRecord(config))
|
|
100
|
+
return;
|
|
101
|
+
const { apiKey, appId, authDomain, projectId } = config;
|
|
102
|
+
if (typeof apiKey !== 'string' || typeof appId !== 'string' || !/^1:\d+:web:[a-f0-9]+$/i.test(appId))
|
|
103
|
+
return;
|
|
104
|
+
if (typeof projectId !== 'string' || !/^[a-z0-9-]+$/.test(projectId))
|
|
105
|
+
return;
|
|
106
|
+
if (authDomain !== `${projectId}.firebaseapp.com` && authDomain !== `${projectId}.web.app`)
|
|
107
|
+
return;
|
|
108
|
+
const first = line.indexOf(apiKey);
|
|
109
|
+
if (first !== -1 && first === line.lastIndexOf(apiKey))
|
|
110
|
+
return apiKey;
|
|
111
|
+
}
|
|
112
|
+
function envEntryFinding(line, lineNumber, fileReason, template) {
|
|
84
113
|
const match = envLine.exec(line);
|
|
85
114
|
if (!match)
|
|
86
115
|
return undefined;
|
|
87
116
|
const [, key, rawValue] = match;
|
|
88
117
|
const value = unquote(rawValue);
|
|
89
|
-
const credentials = urlCredentials(value);
|
|
118
|
+
const credentials = urlCredentials(value, template);
|
|
90
119
|
const isDefault = credentials?.local || isDefaultPassword(value);
|
|
91
120
|
const contextualReason = isDefault ? localCredentialsReason : fileReason;
|
|
92
121
|
const base = { line: lineNumber, column: 1, ...(contextualReason && { contextualReason }) };
|
|
93
122
|
if (credentials) {
|
|
94
123
|
return { ...base, message: `Tracked env file embeds credentials in "${key}" (starts "${redactedPrefix(value)}").` };
|
|
95
124
|
}
|
|
96
|
-
if (!isSecretKey(key) || isPlaceholderValue(value, key))
|
|
97
|
-
return
|
|
125
|
+
if (!isSecretKey(key) || (template ? !isStrongTemplateSecret(value, key) : isPlaceholderValue(value, key)))
|
|
126
|
+
return;
|
|
98
127
|
return { ...base, message: `Tracked env file holds a value for "${key}" (starts "${redactedPrefix(value)}").` };
|
|
99
128
|
}
|
|
100
129
|
function fileContextReason(baseName, text, readsEntries) {
|
|
@@ -103,22 +132,24 @@ function fileContextReason(baseName, text, readsEntries) {
|
|
|
103
132
|
return readsEntries && developmentEnvironment.test(text) ? developmentEnvReason : undefined;
|
|
104
133
|
}
|
|
105
134
|
// Provider-format tokens stay at default level in test and dev files: leaked live credentials are
|
|
106
|
-
// common there.
|
|
107
|
-
//
|
|
135
|
+
// common there. A Firebase Web configuration can identify its client key, whose API restrictions
|
|
136
|
+
// still need review. Env templates only flag provider tokens and strong generic credentials.
|
|
108
137
|
function checkSecrets(file, text) {
|
|
109
138
|
const baseName = file.split('/').at(-1) ?? '';
|
|
110
|
-
const readsEntries = isEnvFileName(baseName)
|
|
111
|
-
const
|
|
139
|
+
const readsEntries = isEnvFileName(baseName);
|
|
140
|
+
const template = readsEntries && templateEnvSuffix.test(baseName);
|
|
141
|
+
const fileReason = fileContextReason(baseName, text, readsEntries && !template);
|
|
112
142
|
const keyBlocks = privateKeyFindings(text).map((finding) => ({
|
|
113
143
|
...(fileReason && { contextualReason: fileReason }),
|
|
114
144
|
...finding,
|
|
115
145
|
}));
|
|
116
146
|
const findings = [...keyBlocks];
|
|
117
147
|
text.split(/\r?\n/).forEach((line, index) => {
|
|
118
|
-
const
|
|
148
|
+
const firebaseKey = readsEntries && !template && line.includes('AIza') ? firebaseBrowserApiKey(line) : undefined;
|
|
149
|
+
const tokens = tokenFindings(line, index + 1, firebaseKey);
|
|
119
150
|
if (tokens.length)
|
|
120
151
|
return findings.push(...tokens);
|
|
121
|
-
const entry = readsEntries && envEntryFinding(line, index + 1, fileReason);
|
|
152
|
+
const entry = readsEntries && envEntryFinding(line, index + 1, fileReason, template);
|
|
122
153
|
if (entry)
|
|
123
154
|
findings.push(entry);
|
|
124
155
|
});
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// Terraform checks for *.tf files: firewall rules that open an administration or database port to
|
|
2
|
+
// the whole internet, public storage buckets, publicly reachable databases, encryption explicitly
|
|
3
|
+
// turned off, and literal credentials. Only literal values count; references, variables and
|
|
4
|
+
// interpolated strings are skipped because their value is not known from the file.
|
|
5
|
+
import { parseHcl } from './hcl.js';
|
|
6
|
+
import { isPlaceholderValue, isSecretKey, redactedPrefix } from './secret-values.js';
|
|
7
|
+
const terraformName = /\.tf$/i;
|
|
8
|
+
const adminPorts = [
|
|
9
|
+
[22, 'SSH'],
|
|
10
|
+
[1433, 'SQL Server'],
|
|
11
|
+
[1521, 'Oracle'],
|
|
12
|
+
[3306, 'MySQL'],
|
|
13
|
+
[3389, 'RDP'],
|
|
14
|
+
[5432, 'PostgreSQL'],
|
|
15
|
+
[6379, 'Redis'],
|
|
16
|
+
[27017, 'MongoDB'],
|
|
17
|
+
];
|
|
18
|
+
const highestPort = 65535;
|
|
19
|
+
const worldCidrs = new Set(['0.0.0.0/0', '::/0']);
|
|
20
|
+
const azureAnySource = new Set(['*', '0.0.0.0/0', '::/0', 'internet', 'any']);
|
|
21
|
+
const awsAllProtocols = new Set(['-1', 'all']);
|
|
22
|
+
const awsTcpProtocols = new Set(['tcp', '6']);
|
|
23
|
+
const publicAcls = new Set(['public-read', 'public-read-write', 'authenticated-read']);
|
|
24
|
+
const publicAccessBlockSettings = [
|
|
25
|
+
'block_public_acls',
|
|
26
|
+
'block_public_policy',
|
|
27
|
+
'ignore_public_acls',
|
|
28
|
+
'restrict_public_buckets',
|
|
29
|
+
];
|
|
30
|
+
const gcsPublicMembers = new Set(['allusers', 'allauthenticatedusers']);
|
|
31
|
+
const gcsAccessControls = new Set([
|
|
32
|
+
'google_storage_bucket_access_control',
|
|
33
|
+
'google_storage_default_object_access_control',
|
|
34
|
+
'google_storage_object_access_control',
|
|
35
|
+
]);
|
|
36
|
+
const publicDatabaseTypes = new Set([
|
|
37
|
+
'aws_db_instance',
|
|
38
|
+
'aws_dms_replication_instance',
|
|
39
|
+
'aws_rds_cluster_instance',
|
|
40
|
+
'aws_redshift_cluster',
|
|
41
|
+
]);
|
|
42
|
+
const azureDatabaseFirewall = /^azurerm_(?:mssql|sql|postgresql|postgresql_flexible_server|mysql|mysql_flexible_server|mariadb)_firewall_rule$/;
|
|
43
|
+
const encryptionSwitches = new Set(['encrypted', 'storage_encrypted', 'at_rest_encryption_enabled']);
|
|
44
|
+
// Resource and module arguments that hold a credential, besides any name ending in _password or
|
|
45
|
+
// _secret; provider arguments use isSecretKey instead.
|
|
46
|
+
const credentialArguments = new Set([
|
|
47
|
+
'admin_password',
|
|
48
|
+
'administrator_login_password',
|
|
49
|
+
'api_key',
|
|
50
|
+
'api_token',
|
|
51
|
+
'auth_token',
|
|
52
|
+
'client_secret',
|
|
53
|
+
'master_password',
|
|
54
|
+
'password',
|
|
55
|
+
'root_password',
|
|
56
|
+
'secret_key',
|
|
57
|
+
'secret_string',
|
|
58
|
+
]);
|
|
59
|
+
function isCredentialArgument(name) {
|
|
60
|
+
return credentialArguments.has(name) || /_(?:password|secret)$/.test(name);
|
|
61
|
+
}
|
|
62
|
+
function isTerraformFile(file) {
|
|
63
|
+
return terraformName.test(file.split(/[\\/]/).at(-1) ?? '');
|
|
64
|
+
}
|
|
65
|
+
function literalString(value) {
|
|
66
|
+
return value?.kind === 'string' && value.literal ? value.value : undefined;
|
|
67
|
+
}
|
|
68
|
+
function literalStrings(value) {
|
|
69
|
+
if (value?.kind === 'list')
|
|
70
|
+
return value.items.flatMap((item) => literalStrings(item));
|
|
71
|
+
const text = literalString(value);
|
|
72
|
+
return text === undefined ? [] : [text];
|
|
73
|
+
}
|
|
74
|
+
function literalNumber(value) {
|
|
75
|
+
if (value?.kind === 'number')
|
|
76
|
+
return value.value;
|
|
77
|
+
const text = literalString(value);
|
|
78
|
+
return text !== undefined && /^-?\d+$/.test(text) ? Number(text) : undefined;
|
|
79
|
+
}
|
|
80
|
+
function literalBool(value) {
|
|
81
|
+
if (value?.kind === 'bool')
|
|
82
|
+
return value.value;
|
|
83
|
+
const text = literalString(value);
|
|
84
|
+
return text === 'true' || text === 'false' ? text === 'true' : undefined;
|
|
85
|
+
}
|
|
86
|
+
function attribute(block, name) {
|
|
87
|
+
return block.attributes.get(name);
|
|
88
|
+
}
|
|
89
|
+
function childBlocks(block, type) {
|
|
90
|
+
return block.blocks.filter((child) => child.type === type);
|
|
91
|
+
}
|
|
92
|
+
function portsIn(from, to) {
|
|
93
|
+
return adminPorts.filter(([port]) => port >= from && port <= to).map(([port, name]) => `${port} (${name})`);
|
|
94
|
+
}
|
|
95
|
+
// "22", "1000-2000" or "*" as an inclusive port range.
|
|
96
|
+
function portRange(text) {
|
|
97
|
+
if (text === '*')
|
|
98
|
+
return [0, highestPort];
|
|
99
|
+
const match = /^(\d+)(?:-(\d+))?$/.exec(text.trim());
|
|
100
|
+
return match ? [Number(match[1]), Number(match[2] ?? match[1])] : undefined;
|
|
101
|
+
}
|
|
102
|
+
function openPortFinding(at, resource, ports) {
|
|
103
|
+
return {
|
|
104
|
+
ruleId: 'terraform-admin-port-open-to-world',
|
|
105
|
+
line: at.line,
|
|
106
|
+
column: at.column,
|
|
107
|
+
message: `${resource} allows inbound traffic from any address to port ${ports.join(', ')}. Restrict the source to known networks, or reach the host through a bastion, VPN or session manager.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// AWS ingress: an inline ingress block, an aws_security_group_rule or an
|
|
111
|
+
// aws_vpc_security_group_ingress_rule.
|
|
112
|
+
function awsIngressFinding(rule, resource, protocolName, cidrNames) {
|
|
113
|
+
const protocol = literalString(rule.attributes.get(protocolName)?.value) ??
|
|
114
|
+
literalNumber(rule.attributes.get(protocolName)?.value)?.toString();
|
|
115
|
+
if (protocol === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
const world = cidrNames
|
|
118
|
+
.map((name) => attribute(rule, name))
|
|
119
|
+
.find((at) => at && literalStrings(at.value).some((cidr) => worldCidrs.has(cidr)));
|
|
120
|
+
if (!world)
|
|
121
|
+
return undefined;
|
|
122
|
+
let ports;
|
|
123
|
+
if (awsAllProtocols.has(protocol.toLowerCase()))
|
|
124
|
+
ports = portsIn(0, highestPort);
|
|
125
|
+
else if (awsTcpProtocols.has(protocol.toLowerCase())) {
|
|
126
|
+
const from = literalNumber(attribute(rule, 'from_port')?.value);
|
|
127
|
+
const to = literalNumber(attribute(rule, 'to_port')?.value);
|
|
128
|
+
if (from === undefined || to === undefined)
|
|
129
|
+
return undefined;
|
|
130
|
+
ports = portsIn(from, to);
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
return undefined;
|
|
134
|
+
return ports.length ? openPortFinding(world, resource, ports) : undefined;
|
|
135
|
+
}
|
|
136
|
+
function addPortRanges(ports, texts) {
|
|
137
|
+
for (const text of texts) {
|
|
138
|
+
const range = portRange(text);
|
|
139
|
+
if (range)
|
|
140
|
+
for (const port of portsIn(...range))
|
|
141
|
+
ports.add(port);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function gcpFirewallFinding(firewall, resource) {
|
|
145
|
+
const direction = literalString(attribute(firewall, 'direction')?.value);
|
|
146
|
+
if (direction !== undefined && direction.toUpperCase() !== 'INGRESS')
|
|
147
|
+
return undefined;
|
|
148
|
+
const sources = attribute(firewall, 'source_ranges');
|
|
149
|
+
if (!sources || !literalStrings(sources.value).some((cidr) => worldCidrs.has(cidr)))
|
|
150
|
+
return undefined;
|
|
151
|
+
const ports = new Set();
|
|
152
|
+
for (const allow of childBlocks(firewall, 'allow')) {
|
|
153
|
+
const protocol = literalString(attribute(allow, 'protocol')?.value)?.toLowerCase();
|
|
154
|
+
if (protocol !== 'tcp' && protocol !== 'all')
|
|
155
|
+
continue;
|
|
156
|
+
const portList = attribute(allow, 'ports');
|
|
157
|
+
if (!portList) {
|
|
158
|
+
for (const port of portsIn(0, highestPort))
|
|
159
|
+
ports.add(port);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
addPortRanges(ports, literalStrings(portList.value));
|
|
163
|
+
}
|
|
164
|
+
return ports.size ? openPortFinding(sources, resource, [...ports]) : undefined;
|
|
165
|
+
}
|
|
166
|
+
function azureRuleFinding(rule, resource) {
|
|
167
|
+
const lower = (name) => literalString(attribute(rule, name)?.value)?.toLowerCase();
|
|
168
|
+
if (lower('direction') !== 'inbound' || lower('access') !== 'allow')
|
|
169
|
+
return undefined;
|
|
170
|
+
const protocol = lower('protocol');
|
|
171
|
+
if (protocol !== 'tcp' && protocol !== '*')
|
|
172
|
+
return undefined;
|
|
173
|
+
const source = ['source_address_prefix', 'source_address_prefixes']
|
|
174
|
+
.map((name) => attribute(rule, name))
|
|
175
|
+
.find((at) => at && literalStrings(at.value).some((prefix) => azureAnySource.has(prefix.toLowerCase())));
|
|
176
|
+
if (!source)
|
|
177
|
+
return undefined;
|
|
178
|
+
const ports = new Set();
|
|
179
|
+
for (const name of ['destination_port_range', 'destination_port_ranges'])
|
|
180
|
+
addPortRanges(ports, literalStrings(attribute(rule, name)?.value));
|
|
181
|
+
return ports.size ? openPortFinding(source, resource, [...ports]) : undefined;
|
|
182
|
+
}
|
|
183
|
+
function openPortFindings(resource, type, name) {
|
|
184
|
+
const label = `${type}.${name}`;
|
|
185
|
+
switch (type) {
|
|
186
|
+
case 'aws_security_group':
|
|
187
|
+
case 'aws_default_security_group':
|
|
188
|
+
return childBlocks(resource, 'ingress').map((rule) => awsIngressFinding(rule, label, 'protocol', ['cidr_blocks', 'ipv6_cidr_blocks']));
|
|
189
|
+
case 'aws_security_group_rule':
|
|
190
|
+
return literalString(attribute(resource, 'type')?.value) === 'ingress'
|
|
191
|
+
? [awsIngressFinding(resource, label, 'protocol', ['cidr_blocks', 'ipv6_cidr_blocks'])]
|
|
192
|
+
: [];
|
|
193
|
+
case 'aws_vpc_security_group_ingress_rule':
|
|
194
|
+
return [awsIngressFinding(resource, label, 'ip_protocol', ['cidr_ipv4', 'cidr_ipv6'])];
|
|
195
|
+
case 'google_compute_firewall':
|
|
196
|
+
return [gcpFirewallFinding(resource, label)];
|
|
197
|
+
case 'azurerm_network_security_rule':
|
|
198
|
+
return [azureRuleFinding(resource, label)];
|
|
199
|
+
case 'azurerm_network_security_group':
|
|
200
|
+
return childBlocks(resource, 'security_rule').map((rule) => azureRuleFinding(rule, label));
|
|
201
|
+
default:
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function publicStorage(at, label, detail, consequence = 'anyone on the internet can read its objects') {
|
|
206
|
+
if (!at)
|
|
207
|
+
return [];
|
|
208
|
+
return [
|
|
209
|
+
{
|
|
210
|
+
ruleId: 'terraform-storage-bucket-public',
|
|
211
|
+
line: at.line,
|
|
212
|
+
column: at.column,
|
|
213
|
+
message: `${label} ${detail}, so ${consequence}. Keep the bucket private and serve public files through a CDN or signed URLs.`,
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
function publicStorageFindings(resource, type, name) {
|
|
218
|
+
const label = `${type}.${name}`;
|
|
219
|
+
if (type === 'aws_s3_bucket' || type === 'aws_s3_bucket_acl') {
|
|
220
|
+
const acl = attribute(resource, 'acl');
|
|
221
|
+
const value = literalString(acl?.value);
|
|
222
|
+
return value && publicAcls.has(value) ? publicStorage(acl, label, `grants the "${value}" canned ACL`) : [];
|
|
223
|
+
}
|
|
224
|
+
if (type === 'aws_s3_bucket_public_access_block' || type === 'aws_s3_account_public_access_block') {
|
|
225
|
+
const disabled = publicAccessBlockSettings
|
|
226
|
+
.map((setting) => attribute(resource, setting))
|
|
227
|
+
.filter((at) => at !== undefined && literalBool(at.value) === false);
|
|
228
|
+
return disabled.length
|
|
229
|
+
? publicStorage(disabled[0], label, `turns off ${disabled.map((at) => at.name).join(', ')}`, 'a public ACL or bucket policy is no longer blocked and can expose its objects')
|
|
230
|
+
: [];
|
|
231
|
+
}
|
|
232
|
+
if (type === 'google_storage_bucket_iam_member' || type === 'google_storage_bucket_iam_binding') {
|
|
233
|
+
const members = attribute(resource, type.endsWith('member') ? 'member' : 'members');
|
|
234
|
+
const member = literalStrings(members?.value).find((value) => gcsPublicMembers.has(value.toLowerCase()));
|
|
235
|
+
return member ? publicStorage(members, label, `grants a role to ${member}`) : [];
|
|
236
|
+
}
|
|
237
|
+
if (gcsAccessControls.has(type)) {
|
|
238
|
+
const entity = attribute(resource, 'entity');
|
|
239
|
+
const value = literalString(entity?.value);
|
|
240
|
+
return value && gcsPublicMembers.has(value.toLowerCase())
|
|
241
|
+
? publicStorage(entity, label, `grants access to ${value}`)
|
|
242
|
+
: [];
|
|
243
|
+
}
|
|
244
|
+
if (type === 'azurerm_storage_container') {
|
|
245
|
+
const access = attribute(resource, 'container_access_type');
|
|
246
|
+
const value = literalString(access?.value);
|
|
247
|
+
return value === 'blob' || value === 'container'
|
|
248
|
+
? publicStorage(access, label, `sets anonymous "${value}" access`)
|
|
249
|
+
: [];
|
|
250
|
+
}
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
function publicDatabase(at, label, detail) {
|
|
254
|
+
return {
|
|
255
|
+
ruleId: 'terraform-database-publicly-accessible',
|
|
256
|
+
line: at.line,
|
|
257
|
+
column: at.column,
|
|
258
|
+
message: `${label} ${detail}. Keep the database on private subnets and connect through the application network, a VPN or a bastion.`,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function publicDatabaseFindings(resource, type, name) {
|
|
262
|
+
const label = `${type}.${name}`;
|
|
263
|
+
if (publicDatabaseTypes.has(type)) {
|
|
264
|
+
const flag = attribute(resource, 'publicly_accessible');
|
|
265
|
+
return flag && literalBool(flag.value) === true ? [publicDatabase(flag, label, 'is publicly accessible')] : [];
|
|
266
|
+
}
|
|
267
|
+
if (type === 'google_sql_database_instance') {
|
|
268
|
+
return childBlocks(resource, 'settings')
|
|
269
|
+
.flatMap((settings) => childBlocks(settings, 'ip_configuration'))
|
|
270
|
+
.flatMap((ipConfiguration) => childBlocks(ipConfiguration, 'authorized_networks'))
|
|
271
|
+
.map((network) => attribute(network, 'value'))
|
|
272
|
+
.filter((at) => at !== undefined && worldCidrs.has(literalString(at.value) ?? ''))
|
|
273
|
+
.map((at) => publicDatabase(at, label, 'authorizes connections from any address'));
|
|
274
|
+
}
|
|
275
|
+
if (azureDatabaseFirewall.test(type)) {
|
|
276
|
+
const start = attribute(resource, 'start_ip_address');
|
|
277
|
+
const end = literalString(attribute(resource, 'end_ip_address')?.value);
|
|
278
|
+
return start && literalString(start.value) === '0.0.0.0' && end === '255.255.255.255'
|
|
279
|
+
? [publicDatabase(start, label, 'allows connections from every IPv4 address')]
|
|
280
|
+
: [];
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
// Every block of a resource, depth first, so nested block devices are included.
|
|
285
|
+
function* allBlocks(block) {
|
|
286
|
+
yield block;
|
|
287
|
+
for (const child of block.blocks)
|
|
288
|
+
yield* allBlocks(child);
|
|
289
|
+
}
|
|
290
|
+
function encryptionFindings(resource, type, name) {
|
|
291
|
+
if (type === 'aws_ebs_encryption_by_default') {
|
|
292
|
+
const enabled = attribute(resource, 'enabled');
|
|
293
|
+
return enabled && literalBool(enabled.value) === false ? [encryptionFinding(enabled, `${type}.${name}`)] : [];
|
|
294
|
+
}
|
|
295
|
+
if (!type.startsWith('aws_'))
|
|
296
|
+
return [];
|
|
297
|
+
return [...allBlocks(resource)].flatMap((block) => [...block.attributes.values()]
|
|
298
|
+
.filter((at) => encryptionSwitches.has(at.name) && literalBool(at.value) === false)
|
|
299
|
+
.map((at) => encryptionFinding(at, `${type}.${name}`)));
|
|
300
|
+
}
|
|
301
|
+
function encryptionFinding(at, label) {
|
|
302
|
+
return {
|
|
303
|
+
ruleId: 'terraform-storage-encryption-disabled',
|
|
304
|
+
line: at.line,
|
|
305
|
+
column: at.column,
|
|
306
|
+
message: `${label} sets ${at.name} = false, so its data is stored unencrypted at rest. Enable encryption, optionally with a customer-managed KMS key.`,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function credentialFindings(block, label, isCredential) {
|
|
310
|
+
return [...allBlocks(block)].flatMap((inner) => [...inner.attributes.values()].flatMap((at) => {
|
|
311
|
+
const value = literalString(at.value);
|
|
312
|
+
if (value === undefined || !isCredential(at.name) || /:\/\//.test(value) || isPlaceholderValue(value, at.name))
|
|
313
|
+
return [];
|
|
314
|
+
return [
|
|
315
|
+
{
|
|
316
|
+
ruleId: 'terraform-hardcoded-credential',
|
|
317
|
+
line: at.line,
|
|
318
|
+
column: at.column,
|
|
319
|
+
message: `${label} sets ${at.name} to a literal value (starts "${redactedPrefix(value)}"). Pass it through a sensitive variable, an environment variable or a secret manager, and rotate the committed value.`,
|
|
320
|
+
},
|
|
321
|
+
];
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
function blockFindings(block) {
|
|
325
|
+
const [type = '', name = ''] = block.labels;
|
|
326
|
+
if (block.type === 'provider')
|
|
327
|
+
return credentialFindings(block, `provider "${type}"`, isSecretKey);
|
|
328
|
+
if (block.type === 'module')
|
|
329
|
+
return credentialFindings(block, `module "${type}"`, isCredentialArgument);
|
|
330
|
+
if (block.type !== 'resource')
|
|
331
|
+
return [];
|
|
332
|
+
return [
|
|
333
|
+
...openPortFindings(block, type, name),
|
|
334
|
+
...publicStorageFindings(block, type, name),
|
|
335
|
+
...publicDatabaseFindings(block, type, name),
|
|
336
|
+
...encryptionFindings(block, type, name),
|
|
337
|
+
...credentialFindings(block, `${type}.${name}`, isCredentialArgument),
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
function checkTerraform(text) {
|
|
341
|
+
return parseHcl(text)
|
|
342
|
+
.flatMap(blockFindings)
|
|
343
|
+
.filter((finding) => finding !== undefined);
|
|
344
|
+
}
|
|
345
|
+
export { checkTerraform, isTerraformFile };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { ts } from '../../performance/engine/compiler.js';
|
|
5
5
|
import { reportTraced, methodName, createdBy, calledExport, initializerOf, fieldWritesOf } from './shared.js';
|
|
6
6
|
import { isProjectSource, returnedExpressions } from '../taint/summaries.js';
|
|
7
|
+
import { validatesOriginalString } from '../taint/original-string-validation.js';
|
|
7
8
|
const ruleId = 'nosql-operator-injection';
|
|
8
9
|
const stageAddingMethods = new Set(['push', 'unshift']);
|
|
9
10
|
const filterFirstMethods = new Set([
|
|
@@ -217,7 +218,7 @@ function reportValue(node, context, contextualReason) {
|
|
|
217
218
|
if (ts.isObjectLiteralExpression(leaf) || ts.isArrayLiteralExpression(leaf))
|
|
218
219
|
continue;
|
|
219
220
|
const trace = context.taint.trace(leaf, 'nosql');
|
|
220
|
-
if (!trace || !isObjectCapable(trace))
|
|
221
|
+
if (!trace || !isObjectCapable(trace) || validatesOriginalString(leaf, context.checker, context.program))
|
|
221
222
|
continue;
|
|
222
223
|
return reportTraced(context, node, ruleId, message(trace.label), trace, contextualReason);
|
|
223
224
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// tell.
|
|
8
8
|
import { ts, isDefaultLibrary } from '../../performance/engine/compiler.js';
|
|
9
9
|
import { analyzeFragment } from '../../performance/datastores/pg-fragments.js';
|
|
10
|
-
import { operandsOf, isValidatedIdentifier } from '../pg-identifier-guards.js';
|
|
10
|
+
import { operandsOf, isFixedMapLookup, isValidatedIdentifier } from '../pg-identifier-guards.js';
|
|
11
11
|
import { declaredPropertyTypeImport } from '../bindings.js';
|
|
12
12
|
import { isPrunedType } from '../taint/sanitizers.js';
|
|
13
13
|
import { assignmentsTo } from '../taint/guards.js';
|
|
@@ -78,7 +78,7 @@ function isFixedPart(part, call, context) {
|
|
|
78
78
|
return true;
|
|
79
79
|
if (ts.isIdentifier(part) && isLiteralLoopElement(part, checker))
|
|
80
80
|
return true;
|
|
81
|
-
if (isFixedPrivateField(part, call, context))
|
|
81
|
+
if (isFixedPrivateField(part, call, context) || isFixedMapLookup(part, checker))
|
|
82
82
|
return true;
|
|
83
83
|
return ts.isIdentifier(part) && isValidatedIdentifier(part, call, checker);
|
|
84
84
|
}
|
|
@@ -111,3 +111,31 @@ export function findLexicalDeclaration(identifier) {
|
|
|
111
111
|
}
|
|
112
112
|
return undefined;
|
|
113
113
|
}
|
|
114
|
+
function declaresVar(list, target) {
|
|
115
|
+
return (list !== undefined &&
|
|
116
|
+
ts.isVariableDeclarationList(list) &&
|
|
117
|
+
!(list.flags & ts.NodeFlags.BlockScoped) &&
|
|
118
|
+
list.declarations.some((decl) => bindingDeclaresName(decl.name, target)));
|
|
119
|
+
}
|
|
120
|
+
// A `var` in a block or loop head belongs to the enclosing function, which finds it through the
|
|
121
|
+
// hoisted-var walk, so the block is not the binding's scope.
|
|
122
|
+
function hoistsOutOf(node, target) {
|
|
123
|
+
if (ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node)) {
|
|
124
|
+
return declaresVar(node.initializer, target);
|
|
125
|
+
}
|
|
126
|
+
const statements = ts.isCaseBlock(node)
|
|
127
|
+
? node.clauses.flatMap((clause) => clause.statements)
|
|
128
|
+
: ts.isBlock(node)
|
|
129
|
+
? node.statements
|
|
130
|
+
: [];
|
|
131
|
+
return statements.some((stmt) => ts.isVariableStatement(stmt) && declaresVar(stmt.declarationList, target));
|
|
132
|
+
}
|
|
133
|
+
// The node whose scope owns the binding `identifier` names, so two identifiers of the same name refer
|
|
134
|
+
// to one binding exactly when they share it. Undefined for imports and globals.
|
|
135
|
+
export function bindingScopeOf(identifier) {
|
|
136
|
+
for (let current = identifier.parent; current; current = current.parent) {
|
|
137
|
+
if (declarationAtNode(current, identifier.text) && !hoistsOutOf(current, identifier.text))
|
|
138
|
+
return current;
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|