




















@@ -64,7 +64,7 @@ export function hintForPath(path: Array<string | number>, hints: ConfigUiHints)
6464if (direct) {
6565return direct;
6666}
67-const segments = key.split(".");
67+const segments = path.map(String);
6868for (const [hintKey, hint] of Object.entries(hints)) {
6969if (!hintKey.includes("*")) {
7070continue;
@@ -120,6 +120,28 @@ const ENV_VAR_PLACEHOLDER_PATTERN = /^\$\{[^}]*\}$/;
120120121121export const REDACTED_PLACEHOLDER = "[redacted - click reveal to view]";
122122123+const MAX_SENSITIVE_SCAN_DEPTH = 64;
124+const MAX_SENSITIVE_SCAN_NODES = 20_000;
125+126+type SensitiveScanState = {
127+visited: number;
128+};
129+130+function createSensitiveScanState(): SensitiveScanState {
131+return { visited: 0 };
132+}
133+134+function enterSensitiveScanNode(state: SensitiveScanState, depth: number): boolean {
135+if (depth > MAX_SENSITIVE_SCAN_DEPTH) {
136+return false;
137+}
138+state.visited += 1;
139+if (state.visited > MAX_SENSITIVE_SCAN_NODES) {
140+return false;
141+}
142+return true;
143+}
144+123145function isEnvVarPlaceholder(value: string): boolean {
124146return ENV_VAR_PLACEHOLDER_PATTERN.test(value.trim());
125147}
@@ -146,6 +168,20 @@ export function hasSensitiveConfigData(
146168path: Array<string | number>,
147169hints: ConfigUiHints,
148170): boolean {
171+return hasSensitiveConfigDataInner(value, path, hints, createSensitiveScanState(), 0);
172+}
173+174+function hasSensitiveConfigDataInner(
175+value: unknown,
176+path: Array<string | number>,
177+hints: ConfigUiHints,
178+scan: SensitiveScanState,
179+depth: number,
180+): boolean {
181+if (!enterSensitiveScanNode(scan, depth)) {
182+return true;
183+}
184+149185const key = pathKey(path);
150186const hint = hintForPath(path, hints);
151187const pathIsSensitive = isHintSensitive(hint) || isSensitiveConfigPath(key);
@@ -155,12 +191,14 @@ export function hasSensitiveConfigData(
155191}
156192157193if (Array.isArray(value)) {
158-return value.some((item, index) => hasSensitiveConfigData(item, [...path, index], hints));
194+return value.some((item, index) =>
195+hasSensitiveConfigDataInner(item, [...path, index], hints, scan, depth + 1),
196+);
159197}
160198161199if (value && typeof value === "object") {
162200return Object.entries(value as Record<string, unknown>).some(([childKey, childValue]) =>
163-hasSensitiveConfigData(childValue, [...path, childKey], hints),
201+hasSensitiveConfigDataInner(childValue, [...path, childKey], hints, scan, depth + 1),
164202);
165203}
166204@@ -172,6 +210,20 @@ export function countSensitiveConfigValues(
172210path: Array<string | number>,
173211hints: ConfigUiHints,
174212): number {
213+return countSensitiveConfigValuesInner(value, path, hints, createSensitiveScanState(), 0);
214+}
215+216+function countSensitiveConfigValuesInner(
217+value: unknown,
218+path: Array<string | number>,
219+hints: ConfigUiHints,
220+scan: SensitiveScanState,
221+depth: number,
222+): number {
223+if (!enterSensitiveScanNode(scan, depth)) {
224+return 1;
225+}
226+175227if (value == null) {
176228return 0;
177229}
@@ -186,15 +238,17 @@ export function countSensitiveConfigValues(
186238187239if (Array.isArray(value)) {
188240return value.reduce(
189-(count, item, index) => count + countSensitiveConfigValues(item, [...path, index], hints),
241+(count, item, index) =>
242+count + countSensitiveConfigValuesInner(item, [...path, index], hints, scan, depth + 1),
1902430,
191244);
192245}
193246194247if (value && typeof value === "object") {
195248return Object.entries(value as Record<string, unknown>).reduce(
196249(count, [childKey, childValue]) =>
197-count + countSensitiveConfigValues(childValue, [...path, childKey], hints),
250+count +
251+countSensitiveConfigValuesInner(childValue, [...path, childKey], hints, scan, depth + 1),
1982520,
199253);
200254}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。