@cdkd/cli 0.373.6 → 0.374.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/dist/{ambient-client-defaults-BqOg0I6e.js → ambient-client-defaults-Bz-RIOwy.js} +3 -3
- package/dist/{ambient-client-defaults-BqOg0I6e.js.map → ambient-client-defaults-Bz-RIOwy.js.map} +1 -1
- package/dist/{asg-provider-DkhAcikX.js → asg-provider-CAUjmdq9.js} +8 -8
- package/dist/{asg-provider-DkhAcikX.js.map → asg-provider-CAUjmdq9.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/{custom-resource-runtime-CLjuWVBC.js → custom-resource-runtime-CWVAEO2K.js} +6 -6
- package/dist/{custom-resource-runtime-CLjuWVBC.js.map → custom-resource-runtime-CWVAEO2K.js.map} +1 -1
- package/dist/{db-associated-roles-CCgL0Loo.js → db-associated-roles-lNcEBB6O.js} +2 -2
- package/dist/{db-associated-roles-CCgL0Loo.js.map → db-associated-roles-lNcEBB6O.js.map} +1 -1
- package/dist/{delete-started-C9z4Yf_c.js → delete-started-CJq_moaK.js} +4 -4
- package/dist/{delete-started-C9z4Yf_c.js.map → delete-started-CJq_moaK.js.map} +1 -1
- package/dist/{deploy-engine-DNEAZMj7.js → deploy-engine-DQU_GZet.js} +10535 -891
- package/dist/deploy-engine-DQU_GZet.js.map +1 -0
- package/dist/{ec2-termination-protection-zaan5pi0.js → ec2-termination-protection-CGDF52lA.js} +3 -3
- package/dist/{ec2-termination-protection-zaan5pi0.js.map → ec2-termination-protection-CGDF52lA.js.map} +1 -1
- package/dist/{ecr-uri-CrQgKKRC.js → ecr-uri-CJJjp-MO.js} +2 -2
- package/dist/{ecr-uri-CrQgKKRC.js.map → ecr-uri-CJJjp-MO.js.map} +1 -1
- package/dist/{emr-cluster-provider-Dkg4vDao.js → emr-cluster-provider-2hRUEW1E.js} +13 -11
- package/dist/emr-cluster-provider-2hRUEW1E.js.map +1 -0
- package/dist/{expected-bucket-owner-DIMD36_h.js → expected-bucket-owner-DyFD7Dw5.js} +2 -2
- package/dist/{expected-bucket-owner-DIMD36_h.js.map → expected-bucket-owner-DyFD7Dw5.js.map} +1 -1
- package/dist/guard-read-retry-CaBmRzwo.js +56 -0
- package/dist/guard-read-retry-CaBmRzwo.js.map +1 -0
- package/dist/{iam-role-provider-CkIQ7vmu.js → iam-role-provider-c32ZQo8P.js} +12 -12
- package/dist/{iam-role-provider-CkIQ7vmu.js.map → iam-role-provider-c32ZQo8P.js.map} +1 -1
- package/dist/{identity-read-denied-DU0YqxNk.js → identity-read-denied-DRjvF3oA.js} +4 -4
- package/dist/{identity-read-denied-DU0YqxNk.js.map → identity-read-denied-DRjvF3oA.js.map} +1 -1
- package/dist/{image-plan-B1CAuiek.js → image-plan-Cmjgc6iE.js} +8 -8
- package/dist/{image-plan-B1CAuiek.js.map → image-plan-Cmjgc6iE.js.map} +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/{logger-IjQ12QWZ.js → logger-BlKwgEgV.js} +3 -3
- package/dist/{logger-IjQ12QWZ.js.map → logger-BlKwgEgV.js.map} +1 -1
- package/dist/{neptune-provider-2O6bzLTH.js → neptune-provider-BiLAHYo4.js} +12 -10
- package/dist/neptune-provider-BiLAHYo4.js.map +1 -0
- package/dist/{program-DnMYJ4--.js → program-CQZs9Ljn.js} +656 -334
- package/dist/program-CQZs9Ljn.js.map +1 -0
- package/dist/{provider-classes-BuCH49t_.js → provider-classes-CNMjjxoS.js} +584 -86
- package/dist/provider-classes-CNMjjxoS.js.map +1 -0
- package/dist/{rds-provider-BSeLwUR8.js → rds-provider-By5mf53G.js} +13 -13
- package/dist/{rds-provider-BSeLwUR8.js.map → rds-provider-By5mf53G.js.map} +1 -1
- package/dist/{read-replica-FMRYAHg6.js → read-replica-BIjj_bfE.js} +3 -3
- package/dist/{read-replica-FMRYAHg6.js.map → read-replica-BIjj_bfE.js.map} +1 -1
- package/dist/{redacted-delete-address-DGHv9GNm.js → redacted-delete-address-DGufa4wz.js} +4 -4
- package/dist/{redacted-delete-address-DGHv9GNm.js.map → redacted-delete-address-DGufa4wz.js.map} +1 -1
- package/dist/{replacement-rules-BAJWgr5f.js → replacement-rules-BQ-sbuiR.js} +3 -3
- package/dist/{replacement-rules-BAJWgr5f.js.map → replacement-rules-BQ-sbuiR.js.map} +1 -1
- package/dist/{resource-deadline-DB1HaWnD.js → resource-deadline-0dfvU7D5.js} +2102 -2055
- package/dist/resource-deadline-0dfvU7D5.js.map +1 -0
- package/dist/{restore-source-guard-BL2O_O6r.js → restore-source-guard-CWbzgUdy.js} +4 -4
- package/dist/{restore-source-guard-BL2O_O6r.js.map → restore-source-guard-CWbzgUdy.js.map} +1 -1
- package/dist/retry-ClxjEovs.js +211 -0
- package/dist/retry-ClxjEovs.js.map +1 -0
- package/dist/{run-cli-CtrPRsbm.js → run-cli-DBXWGhyD.js} +2 -2
- package/dist/{run-cli-CtrPRsbm.js.map → run-cli-DBXWGhyD.js.map} +1 -1
- package/dist/{secret-reference-immutable-XFEdCfNg.js → secret-reference-immutable-CSgI6Td9.js} +10 -211
- package/dist/secret-reference-immutable-CSgI6Td9.js.map +1 -0
- package/dist/{settle-own-write-members-DzUentwR.js → settle-own-write-members-DqlMjdQV.js} +10 -10
- package/dist/{settle-own-write-members-DzUentwR.js.map → settle-own-write-members-DqlMjdQV.js.map} +1 -1
- package/dist/{tag-list-Bye2zxAF.js → tag-list-B4IlIPvY.js} +4 -4
- package/dist/{tag-list-Bye2zxAF.js.map → tag-list-B4IlIPvY.js.map} +1 -1
- package/dist/{update-removal-BpxPxmQR.js → update-removal-VyphayB2.js} +2 -2
- package/dist/{update-removal-BpxPxmQR.js.map → update-removal-VyphayB2.js.map} +1 -1
- package/dist/{version-nXXjUmZl.js → version-fHMzKIi5.js} +2 -2
- package/dist/{version-nXXjUmZl.js.map → version-fHMzKIi5.js.map} +1 -1
- package/package.json +1 -1
- package/dist/deploy-engine-DNEAZMj7.js.map +0 -1
- package/dist/emr-cluster-provider-Dkg4vDao.js.map +0 -1
- package/dist/neptune-provider-2O6bzLTH.js.map +0 -1
- package/dist/program-DnMYJ4--.js.map +0 -1
- package/dist/provider-classes-BuCH49t_.js.map +0 -1
- package/dist/resource-deadline-DB1HaWnD.js.map +0 -1
- package/dist/secret-reference-immutable-XFEdCfNg.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as displayStackName, M as isPlainIdent, N as plainIdentOr, P as safeMsg, S as SECRET_REF_MAX_CODE_POINTS, _ as shellQuote, d as pasteableCommand, j as isPasteableIdent, k as displaySafe, m as proseQuoted, p as plainOrDescribed, r as SHELL_ACTIVE, s as commandHole, u as isInertUnquoted, w as UNRENDERABLE, x as SAFE_MSG_ALTERED_CHAR } from "./version-
|
|
2
|
-
import { J as getCurrentStackName, u as describeAwsFailure } from "./logger-
|
|
3
|
-
import { B as isTransientServerError, D as markReplayMayCollide, F as isAmbiguousOutcomeError, U as isMarkedNonRetryable, V as retryClassificationText, ot as ProvisioningError, x as hasReplayMayCollide, z as isRetryableTransientError } from "./ambient-client-defaults-
|
|
1
|
+
import { A as displayStackName, M as isPlainIdent, N as plainIdentOr, P as safeMsg, S as SECRET_REF_MAX_CODE_POINTS, _ as shellQuote, d as pasteableCommand, j as isPasteableIdent, k as displaySafe, m as proseQuoted, p as plainOrDescribed, r as SHELL_ACTIVE, s as commandHole, u as isInertUnquoted, w as UNRENDERABLE, x as SAFE_MSG_ALTERED_CHAR } from "./version-fHMzKIi5.js";
|
|
2
|
+
import { J as getCurrentStackName, u as describeAwsFailure } from "./logger-BlKwgEgV.js";
|
|
3
|
+
import { B as isTransientServerError, D as markReplayMayCollide, F as isAmbiguousOutcomeError, U as isMarkedNonRetryable, V as retryClassificationText, ot as ProvisioningError, x as hasReplayMayCollide, z as isRetryableTransientError } from "./ambient-client-defaults-Bz-RIOwy.js";
|
|
4
4
|
import { a as getAssumedRoleCredentials, f as ambientRegion, i as awsEndpointOverrideUrl } from "./aws-client-defaults-DAebi99J.js";
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
6
|
|
|
@@ -668,6 +668,7 @@ const nestedStackParameterExpressions = /* @__PURE__ */ new WeakMap();
|
|
|
668
668
|
const renderedParameterSpellings = /* @__PURE__ */ new WeakMap();
|
|
669
669
|
const UNFRAMED_SPELLING = Symbol("cdkd.nested-parameter.unframed-spelling");
|
|
670
670
|
const attributionRefusedParameters = /* @__PURE__ */ new WeakMap();
|
|
671
|
+
const inheritedSubFloorPlaintexts = /* @__PURE__ */ new WeakMap();
|
|
671
672
|
function markAttributionRefusedParameter(secrets, name, kind) {
|
|
672
673
|
let table = attributionRefusedParameters.get(secrets);
|
|
673
674
|
if (table === void 0) {
|
|
@@ -676,6 +677,16 @@ function markAttributionRefusedParameter(secrets, name, kind) {
|
|
|
676
677
|
}
|
|
677
678
|
if (table.get(name) !== "masked") table.set(name, kind);
|
|
678
679
|
}
|
|
680
|
+
function carriesSubFloorEvidence(secrets) {
|
|
681
|
+
return (attributionRefusedParameters.get(secrets)?.size ?? 0) > 0 || (inheritedSubFloorPlaintexts.get(secrets)?.size ?? 0) > 0;
|
|
682
|
+
}
|
|
683
|
+
function containsCarriedSubFloorText(text, secrets) {
|
|
684
|
+
for (const plaintext of inheritedSubFloorPlaintexts.get(secrets) ?? []) if (text.includes(plaintext)) return true;
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
function isCarriedSubFloorText(text, secrets) {
|
|
688
|
+
return inheritedSubFloorPlaintexts.get(secrets)?.has(text) ?? false;
|
|
689
|
+
}
|
|
679
690
|
|
|
680
691
|
// src/deployment/secret-redaction/nested-stack/refused-parameter-reads.ts
|
|
681
692
|
function attributionRefusedReadsOf(node, secrets) {
|
|
@@ -1412,7 +1423,7 @@ function nestedStackRowTagSpellingOf(secrets, key, value) {
|
|
|
1412
1423
|
function recordNestedStackParameterExpressions(secrets, resourceType, resolvedProperties, sourceProperties, provenance = "template-derived") {
|
|
1413
1424
|
if (resourceType !== "AWS::CloudFormation::Stack") return;
|
|
1414
1425
|
if (provenance === "template-derived") recordNestedStackRowTagSpellings(secrets, resourceType, resolvedProperties, sourceProperties);
|
|
1415
|
-
if (secrets.size === 0) return;
|
|
1426
|
+
if (secrets.size === 0 && !carriesSubFloorEvidence(secrets)) return;
|
|
1416
1427
|
if (!isPlainObject(resolvedProperties) || !isPlainObject(sourceProperties)) return;
|
|
1417
1428
|
if (!Object.hasOwn(resolvedProperties, "Parameters")) return;
|
|
1418
1429
|
if (!Object.hasOwn(sourceProperties, "Parameters")) return;
|
|
@@ -1745,2285 +1756,2320 @@ function carriesChildOnlyPlaintext(value, childSecrets, parentSecrets) {
|
|
|
1745
1756
|
return visit(value);
|
|
1746
1757
|
}
|
|
1747
1758
|
|
|
1748
|
-
// src/deployment/secret-redaction/
|
|
1749
|
-
function
|
|
1750
|
-
|
|
1751
|
-
const
|
|
1752
|
-
if (
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
const key = crossStackSourceKey({ Ref: name });
|
|
1756
|
-
if (key === void 0) continue;
|
|
1757
|
-
if (associations === void 0) {
|
|
1758
|
-
associations = /* @__PURE__ */ new Map();
|
|
1759
|
-
crossStackAssociations.set(childSecrets, associations);
|
|
1760
|
-
}
|
|
1761
|
-
if (typeof association === "symbol") {
|
|
1762
|
-
associations.set(key, association);
|
|
1763
|
-
continue;
|
|
1764
|
-
}
|
|
1765
|
-
storeAssociation(associations, key, association.expression, association.plaintext);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
function inheritedParameterExpression(parentSecrets, parameterName, resolvedValue) {
|
|
1769
|
-
const association = nestedStackParameterExpressions.get(parentSecrets)?.get(parameterName);
|
|
1770
|
-
if (association === void 0) return renderedParameterSpelling(parentSecrets, parameterName, resolvedValue);
|
|
1771
|
-
if (typeof association === "symbol") return void 0;
|
|
1772
|
-
if (Array.isArray(resolvedValue)) return certifiedListForLeaf(parentSecrets, association, resolvedValue);
|
|
1773
|
-
return certifiedExpressionForLeaf(parentSecrets, association, resolvedValue);
|
|
1774
|
-
}
|
|
1775
|
-
function renderedParameterSpelling(parentSecrets, parameterName, resolvedValue) {
|
|
1776
|
-
if (typeof resolvedValue !== "string" || parentSecrets.has(resolvedValue)) return void 0;
|
|
1777
|
-
const rendered = renderedParameterSpellings.get(parentSecrets)?.get(parameterName);
|
|
1778
|
-
if (rendered == null || rendered.value !== resolvedValue) return void 0;
|
|
1779
|
-
if (!rendersLiteralTo(rendered.spelling, parentSecrets, resolvedValue)) return void 0;
|
|
1780
|
-
return rendered.spelling;
|
|
1781
|
-
}
|
|
1782
|
-
function inheritedRenderedToken(parentSecrets, parameterName, value, plaintext) {
|
|
1783
|
-
const spelling = inheritedParameterExpression(parentSecrets, parameterName, value);
|
|
1784
|
-
if (typeof spelling !== "string" || isSingleDynamicReferenceToken(spelling)) return void 0;
|
|
1785
|
-
return renderedTokenOf(spelling, parentSecrets, plaintext);
|
|
1759
|
+
// src/deployment/secret-redaction/mask-errors.ts
|
|
1760
|
+
function maskSecretsInText(text, secrets) {
|
|
1761
|
+
const logOnly = logOnlyValuesOf.get(secrets);
|
|
1762
|
+
const noLogOnly = logOnly === void 0 || logOnly.size === 0;
|
|
1763
|
+
if (secrets.size === 0 && noLogOnly) return text;
|
|
1764
|
+
if (text !== "" && (secrets.has(text) || logOnly?.has(text) === true)) return "***";
|
|
1765
|
+
return maskMatchSpans(text, printingNeedles(noLogOnly ? secrets.keys() : [...secrets.keys(), ...logOnly]), "***");
|
|
1786
1766
|
}
|
|
1787
|
-
function
|
|
1788
|
-
|
|
1789
|
-
if (
|
|
1767
|
+
function maskRecordedSecretsInText(text, secrets) {
|
|
1768
|
+
if (secrets.size === 0) return text;
|
|
1769
|
+
if (text !== "" && secrets.has(text)) return "***";
|
|
1770
|
+
return maskMatchSpans(text, substringNeedles(secrets.keys()), "***");
|
|
1790
1771
|
}
|
|
1791
|
-
function
|
|
1792
|
-
|
|
1793
|
-
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
1794
|
-
for (const name of reads.names) {
|
|
1795
|
-
if (crossStackSourceKey({ Ref: name }) !== key) continue;
|
|
1796
|
-
const value = renderedParameterSpellings.get(reads.parent)?.get(name)?.value;
|
|
1797
|
-
if (value === void 0 || text !== void 0 && text !== value) return void 0;
|
|
1798
|
-
if (carriesChildOnlyPlaintext(value, childSecrets, reads.parent)) return void 0;
|
|
1799
|
-
const spelling = inheritedParameterExpression(reads.parent, name, value);
|
|
1800
|
-
if (typeof spelling !== "string") return void 0;
|
|
1801
|
-
if (redactForState(spelling, {
|
|
1802
|
-
provenance: "value-scan",
|
|
1803
|
-
secrets: childSecrets
|
|
1804
|
-
}) !== spelling) return void 0;
|
|
1805
|
-
return {
|
|
1806
|
-
value,
|
|
1807
|
-
spelling
|
|
1808
|
-
};
|
|
1809
|
-
}
|
|
1772
|
+
function substringNeedles(values) {
|
|
1773
|
+
return [...new Set(values)].filter((value) => value.length >= 4);
|
|
1810
1774
|
}
|
|
1811
|
-
const
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
const
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
};
|
|
1821
|
-
inheritedParameterReads.set(childSecrets, created);
|
|
1822
|
-
return created;
|
|
1823
|
-
}
|
|
1824
|
-
if (typeof reads === "symbol") return void 0;
|
|
1825
|
-
if (reads.parent !== parentSecrets) {
|
|
1826
|
-
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1827
|
-
return;
|
|
1775
|
+
const ERROR_CAUSE_MASK_MAX_DEPTH = 20;
|
|
1776
|
+
function errorCauseChain(root) {
|
|
1777
|
+
const chain = [];
|
|
1778
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1779
|
+
let current = root;
|
|
1780
|
+
while (current instanceof Error && !seen.has(current) && chain.length < 20) {
|
|
1781
|
+
seen.add(current);
|
|
1782
|
+
chain.push(current);
|
|
1783
|
+
current = current.cause;
|
|
1828
1784
|
}
|
|
1829
|
-
return
|
|
1785
|
+
return chain;
|
|
1830
1786
|
}
|
|
1831
|
-
function
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
else if (reads.declared.size !== declared.size || [...declared].some((name) => !reads.declared.has(name))) {
|
|
1837
|
-
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1838
|
-
return;
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
if (reads.values.has(parameterName)) {
|
|
1842
|
-
if (!deepEqualJsonValue(reads.values.get(parameterName), value)) inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1787
|
+
function readStack(error) {
|
|
1788
|
+
try {
|
|
1789
|
+
const stack = error.stack;
|
|
1790
|
+
return typeof stack === "string" ? stack : void 0;
|
|
1791
|
+
} catch {
|
|
1843
1792
|
return;
|
|
1844
1793
|
}
|
|
1845
|
-
reads.values.set(parameterName, value);
|
|
1846
|
-
}
|
|
1847
|
-
function recordInheritedParameterRead(childSecrets, parentSecrets, parameterName) {
|
|
1848
|
-
parameterReadsFor(childSecrets, parentSecrets)?.names.add(parameterName);
|
|
1849
1794
|
}
|
|
1850
|
-
function
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1795
|
+
function maskDescriptorValue(descriptor, maskText) {
|
|
1796
|
+
if (!("value" in descriptor)) return descriptor;
|
|
1797
|
+
const value = maskErrorFieldValue(descriptor.value, maskText);
|
|
1798
|
+
return value === descriptor.value ? descriptor : {
|
|
1799
|
+
...descriptor,
|
|
1800
|
+
value
|
|
1801
|
+
};
|
|
1855
1802
|
}
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
return
|
|
1803
|
+
const CLASSIFIER_IDENTIFIER_FIELDS = /* @__PURE__ */ new Set([
|
|
1804
|
+
"name",
|
|
1805
|
+
"code",
|
|
1806
|
+
"Code",
|
|
1807
|
+
"__type",
|
|
1808
|
+
"ccErrorCode",
|
|
1809
|
+
"ccOperation"
|
|
1810
|
+
]);
|
|
1811
|
+
function isAuxiliaryAnchor(key, descriptor) {
|
|
1812
|
+
return key === "logicalId" && descriptor.enumerable === false && descriptor.writable === false && typeof descriptor.value === "string" && descriptor.value.endsWith("/auxiliary");
|
|
1866
1813
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
const name = source["Ref"];
|
|
1871
|
-
if (typeof name !== "string") return void 0;
|
|
1872
|
-
const reads = inheritedParameterReads.get(secrets);
|
|
1873
|
-
if (reads === void 0 || typeof reads === "symbol" || !reads.names.has(name)) return;
|
|
1874
|
-
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
1875
|
-
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
1876
|
-
const answer = persistedInheritedParameterValue(reads.parent, name, bag);
|
|
1877
|
-
if (!deepEqualJsonValue(redactForState(answer, {
|
|
1878
|
-
provenance: "value-scan",
|
|
1879
|
-
secrets
|
|
1880
|
-
}), answer)) return void 0;
|
|
1881
|
-
return answer;
|
|
1814
|
+
const CREATED_BEFORE_FAILURE_MARK = Symbol.for("cdkd.createdBeforeFailure");
|
|
1815
|
+
function isCreatedBeforeFailureMark(key, descriptor) {
|
|
1816
|
+
return key === CREATED_BEFORE_FAILURE_MARK && descriptor.enumerable === false && descriptor.writable === false && typeof descriptor.value === "object" && descriptor.value !== null && Object.isFrozen(descriptor.value);
|
|
1882
1817
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
"AWS::Region",
|
|
1887
|
-
"AWS::Partition",
|
|
1888
|
-
"AWS::URLSuffix",
|
|
1889
|
-
"AWS::AccountId"
|
|
1890
|
-
]);
|
|
1891
|
-
function templateRereadsAccountId(template) {
|
|
1892
|
-
if (template === void 0) return false;
|
|
1893
|
-
const resources = template.Resources !== null && typeof template.Resources === "object" ? template.Resources : void 0;
|
|
1894
|
-
const cached = resources && accountRereadVerdicts.get(resources);
|
|
1895
|
-
if (cached !== void 0 && cached.outputs === template.Outputs) return cached.verdict;
|
|
1896
|
-
const parts = resources ? Object.values(resources) : [];
|
|
1897
|
-
if (template.Outputs !== void 0) parts.push(template.Outputs);
|
|
1898
|
-
const verdict = parts.some(partRereadsAccountId);
|
|
1899
|
-
if (resources) accountRereadVerdicts.set(resources, {
|
|
1900
|
-
outputs: template.Outputs,
|
|
1901
|
-
verdict
|
|
1902
|
-
});
|
|
1903
|
-
return verdict;
|
|
1818
|
+
function isPlainContainer(value) {
|
|
1819
|
+
const proto = Object.getPrototypeOf(value);
|
|
1820
|
+
return Array.isArray(value) ? proto === Array.prototype : proto === Object.prototype || proto === null;
|
|
1904
1821
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
if (Array.isArray(node)) {
|
|
1913
|
-
pending.push(...node);
|
|
1914
|
-
continue;
|
|
1915
|
-
}
|
|
1916
|
-
if (node === null || typeof node !== "object") continue;
|
|
1917
|
-
for (const [key, value] of Object.entries(node)) {
|
|
1918
|
-
if (REREAD_TRIGGERS.has(key)) trigger = true;
|
|
1919
|
-
if (key === "Ref" && value === "AWS::AccountId") account = true;
|
|
1920
|
-
if (key === "Fn::Sub") {
|
|
1921
|
-
const text = Array.isArray(value) ? value[0] : value;
|
|
1922
|
-
if (typeof text === "string" && text.includes("${AWS::AccountId}")) account = true;
|
|
1923
|
-
}
|
|
1924
|
-
pending.push(value);
|
|
1822
|
+
function readFieldNode(node) {
|
|
1823
|
+
try {
|
|
1824
|
+
if (!isPlainContainer(node)) return void 0;
|
|
1825
|
+
const entries = [];
|
|
1826
|
+
for (const key of Reflect.ownKeys(node)) {
|
|
1827
|
+
const descriptor = Object.getOwnPropertyDescriptor(node, key);
|
|
1828
|
+
if (descriptor) entries.push([key, descriptor]);
|
|
1925
1829
|
}
|
|
1830
|
+
const isArray = Array.isArray(node);
|
|
1831
|
+
return {
|
|
1832
|
+
proto: Object.getPrototypeOf(node),
|
|
1833
|
+
isArray,
|
|
1834
|
+
length: isArray ? Object.getOwnPropertyDescriptor(node, "length") : void 0,
|
|
1835
|
+
extensible: Object.isExtensible(node),
|
|
1836
|
+
entries
|
|
1837
|
+
};
|
|
1838
|
+
} catch {
|
|
1839
|
+
return;
|
|
1926
1840
|
}
|
|
1927
|
-
return trigger && account;
|
|
1928
1841
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
return typeof bound === "string" ? bound : void 0;
|
|
1955
|
-
}
|
|
1956
|
-
function inheritedPseudoSpan(childSecrets, key) {
|
|
1957
|
-
const reads = inheritedParameterReads.get(childSecrets);
|
|
1958
|
-
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
1959
|
-
for (const name of REREAD_PSEUDO_PARAMETERS) if (crossStackSourceKey({ Ref: name }) === key) return inheritedPseudoValue(reads.parent, name);
|
|
1960
|
-
}
|
|
1961
|
-
const REREAD_TRIGGERS = /* @__PURE__ */ new Set([
|
|
1962
|
-
"Fn::Select",
|
|
1963
|
-
"Fn::Split",
|
|
1964
|
-
"Fn::If"
|
|
1965
|
-
]);
|
|
1966
|
-
|
|
1967
|
-
// src/deployment/secret-redaction/nested-stack/reread.ts
|
|
1968
|
-
const MAX_REREAD_DEPTH = 16;
|
|
1969
|
-
const MAX_REREAD_CONDITIONS = 4;
|
|
1970
|
-
const REREAD_NO_VALUE = Symbol("cdkd.reread.no-value");
|
|
1971
|
-
function splitOutsideDynamicReferences(text, delimiter, standsForSecret) {
|
|
1972
|
-
if (delimiter === "") return text.split(delimiter);
|
|
1973
|
-
const spans = dynamicReferenceSpans(text).filter((span) => {
|
|
1974
|
-
const token = text.slice(span.start, span.end);
|
|
1975
|
-
return spanNamesResolvableService(token) && standsForSecret(token);
|
|
1976
|
-
});
|
|
1977
|
-
if (spans.length === 0) return text.split(delimiter);
|
|
1978
|
-
const pieces = [];
|
|
1979
|
-
let cursor = 0;
|
|
1980
|
-
let from = 0;
|
|
1981
|
-
for (;;) {
|
|
1982
|
-
const at = text.indexOf(delimiter, from);
|
|
1983
|
-
if (at === -1) break;
|
|
1984
|
-
const end = at + delimiter.length;
|
|
1985
|
-
const token = spans.find((span) => span.start < end && at < span.end);
|
|
1986
|
-
if (token !== void 0) {
|
|
1987
|
-
from = token.end;
|
|
1988
|
-
continue;
|
|
1842
|
+
function maskErrorFieldValue(value, maskText) {
|
|
1843
|
+
if (typeof value === "string") return maskText(value);
|
|
1844
|
+
if (typeof value !== "object" || value === null) return value;
|
|
1845
|
+
try {
|
|
1846
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
1847
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1848
|
+
let changed = false;
|
|
1849
|
+
let frontier = [value];
|
|
1850
|
+
for (let depth = 0; frontier.length > 0 && depth < 20; depth++) {
|
|
1851
|
+
const next = [];
|
|
1852
|
+
for (const node of frontier) {
|
|
1853
|
+
if (seen.has(node)) continue;
|
|
1854
|
+
seen.add(node);
|
|
1855
|
+
const read = readFieldNode(node);
|
|
1856
|
+
if (!read) continue;
|
|
1857
|
+
nodes.set(node, read);
|
|
1858
|
+
for (const [, descriptor] of read.entries) {
|
|
1859
|
+
if (!("value" in descriptor)) continue;
|
|
1860
|
+
const child = descriptor.value;
|
|
1861
|
+
if (typeof child === "string") {
|
|
1862
|
+
if (!changed && maskText(child) !== child) changed = true;
|
|
1863
|
+
} else if (typeof child === "object" && child !== null) next.push(child);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
frontier = next;
|
|
1989
1867
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1868
|
+
if (!changed) return value;
|
|
1869
|
+
const copies = /* @__PURE__ */ new Map();
|
|
1870
|
+
for (const [node, read] of nodes) copies.set(node, read.isArray ? new Array(read.length?.value ?? 0) : Object.create(read.proto));
|
|
1871
|
+
for (const [node, read] of nodes) {
|
|
1872
|
+
const copy = copies.get(node);
|
|
1873
|
+
for (const [key, original] of read.entries) {
|
|
1874
|
+
if (key === "length" && read.isArray) continue;
|
|
1875
|
+
const descriptor = { ...original };
|
|
1876
|
+
if ("value" in descriptor) {
|
|
1877
|
+
const child = descriptor.value;
|
|
1878
|
+
if (typeof child === "string") descriptor.value = maskText(child);
|
|
1879
|
+
else if (typeof child === "object" && child !== null && copies.has(child)) descriptor.value = copies.get(child);
|
|
1880
|
+
}
|
|
1881
|
+
Object.defineProperty(copy, key, descriptor);
|
|
1882
|
+
}
|
|
1883
|
+
if (read.length?.writable === false) Object.defineProperty(copy, "length", { writable: false });
|
|
1884
|
+
if (!read.extensible) Object.preventExtensions(copy);
|
|
1885
|
+
}
|
|
1886
|
+
return copies.get(value) ?? value;
|
|
1887
|
+
} catch {
|
|
1888
|
+
return value;
|
|
1993
1889
|
}
|
|
1994
|
-
pieces.push(text.slice(cursor));
|
|
1995
|
-
return pieces;
|
|
1996
|
-
}
|
|
1997
|
-
function standsForInheritedSecret(parentSecrets, token) {
|
|
1998
|
-
return parentSecrets !== void 0 && resolvedPlaintextOf(parentSecrets, token) !== void 0;
|
|
1999
1890
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
const
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
1891
|
+
function maskSecretsInError(error, secrets, extraMask) {
|
|
1892
|
+
if (!(error instanceof Error) || !hasMaskableValues(secrets) && !extraMask) return error;
|
|
1893
|
+
const maskText = (text) => maskSecretsInText(extraMask ? extraMask(text) : text, secrets);
|
|
1894
|
+
const chain = errorCauseChain(error);
|
|
1895
|
+
let changed = false;
|
|
1896
|
+
const links = chain.map((link) => {
|
|
1897
|
+
const message = maskText(link.message);
|
|
1898
|
+
const stack = readStack(link);
|
|
1899
|
+
const maskedStack = typeof stack === "string" ? maskText(stack) : void 0;
|
|
1900
|
+
const descriptors = {};
|
|
1901
|
+
for (const key of Reflect.ownKeys(link)) {
|
|
1902
|
+
if (key === "message" || key === "cause" || key === "stack") continue;
|
|
1903
|
+
const descriptor = Object.getOwnPropertyDescriptor(link, key);
|
|
1904
|
+
if (!descriptor) continue;
|
|
1905
|
+
descriptors[key] = typeof key === "string" && CLASSIFIER_IDENTIFIER_FIELDS.has(key) && typeof descriptor.value === "string" || isAuxiliaryAnchor(key, descriptor) || isCreatedBeforeFailureMark(key, descriptor) ? descriptor : maskDescriptorValue(descriptor, maskText);
|
|
1906
|
+
if (descriptors[key] !== descriptor) changed = true;
|
|
2011
1907
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
1908
|
+
let cause = Object.getOwnPropertyDescriptor(link, "cause");
|
|
1909
|
+
if (cause && !("value" in cause && cause.value instanceof Error)) {
|
|
1910
|
+
const masked = maskDescriptorValue(cause, maskText);
|
|
1911
|
+
if (masked !== cause) changed = true;
|
|
1912
|
+
cause = masked;
|
|
1913
|
+
}
|
|
1914
|
+
if (message !== link.message || maskedStack !== stack) changed = true;
|
|
1915
|
+
return {
|
|
1916
|
+
message,
|
|
1917
|
+
stack: maskedStack,
|
|
1918
|
+
descriptors,
|
|
1919
|
+
cause
|
|
1920
|
+
};
|
|
1921
|
+
});
|
|
1922
|
+
if (!changed) return error;
|
|
1923
|
+
const clones = /* @__PURE__ */ new Map();
|
|
1924
|
+
for (const [i, original] of chain.entries()) {
|
|
1925
|
+
const { message, stack, descriptors } = links[i];
|
|
1926
|
+
const clone = Object.create(Object.getPrototypeOf(original), descriptors);
|
|
1927
|
+
Object.defineProperty(clone, "message", {
|
|
1928
|
+
value: message,
|
|
1929
|
+
writable: true,
|
|
1930
|
+
enumerable: false,
|
|
1931
|
+
configurable: true
|
|
1932
|
+
});
|
|
1933
|
+
if (stack !== void 0) Object.defineProperty(clone, "stack", {
|
|
1934
|
+
value: stack,
|
|
1935
|
+
writable: true,
|
|
1936
|
+
enumerable: false,
|
|
1937
|
+
configurable: true
|
|
1938
|
+
});
|
|
1939
|
+
clones.set(original, clone);
|
|
2022
1940
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
1941
|
+
for (const [i, original] of chain.entries()) {
|
|
1942
|
+
const causeDescriptor = links[i].cause;
|
|
1943
|
+
if (!causeDescriptor) continue;
|
|
1944
|
+
const clone = clones.get(original);
|
|
1945
|
+
const causeValue = original.cause;
|
|
1946
|
+
const replacement = causeValue instanceof Error ? clones.get(causeValue) : void 0;
|
|
1947
|
+
Object.defineProperty(clone, "cause", replacement ? {
|
|
1948
|
+
value: replacement,
|
|
1949
|
+
writable: true,
|
|
1950
|
+
enumerable: causeDescriptor.enumerable === true,
|
|
1951
|
+
configurable: true
|
|
1952
|
+
} : causeDescriptor);
|
|
2028
1953
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
1954
|
+
return clones.get(error);
|
|
1955
|
+
}
|
|
1956
|
+
function createSecretMasker(secrets) {
|
|
1957
|
+
return (text) => maskSecretsInText(text, secrets);
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
// src/deployment/secret-redaction/log-only.ts
|
|
1961
|
+
const logOnlyValuesOf = /* @__PURE__ */ new WeakMap();
|
|
1962
|
+
function recordLogOnlyValue(secrets, plaintext) {
|
|
1963
|
+
if (plaintext === "") return;
|
|
1964
|
+
sideSetOf(logOnlyValuesOf, secrets).add(plaintext);
|
|
1965
|
+
}
|
|
1966
|
+
function carryLogOnlyValues(from, to) {
|
|
1967
|
+
const values = logOnlyValuesOf.get(from);
|
|
1968
|
+
if (values === void 0 || values.size === 0) return;
|
|
1969
|
+
const into = sideSetOf(logOnlyValuesOf, to);
|
|
1970
|
+
for (const value of values) into.add(value);
|
|
1971
|
+
}
|
|
1972
|
+
function carryLogOnlyValuesCarriedBy(from, to, value) {
|
|
1973
|
+
const values = logOnlyValuesOf.get(from);
|
|
1974
|
+
if (values === void 0 || values.size === 0) return;
|
|
1975
|
+
const leaves = printedLeavesOf(value);
|
|
1976
|
+
if (leaves.size === 0) return;
|
|
1977
|
+
for (const needle of values) for (const leaf of leaves) if (leaf === needle || needle.length >= 4 && leaf.includes(needle)) {
|
|
1978
|
+
recordLogOnlyValue(to, needle);
|
|
1979
|
+
break;
|
|
2038
1980
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
1981
|
+
carryListElementFragments(values, to, value);
|
|
1982
|
+
}
|
|
1983
|
+
function carryListElementFragments(needles, to, value) {
|
|
1984
|
+
if (!Array.isArray(value) || value.length === 0) return;
|
|
1985
|
+
if (!value.every((e) => typeof e === "string" || typeof e === "number" || typeof e === "boolean")) return;
|
|
1986
|
+
const numeric = value.every((element) => typeof element === "number");
|
|
1987
|
+
const joined = value.map((element) => String(element)).join(",");
|
|
1988
|
+
for (const needle of [...needles]) {
|
|
1989
|
+
const pieces = needle.split(",").map((piece) => piece.trim());
|
|
1990
|
+
if (numeric && pieces.every((piece) => piece === "" || Number.isNaN(Number(piece)))) continue;
|
|
1991
|
+
const fragments = fragmentsOfNeedleIn(joined, ",", pieces.map((piece) => numeric ? String(Number(piece)) : piece).join(","));
|
|
1992
|
+
if (fragments.size === 0) continue;
|
|
1993
|
+
recordLogOnlyValue(to, needle);
|
|
1994
|
+
for (const fragment of fragments) recordLogOnlyValue(to, fragment);
|
|
2045
1995
|
}
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
1996
|
+
}
|
|
1997
|
+
function recordLogOnlySplitFragments(from, to, text, delimiter, printed) {
|
|
1998
|
+
if (delimiter === "") return;
|
|
1999
|
+
const splits = [text.split(delimiter)];
|
|
2000
|
+
if (printed !== void 0 && (printed.length !== splits[0].length || printed.some((piece, i) => piece !== splits[0][i]))) splits.push(printed);
|
|
2001
|
+
for (const bag of from) {
|
|
2002
|
+
if (bag === void 0) continue;
|
|
2003
|
+
for (const needle of [...logOnlyValuesOf.get(bag) ?? []]) for (const pieces of splits) for (const fragment of fragmentsOfNeedleIn(text, delimiter, needle, pieces)) if (fragment !== needle) recordLogOnlyValue(to, fragment);
|
|
2051
2004
|
}
|
|
2052
2005
|
}
|
|
2053
|
-
function
|
|
2054
|
-
const
|
|
2055
|
-
if (
|
|
2056
|
-
const
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2006
|
+
function fragmentsOfNeedleIn(text, delimiter, needle, pieces = text.split(delimiter)) {
|
|
2007
|
+
const fragments = /* @__PURE__ */ new Set();
|
|
2008
|
+
if (needle === "") return fragments;
|
|
2009
|
+
const starts = [];
|
|
2010
|
+
if (text === needle) starts.push(0);
|
|
2011
|
+
else if (needle.length >= 4) for (let at = text.indexOf(needle); at !== -1; at = text.indexOf(needle, at + 1)) starts.push(at);
|
|
2012
|
+
if (starts.length === 0) return fragments;
|
|
2013
|
+
const spans = [];
|
|
2014
|
+
let offset = 0;
|
|
2015
|
+
for (const piece of pieces) {
|
|
2016
|
+
spans.push([offset, offset + piece.length]);
|
|
2017
|
+
offset += piece.length + delimiter.length;
|
|
2061
2018
|
}
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
else if (name === "") replacement = match[0];
|
|
2069
|
-
else if (bound.has(name)) replacement = bound.get(name);
|
|
2070
|
-
else {
|
|
2071
|
-
if (name.includes(".")) return void 0;
|
|
2072
|
-
const value = bindReadName(name, bind, pseudo);
|
|
2073
|
-
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
2074
|
-
replacement = value.value;
|
|
2019
|
+
for (const start of starts) {
|
|
2020
|
+
const end = start + needle.length;
|
|
2021
|
+
for (const [pieceStart, pieceEnd] of spans) {
|
|
2022
|
+
const from = Math.max(pieceStart, start);
|
|
2023
|
+
const to = Math.min(pieceEnd, end);
|
|
2024
|
+
if (from < to) fragments.add(text.slice(from, to));
|
|
2075
2025
|
}
|
|
2076
|
-
out += text.slice(cursor, match.index) + replacement;
|
|
2077
|
-
cursor = match.index + match[0].length;
|
|
2078
2026
|
}
|
|
2079
|
-
return
|
|
2080
|
-
}
|
|
2081
|
-
function bindReadName(name, bind, pseudo) {
|
|
2082
|
-
if (!name.startsWith("AWS::")) return bind(name);
|
|
2083
|
-
return bind(name) === void 0 ? pseudo(name) : void 0;
|
|
2027
|
+
return fragments;
|
|
2084
2028
|
}
|
|
2085
|
-
function
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2029
|
+
function printedLeavesOf(value) {
|
|
2030
|
+
const leaves = wholeStringLeavesOf(value);
|
|
2031
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2032
|
+
const walk = (node) => {
|
|
2033
|
+
if (typeof node === "number" || typeof node === "boolean") {
|
|
2034
|
+
leaves.add(String(node));
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
if (node === null || typeof node !== "object") return;
|
|
2038
|
+
if (seen.has(node)) return;
|
|
2039
|
+
seen.add(node);
|
|
2040
|
+
for (const child of Array.isArray(node) ? node : Object.values(node)) walk(child);
|
|
2041
|
+
};
|
|
2042
|
+
walk(value);
|
|
2043
|
+
return leaves;
|
|
2095
2044
|
}
|
|
2096
|
-
function
|
|
2097
|
-
|
|
2098
|
-
if (Array.isArray(node)) return node.some((element) => holdsRereadTrigger(element, depth + 1));
|
|
2099
|
-
if (!isPlainObject(node)) return false;
|
|
2100
|
-
return Object.entries(node).some(([key, child]) => REREAD_TRIGGERS.has(key) || holdsRereadTrigger(child, depth + 1));
|
|
2045
|
+
function shareLogOnlyValues(view, target) {
|
|
2046
|
+
logOnlyValuesOf.set(view, sideSetOf(logOnlyValuesOf, target));
|
|
2101
2047
|
}
|
|
2102
|
-
function
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
if (
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2048
|
+
function recordLogOnlyParameterValue(secrets, value, splitDelimiters) {
|
|
2049
|
+
const record = (leaf) => {
|
|
2050
|
+
const spelled = typeof leaf === "string" ? leaf : typeof leaf === "number" || typeof leaf === "boolean" ? String(leaf) : void 0;
|
|
2051
|
+
if (spelled === void 0) return;
|
|
2052
|
+
recordLogOnlyValue(secrets, spelled);
|
|
2053
|
+
for (const delimiter of splitDelimiters ?? []) {
|
|
2054
|
+
if (delimiter === "" || !spelled.includes(delimiter)) continue;
|
|
2055
|
+
for (const piece of spelled.split(delimiter)) recordLogOnlyValue(secrets, piece);
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
if (Array.isArray(value)) {
|
|
2059
|
+
for (const element of value) record(element);
|
|
2060
|
+
record(value.map((element) => String(element)).join(","));
|
|
2061
|
+
return;
|
|
2110
2062
|
}
|
|
2111
|
-
|
|
2112
|
-
return false;
|
|
2063
|
+
record(value);
|
|
2113
2064
|
}
|
|
2114
|
-
|
|
2115
|
-
const
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
const
|
|
2120
|
-
return
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2065
|
+
function literalSplitDelimitersOf(template, parameters) {
|
|
2066
|
+
const delimiters = /* @__PURE__ */ new Set();
|
|
2067
|
+
if (parameters.size === 0) return delimiters;
|
|
2068
|
+
const reads = (node, seen) => {
|
|
2069
|
+
if (typeof node === "string") {
|
|
2070
|
+
for (const name of parameters) if (node.includes(`\${${name}}`)) return true;
|
|
2071
|
+
return false;
|
|
2072
|
+
}
|
|
2073
|
+
if (node === null || typeof node !== "object" || seen.has(node)) return false;
|
|
2074
|
+
seen.add(node);
|
|
2075
|
+
if (!Array.isArray(node)) {
|
|
2076
|
+
const ref = node["Ref"];
|
|
2077
|
+
if (typeof ref === "string" && parameters.has(ref)) return true;
|
|
2078
|
+
}
|
|
2079
|
+
for (const child of Array.isArray(node) ? node : Object.values(node)) if (reads(child, seen)) return true;
|
|
2080
|
+
return false;
|
|
2123
2081
|
};
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
redacted: redacted.value
|
|
2082
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2083
|
+
const walk = (node) => {
|
|
2084
|
+
if (node === null || typeof node !== "object" || seen.has(node)) return;
|
|
2085
|
+
seen.add(node);
|
|
2086
|
+
if (Array.isArray(node)) {
|
|
2087
|
+
for (const child of node) walk(child);
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
for (const [key, child] of Object.entries(node)) {
|
|
2091
|
+
if (key === "Fn::Split" && Array.isArray(child) && typeof child[0] === "string" && reads(child[1], /* @__PURE__ */ new Set())) delimiters.add(child[0]);
|
|
2092
|
+
walk(child);
|
|
2093
|
+
}
|
|
2137
2094
|
};
|
|
2095
|
+
walk(template);
|
|
2096
|
+
return delimiters;
|
|
2138
2097
|
}
|
|
2139
|
-
function
|
|
2140
|
-
|
|
2141
|
-
if (
|
|
2142
|
-
|
|
2143
|
-
if (!
|
|
2144
|
-
|
|
2145
|
-
const args = node["Fn::If"];
|
|
2146
|
-
if (Object.keys(node).length !== 1) return true;
|
|
2147
|
-
if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return true;
|
|
2148
|
-
const tookTrue = choose(args[0], node);
|
|
2149
|
-
if (tookTrue === void 0) return true;
|
|
2150
|
-
return namesParameterOnBranches(tookTrue ? args[1] : args[2], choose, isParameter, depth + 1);
|
|
2151
|
-
}
|
|
2152
|
-
if (typeof node["Ref"] === "string" && isParameter(node["Ref"])) return true;
|
|
2153
|
-
const sub = node["Fn::Sub"];
|
|
2154
|
-
const text = typeof sub === "string" ? sub : Array.isArray(sub) ? sub[0] : void 0;
|
|
2155
|
-
if (typeof text === "string") {
|
|
2156
|
-
for (const match of text.matchAll(/\$\{([^}!][^}]*)\}/g)) if (isParameter(match[1].trim()) || isParameter(match[1])) return true;
|
|
2157
|
-
}
|
|
2158
|
-
return Object.values(node).some((child) => namesParameterOnBranches(child, choose, isParameter, depth + 1));
|
|
2098
|
+
function printingCorpusOf(secrets) {
|
|
2099
|
+
const logOnly = logOnlyValuesOf.get(secrets);
|
|
2100
|
+
if (logOnly === void 0 || logOnly.size === 0) return secrets;
|
|
2101
|
+
const corpus = new Map(secrets);
|
|
2102
|
+
for (const needle of logOnly) if (!corpus.has(needle)) corpus.set(needle, "***");
|
|
2103
|
+
return corpus;
|
|
2159
2104
|
}
|
|
2160
|
-
function
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
let unbound = false;
|
|
2170
|
-
const tracked = (name) => {
|
|
2171
|
-
const bound = bind(name);
|
|
2172
|
-
if (bound === void 0 && untakenWhenUnbound(name)) unbound = true;
|
|
2173
|
-
return bound;
|
|
2174
|
-
};
|
|
2175
|
-
const reread = rereadUnder(source, tracked, parentSecrets, choose);
|
|
2176
|
-
if (unbound) out.push(REREAD_UNBOUND);
|
|
2177
|
-
else if (reread !== void 0) out.push(reread);
|
|
2178
|
-
else if (parameterFree !== void 0 && !namesParameterOnBranches(source, choose, parameterFree)) out.push(REREAD_PARAMETER_FREE);
|
|
2179
|
-
else out.push(void 0);
|
|
2105
|
+
function logOnlyValueCount(secrets) {
|
|
2106
|
+
return logOnlyValuesOf.get(secrets)?.size ?? 0;
|
|
2107
|
+
}
|
|
2108
|
+
function unionOfSecretBags(bags) {
|
|
2109
|
+
const union = /* @__PURE__ */ new Map();
|
|
2110
|
+
for (const bag of bags) {
|
|
2111
|
+
if (bag === void 0) continue;
|
|
2112
|
+
for (const [plaintext, expression] of bag) if (!union.has(plaintext)) union.set(plaintext, expression);
|
|
2113
|
+
carryLogOnlyValues(bag, union);
|
|
2180
2114
|
}
|
|
2181
|
-
return
|
|
2115
|
+
return union;
|
|
2182
2116
|
}
|
|
2183
|
-
function
|
|
2184
|
-
const
|
|
2185
|
-
|
|
2186
|
-
|
|
2117
|
+
function createUnionSecretMasker(bags) {
|
|
2118
|
+
const present = bags.filter((bag) => bag !== void 0);
|
|
2119
|
+
let stamp;
|
|
2120
|
+
let needles = /* @__PURE__ */ new Set();
|
|
2121
|
+
let scanned = [];
|
|
2122
|
+
return (text) => {
|
|
2123
|
+
const now = present.map((bag) => `${bag.size}:${logOnlyValueCount(bag)}`).join(",");
|
|
2124
|
+
if (now !== stamp) {
|
|
2125
|
+
needles = /* @__PURE__ */ new Set();
|
|
2126
|
+
for (const bag of present) {
|
|
2127
|
+
for (const plaintext of bag.keys()) needles.add(plaintext);
|
|
2128
|
+
for (const plaintext of logOnlyValuesOf.get(bag) ?? []) needles.add(plaintext);
|
|
2129
|
+
}
|
|
2130
|
+
scanned = printingNeedles(needles);
|
|
2131
|
+
stamp = now;
|
|
2132
|
+
}
|
|
2133
|
+
if (text !== "" && needles.has(text)) return "***";
|
|
2134
|
+
return maskMatchSpans(text, scanned, "***");
|
|
2135
|
+
};
|
|
2187
2136
|
}
|
|
2188
|
-
function
|
|
2189
|
-
|
|
2137
|
+
function hasLogOnlyValues(secrets) {
|
|
2138
|
+
if (secrets === void 0) return false;
|
|
2139
|
+
const logOnly = logOnlyValuesOf.get(secrets);
|
|
2140
|
+
return logOnly !== void 0 && logOnly.size > 0;
|
|
2190
2141
|
}
|
|
2191
|
-
function
|
|
2192
|
-
|
|
2193
|
-
if (
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
if (
|
|
2213
|
-
|
|
2142
|
+
function hasMaskableValues(secrets) {
|
|
2143
|
+
if (secrets === void 0) return false;
|
|
2144
|
+
if (secrets.size > 0) return true;
|
|
2145
|
+
const logOnly = logOnlyValuesOf.get(secrets);
|
|
2146
|
+
return logOnly !== void 0 && logOnly.size > 0;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// src/deployment/secret-redaction/nested-stack/inherited-parameters.ts
|
|
2150
|
+
function inheritNestedStackParameterAssociations(childSecrets, parentSecrets) {
|
|
2151
|
+
for (const [name, kind] of attributionRefusedParameters.get(parentSecrets) ?? []) markAttributionRefusedParameter(childSecrets, name, kind);
|
|
2152
|
+
inheritSubFloorPlaintexts(childSecrets, parentSecrets);
|
|
2153
|
+
const table = nestedStackParameterExpressions.get(parentSecrets);
|
|
2154
|
+
if (table === void 0 || table.size === 0) return;
|
|
2155
|
+
let associations = crossStackAssociations.get(childSecrets);
|
|
2156
|
+
for (const [name, association] of table) {
|
|
2157
|
+
const key = crossStackSourceKey({ Ref: name });
|
|
2158
|
+
if (key === void 0) continue;
|
|
2159
|
+
if (associations === void 0) {
|
|
2160
|
+
associations = /* @__PURE__ */ new Map();
|
|
2161
|
+
crossStackAssociations.set(childSecrets, associations);
|
|
2162
|
+
}
|
|
2163
|
+
if (typeof association === "symbol") {
|
|
2164
|
+
associations.set(key, association);
|
|
2165
|
+
continue;
|
|
2166
|
+
}
|
|
2167
|
+
storeAssociation(associations, key, association.expression, association.plaintext);
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
function inheritedParameterExpression(parentSecrets, parameterName, resolvedValue) {
|
|
2171
|
+
const association = nestedStackParameterExpressions.get(parentSecrets)?.get(parameterName);
|
|
2172
|
+
if (association === void 0) return renderedParameterSpelling(parentSecrets, parameterName, resolvedValue);
|
|
2173
|
+
if (typeof association === "symbol") return void 0;
|
|
2174
|
+
if (Array.isArray(resolvedValue)) return certifiedListForLeaf(parentSecrets, association, resolvedValue);
|
|
2175
|
+
return certifiedExpressionForLeaf(parentSecrets, association, resolvedValue);
|
|
2176
|
+
}
|
|
2177
|
+
function renderedParameterSpelling(parentSecrets, parameterName, resolvedValue) {
|
|
2178
|
+
if (typeof resolvedValue !== "string" || parentSecrets.has(resolvedValue)) return void 0;
|
|
2179
|
+
const rendered = renderedParameterSpellings.get(parentSecrets)?.get(parameterName);
|
|
2180
|
+
if (rendered == null || rendered.value !== resolvedValue) return void 0;
|
|
2181
|
+
if (!rendersLiteralTo(rendered.spelling, parentSecrets, resolvedValue)) return void 0;
|
|
2182
|
+
return rendered.spelling;
|
|
2183
|
+
}
|
|
2184
|
+
function inheritedRenderedToken(parentSecrets, parameterName, value, plaintext) {
|
|
2185
|
+
const spelling = inheritedParameterExpression(parentSecrets, parameterName, value);
|
|
2186
|
+
if (typeof spelling !== "string" || isSingleDynamicReferenceToken(spelling)) return void 0;
|
|
2187
|
+
return renderedTokenOf(spelling, parentSecrets, plaintext);
|
|
2188
|
+
}
|
|
2189
|
+
function withdrawRenderedParameterSpelling(parentSecrets, parameterName) {
|
|
2190
|
+
const rendered = renderedParameterSpellings.get(parentSecrets);
|
|
2191
|
+
if (rendered?.has(parameterName)) rendered.set(parameterName, null);
|
|
2192
|
+
}
|
|
2193
|
+
function inheritedRenderedSpan(childSecrets, key, text) {
|
|
2194
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
2195
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
2196
|
+
for (const name of reads.names) {
|
|
2197
|
+
if (crossStackSourceKey({ Ref: name }) !== key) continue;
|
|
2198
|
+
const value = renderedParameterSpellings.get(reads.parent)?.get(name)?.value;
|
|
2199
|
+
if (value === void 0 || text !== void 0 && text !== value) return void 0;
|
|
2200
|
+
if (carriesChildOnlyPlaintext(value, childSecrets, reads.parent)) return void 0;
|
|
2201
|
+
const spelling = inheritedParameterExpression(reads.parent, name, value);
|
|
2202
|
+
if (typeof spelling !== "string") return void 0;
|
|
2203
|
+
if (redactForState(spelling, {
|
|
2204
|
+
provenance: "value-scan",
|
|
2205
|
+
secrets: childSecrets
|
|
2206
|
+
}) !== spelling) return void 0;
|
|
2207
|
+
return {
|
|
2208
|
+
value,
|
|
2209
|
+
spelling
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
const inheritedParameterReads = /* @__PURE__ */ new WeakMap();
|
|
2214
|
+
const POISONED_PARAMETER_READS = Symbol("cdkd.inherited-parameter-reads.poisoned");
|
|
2215
|
+
function parameterReadsFor(childSecrets, parentSecrets) {
|
|
2216
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
2217
|
+
if (reads === void 0) {
|
|
2218
|
+
const created = {
|
|
2219
|
+
parent: parentSecrets,
|
|
2220
|
+
names: /* @__PURE__ */ new Set(),
|
|
2221
|
+
values: /* @__PURE__ */ new Map()
|
|
2222
|
+
};
|
|
2223
|
+
inheritedParameterReads.set(childSecrets, created);
|
|
2224
|
+
return created;
|
|
2225
|
+
}
|
|
2226
|
+
if (typeof reads === "symbol") return void 0;
|
|
2227
|
+
if (reads.parent !== parentSecrets) {
|
|
2228
|
+
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
return reads;
|
|
2232
|
+
}
|
|
2233
|
+
function recordInheritedParameterValue(childSecrets, parentSecrets, parameterName, value, declared) {
|
|
2234
|
+
const reads = parameterReadsFor(childSecrets, parentSecrets);
|
|
2235
|
+
if (reads === void 0) return;
|
|
2236
|
+
if (declared !== void 0) {
|
|
2237
|
+
if (reads.declared === void 0) reads.declared = declared;
|
|
2238
|
+
else if (reads.declared.size !== declared.size || [...declared].some((name) => !reads.declared.has(name))) {
|
|
2239
|
+
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
if (reads.values.has(parameterName)) {
|
|
2244
|
+
if (!deepEqualJsonValue(reads.values.get(parameterName), value)) inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
2245
|
+
return;
|
|
2214
2246
|
}
|
|
2247
|
+
reads.values.set(parameterName, value);
|
|
2248
|
+
}
|
|
2249
|
+
function recordInheritedParameterRead(childSecrets, parentSecrets, parameterName) {
|
|
2250
|
+
parameterReadsFor(childSecrets, parentSecrets)?.names.add(parameterName);
|
|
2251
|
+
}
|
|
2252
|
+
function redactInheritedParameterValue(parentSecrets, parameterName, value) {
|
|
2253
|
+
return inheritedParameterExpression(parentSecrets, parameterName, value) ?? redactForState(value, {
|
|
2254
|
+
provenance: "value-scan",
|
|
2255
|
+
secrets: parentSecrets
|
|
2256
|
+
});
|
|
2257
|
+
}
|
|
2258
|
+
function persistedInheritedParameterValue(parentSecrets, parameterName, value) {
|
|
2259
|
+
if (attributionRefusedParameters.get(parentSecrets)?.get(parameterName) !== "sub-floor") return redactInheritedParameterValue(parentSecrets, parameterName, value);
|
|
2260
|
+
const certified = inheritedParameterExpression(parentSecrets, parameterName, value);
|
|
2261
|
+
if (certified !== void 0) return certified;
|
|
2262
|
+
const scanned = redactForState(value, {
|
|
2263
|
+
provenance: "value-scan",
|
|
2264
|
+
secrets: parentSecrets
|
|
2265
|
+
});
|
|
2266
|
+
const masked = (text) => typeof text === "string" && literalTextHoldsSubFloorSecret(text, parentSecrets) ? "***" : text;
|
|
2267
|
+
return Array.isArray(scanned) ? scanned.map(masked) : masked(scanned);
|
|
2268
|
+
}
|
|
2269
|
+
function keepsInheritedSubFloorText(answer, secrets) {
|
|
2270
|
+
const holds = (text) => typeof text !== "string" || literalTextHoldsSubFloorSecret(text, secrets);
|
|
2271
|
+
return Array.isArray(answer) ? answer.some(holds) : holds(answer);
|
|
2272
|
+
}
|
|
2273
|
+
function scannedSubFloorRead(bag, source, secrets) {
|
|
2274
|
+
if (readsThroughSplit(source, 0)) return "***";
|
|
2275
|
+
const scanned = redactForState(bag, {
|
|
2276
|
+
provenance: "value-scan",
|
|
2277
|
+
secrets
|
|
2278
|
+
});
|
|
2279
|
+
const masked = (text) => keepsInheritedSubFloorText(text, secrets) ? "***" : text;
|
|
2280
|
+
return Array.isArray(scanned) ? scanned.map(masked) : masked(scanned);
|
|
2281
|
+
}
|
|
2282
|
+
function positionByInheritedParameter(bag, source, secrets) {
|
|
2283
|
+
const keys = Object.keys(source);
|
|
2284
|
+
if (keys.length !== 1 || keys[0] !== "Ref") return void 0;
|
|
2285
|
+
const name = source["Ref"];
|
|
2286
|
+
if (typeof name !== "string") return void 0;
|
|
2287
|
+
const reads = inheritedParameterReads.get(secrets);
|
|
2288
|
+
if (reads === void 0 || typeof reads === "symbol" || !reads.names.has(name)) return;
|
|
2289
|
+
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
2215
2290
|
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
2291
|
+
const answer = persistedInheritedParameterValue(reads.parent, name, bag);
|
|
2216
2292
|
if (!deepEqualJsonValue(redactForState(answer, {
|
|
2217
2293
|
provenance: "value-scan",
|
|
2218
2294
|
secrets
|
|
2219
2295
|
}), answer)) return void 0;
|
|
2220
2296
|
return answer;
|
|
2221
2297
|
}
|
|
2298
|
+
function inheritSubFloorPlaintexts(childSecrets, parentSecrets) {
|
|
2299
|
+
const carried = new Set(inheritedSubFloorPlaintexts.get(childSecrets));
|
|
2300
|
+
for (const plaintext of inheritedSubFloorPlaintexts.get(parentSecrets) ?? []) carried.add(plaintext);
|
|
2301
|
+
for (const [plaintext, expression] of parentSecrets) {
|
|
2302
|
+
if (plaintext === "" || plaintext.length >= 4) continue;
|
|
2303
|
+
if (!isMaskLeaf(expression)) carried.add(plaintext);
|
|
2304
|
+
}
|
|
2305
|
+
if (carried.size > 0) inheritedSubFloorPlaintexts.set(childSecrets, carried);
|
|
2306
|
+
}
|
|
2307
|
+
function carriesInheritedRedaction(secrets) {
|
|
2308
|
+
if (secrets === void 0) return false;
|
|
2309
|
+
return hasMaskableValues(secrets) || carriesSubFloorEvidence(secrets);
|
|
2310
|
+
}
|
|
2311
|
+
function readsThroughSplit(node, depth) {
|
|
2312
|
+
if (depth > 64) return true;
|
|
2313
|
+
if (Array.isArray(node)) return node.some((item) => readsThroughSplit(item, depth + 1));
|
|
2314
|
+
if (node === null || typeof node !== "object") return false;
|
|
2315
|
+
return Object.entries(node).some(([key, inner]) => key === "Fn::Split" || readsThroughSplit(inner, depth + 1));
|
|
2316
|
+
}
|
|
2222
2317
|
|
|
2223
|
-
// src/deployment/secret-redaction/
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2318
|
+
// src/deployment/secret-redaction/nested-stack/pseudo-parameters.ts
|
|
2319
|
+
const REREAD_PSEUDO_PARAMETERS = /* @__PURE__ */ new Set([
|
|
2320
|
+
"AWS::Region",
|
|
2321
|
+
"AWS::Partition",
|
|
2322
|
+
"AWS::URLSuffix",
|
|
2323
|
+
"AWS::AccountId"
|
|
2324
|
+
]);
|
|
2325
|
+
function templateRereadsAccountId(template) {
|
|
2326
|
+
if (template === void 0) return false;
|
|
2327
|
+
const resources = template.Resources !== null && typeof template.Resources === "object" ? template.Resources : void 0;
|
|
2328
|
+
const cached = resources && accountRereadVerdicts.get(resources);
|
|
2329
|
+
if (cached !== void 0 && cached.outputs === template.Outputs) return cached.verdict;
|
|
2330
|
+
const parts = resources ? Object.values(resources) : [];
|
|
2331
|
+
if (template.Outputs !== void 0) parts.push(template.Outputs);
|
|
2332
|
+
const verdict = parts.some(partRereadsAccountId);
|
|
2333
|
+
if (resources) accountRereadVerdicts.set(resources, {
|
|
2334
|
+
outputs: template.Outputs,
|
|
2335
|
+
verdict
|
|
2336
|
+
});
|
|
2337
|
+
return verdict;
|
|
2227
2338
|
}
|
|
2228
|
-
const
|
|
2229
|
-
function
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2339
|
+
const accountRereadVerdicts = /* @__PURE__ */ new WeakMap();
|
|
2340
|
+
function partRereadsAccountId(part) {
|
|
2341
|
+
let trigger = false;
|
|
2342
|
+
let account = false;
|
|
2343
|
+
const pending = [part];
|
|
2344
|
+
while (pending.length > 0 && !(trigger && account)) {
|
|
2345
|
+
const node = pending.pop();
|
|
2346
|
+
if (Array.isArray(node)) {
|
|
2347
|
+
pending.push(...node);
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
if (node === null || typeof node !== "object") continue;
|
|
2351
|
+
for (const [key, value] of Object.entries(node)) {
|
|
2352
|
+
if (REREAD_TRIGGERS.has(key)) trigger = true;
|
|
2353
|
+
if (key === "Ref" && value === "AWS::AccountId") account = true;
|
|
2354
|
+
if (key === "Fn::Sub") {
|
|
2355
|
+
const text = Array.isArray(value) ? value[0] : value;
|
|
2356
|
+
if (typeof text === "string" && text.includes("${AWS::AccountId}")) account = true;
|
|
2357
|
+
}
|
|
2358
|
+
pending.push(value);
|
|
2359
|
+
}
|
|
2233
2360
|
}
|
|
2234
|
-
|
|
2235
|
-
out.push(part);
|
|
2361
|
+
return trigger && account;
|
|
2236
2362
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
if (
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2363
|
+
const inheritedPseudoParameters = /* @__PURE__ */ new WeakMap();
|
|
2364
|
+
const POISONED_PSEUDO_PARAMETERS = Symbol("cdkd.inherited-pseudo-parameters.poisoned");
|
|
2365
|
+
function recordInheritedPseudoParameters(inheritedSecrets, values) {
|
|
2366
|
+
let table = inheritedPseudoParameters.get(inheritedSecrets);
|
|
2367
|
+
if (table === POISONED_PSEUDO_PARAMETERS) return;
|
|
2368
|
+
if (table === void 0) {
|
|
2369
|
+
table = /* @__PURE__ */ new Map();
|
|
2370
|
+
inheritedPseudoParameters.set(inheritedSecrets, table);
|
|
2371
|
+
}
|
|
2372
|
+
for (const [name, value] of values) {
|
|
2373
|
+
if (!REREAD_PSEUDO_PARAMETERS.has(name) || typeof value !== "string") continue;
|
|
2374
|
+
const known = table.get(name);
|
|
2375
|
+
if (known !== void 0 && known !== value) {
|
|
2376
|
+
inheritedPseudoParameters.set(inheritedSecrets, POISONED_PSEUDO_PARAMETERS);
|
|
2246
2377
|
return;
|
|
2247
2378
|
}
|
|
2248
|
-
|
|
2249
|
-
return pushPlaceholderPart(out, keyedPart(value), budget);
|
|
2379
|
+
table.set(name, value);
|
|
2250
2380
|
}
|
|
2251
|
-
pushPlaceholderPart(out, UNKNOWN_PART, budget);
|
|
2252
2381
|
}
|
|
2253
|
-
function
|
|
2254
|
-
const
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2382
|
+
function pseudoBindingOf(parentSecrets) {
|
|
2383
|
+
const table = inheritedPseudoParameters.get(parentSecrets);
|
|
2384
|
+
return (name) => table instanceof Map && table.has(name) ? { value: table.get(name) } : void 0;
|
|
2385
|
+
}
|
|
2386
|
+
function inheritedPseudoValue(parentSecrets, name) {
|
|
2387
|
+
const bound = pseudoBindingOf(parentSecrets)(name)?.value;
|
|
2388
|
+
return typeof bound === "string" ? bound : void 0;
|
|
2389
|
+
}
|
|
2390
|
+
function inheritedPseudoSpan(childSecrets, key) {
|
|
2391
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
2392
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
2393
|
+
for (const name of REREAD_PSEUDO_PARAMETERS) if (crossStackSourceKey({ Ref: name }) === key) return inheritedPseudoValue(reads.parent, name);
|
|
2394
|
+
}
|
|
2395
|
+
const REREAD_TRIGGERS = /* @__PURE__ */ new Set([
|
|
2396
|
+
"Fn::Select",
|
|
2397
|
+
"Fn::Split",
|
|
2398
|
+
"Fn::If"
|
|
2399
|
+
]);
|
|
2400
|
+
|
|
2401
|
+
// src/deployment/secret-redaction/nested-stack/reread.ts
|
|
2402
|
+
const MAX_REREAD_DEPTH = 16;
|
|
2403
|
+
const MAX_REREAD_CONDITIONS = 4;
|
|
2404
|
+
const REREAD_NO_VALUE = Symbol("cdkd.reread.no-value");
|
|
2405
|
+
function splitOutsideDynamicReferences(text, delimiter, standsForSecret) {
|
|
2406
|
+
if (delimiter === "") return text.split(delimiter);
|
|
2407
|
+
const spans = dynamicReferenceSpans(text).filter((span) => {
|
|
2408
|
+
const token = text.slice(span.start, span.end);
|
|
2409
|
+
return spanNamesResolvableService(token) && standsForSecret(token);
|
|
2410
|
+
});
|
|
2411
|
+
if (spans.length === 0) return text.split(delimiter);
|
|
2412
|
+
const pieces = [];
|
|
2413
|
+
let cursor = 0;
|
|
2414
|
+
let from = 0;
|
|
2415
|
+
for (;;) {
|
|
2416
|
+
const at = text.indexOf(delimiter, from);
|
|
2417
|
+
if (at === -1) break;
|
|
2418
|
+
const end = at + delimiter.length;
|
|
2419
|
+
const token = spans.find((span) => span.start < end && at < span.end);
|
|
2420
|
+
if (token !== void 0) {
|
|
2421
|
+
from = token.end;
|
|
2422
|
+
continue;
|
|
2289
2423
|
}
|
|
2290
|
-
|
|
2291
|
-
|
|
2424
|
+
pieces.push(text.slice(cursor, at));
|
|
2425
|
+
cursor = end;
|
|
2426
|
+
from = end;
|
|
2292
2427
|
}
|
|
2293
|
-
|
|
2428
|
+
pieces.push(text.slice(cursor));
|
|
2429
|
+
return pieces;
|
|
2294
2430
|
}
|
|
2295
|
-
function
|
|
2296
|
-
|
|
2297
|
-
remaining: bag.length * 2 + 16,
|
|
2298
|
-
exhausted: false
|
|
2299
|
-
};
|
|
2300
|
-
const out = [];
|
|
2301
|
-
if (!appendParameterPlaceholderParts(source, out, budget, 0)) return void 0;
|
|
2302
|
-
return budget.exhausted ? void 0 : out;
|
|
2431
|
+
function standsForInheritedSecret(parentSecrets, token) {
|
|
2432
|
+
return parentSecrets !== void 0 && resolvedPlaintextOf(parentSecrets, token) !== void 0;
|
|
2303
2433
|
}
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
if (
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
const spans = [];
|
|
2316
|
-
for (const part of parts) {
|
|
2317
|
-
let rendered;
|
|
2318
|
-
let persisted;
|
|
2319
|
-
if (typeof part === "string") {
|
|
2320
|
-
rendered = part;
|
|
2321
|
-
persisted = part;
|
|
2322
|
-
} else {
|
|
2323
|
-
let expression;
|
|
2324
|
-
let plaintext = "";
|
|
2325
|
-
if (part !== UNKNOWN_PART) {
|
|
2326
|
-
const association = associations?.get(part.key);
|
|
2327
|
-
if (association !== void 0 && typeof association !== "symbol") {
|
|
2328
|
-
plaintext = association.plaintext;
|
|
2329
|
-
expression = certifiedExpressionForLeaf(secrets, association, plaintext);
|
|
2330
|
-
}
|
|
2331
|
-
if (expression === void 0) {
|
|
2332
|
-
const inherited = inheritedRenderedSpan(secrets, part.key);
|
|
2333
|
-
if (inherited !== void 0) {
|
|
2334
|
-
plaintext = inherited.value;
|
|
2335
|
-
expression = inherited.spelling;
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
const pseudo = expression === void 0 && part !== UNKNOWN_PART ? inheritedPseudoSpan(secrets, part.key) : void 0;
|
|
2340
|
-
if (pseudo !== void 0) {
|
|
2341
|
-
side[0] += pseudo;
|
|
2342
|
-
side[1] += pseudo;
|
|
2343
|
-
continue;
|
|
2344
|
-
}
|
|
2345
|
-
if (expression === void 0) {
|
|
2346
|
-
if (unknown) return void 0;
|
|
2347
|
-
unknown = true;
|
|
2348
|
-
side = after;
|
|
2349
|
-
continue;
|
|
2350
|
-
}
|
|
2351
|
-
rendered = plaintext;
|
|
2352
|
-
persisted = expression;
|
|
2353
|
-
certified += 1;
|
|
2354
|
-
spans.push([
|
|
2355
|
-
side,
|
|
2356
|
-
side[0].length,
|
|
2357
|
-
plaintext.length
|
|
2358
|
-
]);
|
|
2434
|
+
const plainSplit = (text, delimiter) => text.split(delimiter);
|
|
2435
|
+
function evaluatePureRead(node, bind, pseudo, split, choose, depth = 0) {
|
|
2436
|
+
if (depth > MAX_REREAD_DEPTH) return void 0;
|
|
2437
|
+
const evaluate = (child) => evaluatePureRead(child, bind, pseudo, split, choose, depth + 1);
|
|
2438
|
+
if (typeof node === "string") return mentionsDynamicReference(node) ? void 0 : { value: node };
|
|
2439
|
+
if (Array.isArray(node)) {
|
|
2440
|
+
const out = [];
|
|
2441
|
+
for (const element of node) {
|
|
2442
|
+
const evaluated = evaluate(element);
|
|
2443
|
+
if (evaluated === void 0 || evaluated.value === REREAD_NO_VALUE) return void 0;
|
|
2444
|
+
out.push(evaluated.value);
|
|
2359
2445
|
}
|
|
2360
|
-
|
|
2361
|
-
side[1] += persisted;
|
|
2446
|
+
return { value: out };
|
|
2362
2447
|
}
|
|
2363
|
-
if (
|
|
2364
|
-
|
|
2365
|
-
if (
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
if (
|
|
2370
|
-
|
|
2371
|
-
const middle = bag.slice(before[0].length, bag.length - after[0].length);
|
|
2372
|
-
if (redactForState(middle, {
|
|
2373
|
-
provenance: "value-scan",
|
|
2374
|
-
secrets
|
|
2375
|
-
}) !== middle) return void 0;
|
|
2376
|
-
persisted = before[1] + middle + after[1];
|
|
2448
|
+
if (!isPlainObject(node)) return void 0;
|
|
2449
|
+
const keys = Object.keys(node);
|
|
2450
|
+
if (keys.length !== 1) return void 0;
|
|
2451
|
+
const key = keys[0];
|
|
2452
|
+
const args = node[key];
|
|
2453
|
+
if (key === "Ref") {
|
|
2454
|
+
if (args === "AWS::NoValue") return { value: REREAD_NO_VALUE };
|
|
2455
|
+
return typeof args === "string" ? bindReadName(args, bind, pseudo) : void 0;
|
|
2377
2456
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
if (plaintext.length < 4) continue;
|
|
2384
|
-
for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
|
|
2385
|
-
const end = at + plaintext.length;
|
|
2386
|
-
for (const [start, length] of spans) if (at < start + length && end > start && (at < start || end > start + length)) return void 0;
|
|
2387
|
-
}
|
|
2457
|
+
if (key === "Fn::If") {
|
|
2458
|
+
if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return void 0;
|
|
2459
|
+
const tookTrue = choose(args[0], node);
|
|
2460
|
+
if (tookTrue === void 0) return void 0;
|
|
2461
|
+
return evaluate(tookTrue ? args[1] : args[2]);
|
|
2388
2462
|
}
|
|
2389
|
-
if (
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
const recorded = resolution.parameterSpans;
|
|
2399
|
-
if (recorded === void 0) return void 0;
|
|
2400
|
-
let previousEnd = 0;
|
|
2401
|
-
let cursor = 0;
|
|
2402
|
-
let persisted = "";
|
|
2403
|
-
const gaps = [];
|
|
2404
|
-
const certified = [];
|
|
2405
|
-
for (const { start, length, key } of recorded) {
|
|
2406
|
-
if (!(start >= previousEnd && length > 0 && start + length <= bag.length)) return void 0;
|
|
2407
|
-
previousEnd = start + length;
|
|
2408
|
-
const text = bag.slice(start, start + length);
|
|
2409
|
-
const association = associations?.get(key);
|
|
2410
|
-
const expression = (association !== void 0 && typeof association !== "symbol" ? certifiedExpressionForLeaf(secrets, association, text) : void 0) ?? inheritedRenderedSpan(secrets, key, text)?.spelling;
|
|
2411
|
-
if (expression === void 0) continue;
|
|
2412
|
-
const gap = bag.slice(cursor, start);
|
|
2413
|
-
gaps.push(gap);
|
|
2414
|
-
persisted += gap + expression;
|
|
2415
|
-
certified.push([start, length]);
|
|
2416
|
-
cursor = start + length;
|
|
2463
|
+
if (key === "Fn::Sub") return evaluatePureSub(args, bind, pseudo, evaluate);
|
|
2464
|
+
if (!Array.isArray(args) || args.length !== 2) return void 0;
|
|
2465
|
+
if (key === "Fn::Select") {
|
|
2466
|
+
const index = args[0];
|
|
2467
|
+
const position = typeof index === "number" ? index : typeof index === "string" && /^(0|[1-9][0-9]*)$/.test(index) ? Number(index) : void 0;
|
|
2468
|
+
if (position === void 0 || !Number.isSafeInteger(position) || position < 0) return void 0;
|
|
2469
|
+
const list = evaluate(args[1]);
|
|
2470
|
+
if (list === void 0 || !Array.isArray(list.value) || position >= list.value.length) return;
|
|
2471
|
+
return { value: list.value[position] };
|
|
2417
2472
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
const ARRAY_IDENTITY_KEYS = ["Name", "Key"];
|
|
2431
|
-
function isUniquelyKeyedBy(items, key) {
|
|
2432
|
-
if (items.length === 0) return false;
|
|
2433
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2434
|
-
for (const item of items) {
|
|
2435
|
-
if (!isPlainObject(item) || !Object.hasOwn(item, key)) return false;
|
|
2436
|
-
const id = item[key];
|
|
2437
|
-
if (typeof id !== "string" || id === "") return false;
|
|
2438
|
-
if (seen.has(id)) return false;
|
|
2439
|
-
seen.add(id);
|
|
2473
|
+
const delimiter = args[0];
|
|
2474
|
+
if (typeof delimiter !== "string") return void 0;
|
|
2475
|
+
if (key === "Fn::Split") {
|
|
2476
|
+
const value = evaluate(args[1]);
|
|
2477
|
+
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
2478
|
+
return { value: split(value.value, delimiter) };
|
|
2479
|
+
}
|
|
2480
|
+
if (key === "Fn::Join") {
|
|
2481
|
+
const parts = evaluate(args[1]);
|
|
2482
|
+
if (parts === void 0 || !Array.isArray(parts.value)) return void 0;
|
|
2483
|
+
if (!parts.value.every((part) => typeof part === "string")) return void 0;
|
|
2484
|
+
return { value: parts.value.join(delimiter) };
|
|
2440
2485
|
}
|
|
2441
|
-
return true;
|
|
2442
|
-
}
|
|
2443
|
-
function identityKeyFor(bag, source) {
|
|
2444
|
-
for (const key of ARRAY_IDENTITY_KEYS) if (isUniquelyKeyedBy(bag, key) && isUniquelyKeyedBy(source, key)) return key;
|
|
2445
|
-
}
|
|
2446
|
-
function positionListByCrossStackSource(bag, source, secrets) {
|
|
2447
|
-
const association = associationForSource(source, secrets);
|
|
2448
|
-
if (association === void 0) return void 0;
|
|
2449
|
-
return certifiedListForLeaf(secrets, association, bag);
|
|
2450
2486
|
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
]);
|
|
2460
|
-
function arrayElementDrop(element, depth = 0) {
|
|
2461
|
-
if (depth > 16) return "unknown";
|
|
2462
|
-
if (!isPlainObject(element)) return "never";
|
|
2463
|
-
if (Object.hasOwn(element, "Ref")) return element["Ref"] === "AWS::NoValue" ? "always" : "never";
|
|
2464
|
-
const keys = Object.keys(element);
|
|
2465
|
-
if (keys.filter((key) => key.startsWith("Fn::") || key === "Condition").length === 0) return "never";
|
|
2466
|
-
if (keys.length !== 1) return "unknown";
|
|
2467
|
-
if (NEVER_DROPPING_INTRINSICS.has(keys[0])) return "never";
|
|
2468
|
-
if (keys[0] !== "Fn::If") return "unknown";
|
|
2469
|
-
const args = element["Fn::If"];
|
|
2470
|
-
if (!Array.isArray(args) || args.length !== 3) return "unknown";
|
|
2471
|
-
const branches = [arrayElementDrop(args[1], depth + 1), arrayElementDrop(args[2], depth + 1)];
|
|
2472
|
-
if (branches.includes("unknown")) return "unknown";
|
|
2473
|
-
if (branches.every((branch) => branch === "never")) return "never";
|
|
2474
|
-
if (branches.every((branch) => branch === "always")) return "always";
|
|
2475
|
-
return "maybe";
|
|
2476
|
-
}
|
|
2477
|
-
function sourceElementsKeptFor(source, bagLength, secrets) {
|
|
2478
|
-
const recorded = secrets && droppedArrayElementsOf(secrets, source);
|
|
2479
|
-
if (recorded !== void 0) {
|
|
2480
|
-
if (source.length - recorded.length !== bagLength) return void 0;
|
|
2481
|
-
return source.filter((_, i) => !recorded.includes(i));
|
|
2482
|
-
}
|
|
2483
|
-
const drops = source.map((element) => arrayElementDrop(element));
|
|
2484
|
-
if (drops.includes("unknown")) return void 0;
|
|
2485
|
-
const always = drops.filter((drop) => drop === "always").length;
|
|
2486
|
-
const maybe = drops.filter((drop) => drop === "maybe").length;
|
|
2487
|
-
const dropped = source.length - bagLength;
|
|
2488
|
-
let dropMaybe;
|
|
2489
|
-
if (dropped === always) dropMaybe = false;
|
|
2490
|
-
else if (dropped === always + maybe) dropMaybe = true;
|
|
2491
|
-
else return void 0;
|
|
2492
|
-
return source.filter((_, i) => drops[i] === "never" || drops[i] === "maybe" && !dropMaybe);
|
|
2493
|
-
}
|
|
2494
|
-
function keptLiteralsCorroborate(kept, bag, secrets) {
|
|
2495
|
-
return kept.every((element, i) => keptElementCorroborates(element, bag[i], secrets));
|
|
2496
|
-
}
|
|
2497
|
-
function isIntrinsicNode(value) {
|
|
2498
|
-
if (!isPlainObject(value)) return false;
|
|
2499
|
-
const keys = Object.keys(value);
|
|
2500
|
-
return keys.length === 1 && (keys[0] === "Ref" || keys[0].startsWith("Fn::"));
|
|
2501
|
-
}
|
|
2502
|
-
function keptElementCorroborates(source, bag, secrets, depth = 0) {
|
|
2503
|
-
if (depth > 16) return false;
|
|
2504
|
-
if (typeof source === "string") {
|
|
2505
|
-
if (!source.includes("{{resolve:")) return source === bag;
|
|
2506
|
-
return isSingleDynamicReferenceToken(source) && resolvedPlaintextOf(secrets, source) === bag;
|
|
2507
|
-
}
|
|
2508
|
-
if (source === null || typeof source !== "object") return source === bag;
|
|
2509
|
-
if (isIntrinsicNode(source)) return true;
|
|
2510
|
-
if (Array.isArray(source)) return Array.isArray(bag) && bag.length === source.length && source.every((element, i) => keptElementCorroborates(element, bag[i], secrets, depth + 1));
|
|
2511
|
-
if (!isPlainObject(source) || !isPlainObject(bag)) return false;
|
|
2512
|
-
if (Object.keys(bag).some((key) => !Object.hasOwn(source, key))) return false;
|
|
2513
|
-
return Object.entries(source).every(([key, value]) => Object.hasOwn(bag, key) ? keptElementCorroborates(value, bag[key], secrets, depth + 1) : arrayElementDrop(value) === "always" || arrayElementDrop(value) === "maybe");
|
|
2514
|
-
}
|
|
2515
|
-
function corroboratesWhateverResolves(source, depth = 0) {
|
|
2516
|
-
if (depth > 16) return false;
|
|
2517
|
-
if (typeof source === "string") return !source.includes("{{resolve:");
|
|
2518
|
-
if (source === null || typeof source !== "object") return true;
|
|
2519
|
-
if (isIntrinsicNode(source)) return true;
|
|
2520
|
-
if (Array.isArray(source)) return source.every((element) => arrayElementDrop(element) === "never" && corroboratesWhateverResolves(element, depth + 1));
|
|
2521
|
-
if (!isPlainObject(source)) return false;
|
|
2522
|
-
if (Object.keys(source).some((key) => key === "Ref" || key.startsWith("Fn::"))) return false;
|
|
2523
|
-
return Object.values(source).every((value) => arrayElementDrop(value) !== "unknown" && corroboratesWhateverResolves(value, depth + 1));
|
|
2524
|
-
}
|
|
2525
|
-
function arrayPairsWhateverDrops(source) {
|
|
2526
|
-
if (!source.some((element) => isPlainObject(element) && (Object.hasOwn(element, "Fn::If") || element["Ref"] === "AWS::NoValue" || Array.isArray(element["Fn::FindInMap"]) && element["Fn::FindInMap"].length > 3))) return true;
|
|
2527
|
-
return source.every((element) => corroboratesWhateverResolves(element));
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
|
-
// src/deployment/secret-redaction/redact-path/subtree.ts
|
|
2531
|
-
function isReadbackProjectedFromState(rules) {
|
|
2532
|
-
return rules.trustAnyExpression && !rules.descendArrays && rules.sourceIsSameGeneration;
|
|
2533
|
-
}
|
|
2534
|
-
function subtreeHasDynamicReference(value) {
|
|
2535
|
-
if (isDynamicReferenceString(value)) return true;
|
|
2536
|
-
if (Array.isArray(value)) return value.some(subtreeHasDynamicReference);
|
|
2537
|
-
if (isPlainObject(value)) return Object.values(value).some(subtreeHasDynamicReference);
|
|
2538
|
-
return false;
|
|
2539
|
-
}
|
|
2540
|
-
function pathCrossesDottedKey(bag, path) {
|
|
2541
|
-
const segments = path.split(".");
|
|
2542
|
-
let cursor = bag;
|
|
2543
|
-
for (let i = 0; i < segments.length; i++) {
|
|
2544
|
-
if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor)) return false;
|
|
2545
|
-
const rest = segments.slice(i).join(".");
|
|
2546
|
-
for (const key of Object.keys(cursor)) if (key.includes(".") && (rest === key || rest.startsWith(`${key}.`))) return true;
|
|
2547
|
-
if (!Object.hasOwn(cursor, segments[i])) return false;
|
|
2548
|
-
cursor = cursor[segments[i]];
|
|
2549
|
-
}
|
|
2550
|
-
return false;
|
|
2551
|
-
}
|
|
2552
|
-
|
|
2553
|
-
// src/deployment/secret-redaction/redact-path/definition.ts
|
|
2554
|
-
const DEFINITION_SOURCE_KEYS = [
|
|
2555
|
-
"DefinitionSubstitutions",
|
|
2556
|
-
"DefinitionString",
|
|
2557
|
-
"Definition"
|
|
2558
|
-
];
|
|
2559
|
-
const RENDERED_DEFINITION_KEYS = /* @__PURE__ */ new Set(["Definition", "DefinitionString"]);
|
|
2560
|
-
function definitionSourceCarriesSecret(source) {
|
|
2561
|
-
return DEFINITION_SOURCE_KEYS.some((k) => Object.hasOwn(source, k) && (subtreeHasDynamicReference(source[k]) || carriesSecretMask(source[k])));
|
|
2562
|
-
}
|
|
2563
|
-
function nameScalarSecrets(value, secrets) {
|
|
2564
|
-
const byValue = /* @__PURE__ */ new Set();
|
|
2565
|
-
for (const plaintext of secrets.keys()) try {
|
|
2566
|
-
const parsed = JSON.parse(plaintext);
|
|
2567
|
-
if (typeof parsed === "number" && Number.isFinite(parsed) || typeof parsed === "boolean") byValue.add(parsed);
|
|
2568
|
-
} catch {}
|
|
2569
|
-
if (byValue.size === 0) return value;
|
|
2570
|
-
const walk = (node) => {
|
|
2571
|
-
if (typeof node === "number" || typeof node === "boolean") {
|
|
2572
|
-
if (typeof node === "number" && !Number.isFinite(node)) return node;
|
|
2573
|
-
return secrets.has(String(node)) || byValue.has(node) ? "***" : node;
|
|
2574
|
-
}
|
|
2575
|
-
if (Array.isArray(node)) return node.map(walk);
|
|
2576
|
-
if (isPlainObject(node) && hasPlainPrototype(node)) {
|
|
2577
|
-
const out = Object.create(null);
|
|
2578
|
-
for (const [k, v] of Object.entries(node)) out[k] = walk(v);
|
|
2579
|
-
return out;
|
|
2580
|
-
}
|
|
2581
|
-
return node;
|
|
2582
|
-
};
|
|
2583
|
-
return walk(value);
|
|
2584
|
-
}
|
|
2585
|
-
const SENTINEL_IN_STRING = "";
|
|
2586
|
-
const SENTINEL_OUT_OF_STRING = "";
|
|
2587
|
-
function substitutionIsSecret(value) {
|
|
2588
|
-
return subtreeHasDynamicReference(value) || value.includes("***");
|
|
2589
|
-
}
|
|
2590
|
-
function sentinelDefinitionOf(source) {
|
|
2591
|
-
const subs = source["DefinitionSubstitutions"];
|
|
2592
|
-
const values = /* @__PURE__ */ new Map();
|
|
2593
|
-
if (isPlainObject(subs)) {
|
|
2594
|
-
for (const [name, value] of Object.entries(subs)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values.set(name, String(value));
|
|
2595
|
-
}
|
|
2596
|
-
for (const key of ["DefinitionString", "Definition"]) {
|
|
2597
|
-
if (!Object.hasOwn(source, key)) continue;
|
|
2598
|
-
const raw = source[key];
|
|
2599
|
-
const body = typeof raw === "string" ? raw : isPlainObject(raw) ? JSON.stringify(raw) : void 0;
|
|
2600
|
-
if (body === void 0) continue;
|
|
2601
|
-
if (body.includes(SENTINEL_IN_STRING) || body.includes(SENTINEL_OUT_OF_STRING) || /\\u[eE]00[01]/.test(body)) continue;
|
|
2602
|
-
const names = [];
|
|
2603
|
-
let text = "";
|
|
2604
|
-
let inString = false;
|
|
2605
|
-
let escaped = false;
|
|
2606
|
-
const feed = (c) => {
|
|
2607
|
-
text += c;
|
|
2608
|
-
if (inString) {
|
|
2609
|
-
if (escaped) escaped = false;
|
|
2610
|
-
else if (c === "\\") escaped = true;
|
|
2611
|
-
else if (c === "\"") inString = false;
|
|
2612
|
-
} else if (c === "\"") inString = true;
|
|
2613
|
-
};
|
|
2614
|
-
for (let i = 0; i < body.length; i++) {
|
|
2615
|
-
if (body.startsWith("${", i)) {
|
|
2616
|
-
const end = body.indexOf("}", i + 2);
|
|
2617
|
-
const name = end === -1 ? void 0 : body.slice(i + 2, end);
|
|
2618
|
-
const value = name === void 0 ? void 0 : values.get(name);
|
|
2619
|
-
if (name !== void 0 && value !== void 0) {
|
|
2620
|
-
if (substitutionIsSecret(value)) {
|
|
2621
|
-
const index = names.push(name) - 1;
|
|
2622
|
-
text += inString ? `${SENTINEL_IN_STRING}${index}${SENTINEL_IN_STRING}` : `"${SENTINEL_OUT_OF_STRING}${index}${SENTINEL_OUT_OF_STRING}"`;
|
|
2623
|
-
} else for (const c of value) feed(c);
|
|
2624
|
-
i = end;
|
|
2625
|
-
continue;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
feed(body[i]);
|
|
2629
|
-
}
|
|
2630
|
-
let parsed;
|
|
2631
|
-
try {
|
|
2632
|
-
parsed = JSON.parse(text);
|
|
2633
|
-
} catch {
|
|
2634
|
-
continue;
|
|
2635
|
-
}
|
|
2636
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2637
|
-
const strings = /* @__PURE__ */ new Set();
|
|
2638
|
-
const scalars = /* @__PURE__ */ new Set();
|
|
2639
|
-
const secretLeaves = [];
|
|
2640
|
-
const marked = (t) => t.includes(SENTINEL_IN_STRING) || t.includes(SENTINEL_OUT_OF_STRING);
|
|
2641
|
-
const outOfString = new RegExp(`^${SENTINEL_OUT_OF_STRING}(\\d+)${SENTINEL_OUT_OF_STRING}$`);
|
|
2642
|
-
const inStringMarkers = new RegExp(`${SENTINEL_IN_STRING}(\\d+)${SENTINEL_IN_STRING}`, "g");
|
|
2643
|
-
const written = (t) => t.replace(inStringMarkers, (_m, i) => `\${${names[Number(i)]}}`);
|
|
2644
|
-
const walk = (node, path, shapes) => {
|
|
2645
|
-
if (typeof node === "string") {
|
|
2646
|
-
const m = outOfString.exec(node);
|
|
2647
|
-
if (m !== null) secretLeaves.push({
|
|
2648
|
-
path,
|
|
2649
|
-
shapes,
|
|
2650
|
-
outOfStringName: names[Number(m[1])],
|
|
2651
|
-
asWritten: void 0
|
|
2652
|
-
});
|
|
2653
|
-
else if (marked(node)) secretLeaves.push({
|
|
2654
|
-
path,
|
|
2655
|
-
shapes,
|
|
2656
|
-
outOfStringName: void 0,
|
|
2657
|
-
asWritten: written(node)
|
|
2658
|
-
});
|
|
2659
|
-
else strings.add(node);
|
|
2660
|
-
return;
|
|
2661
|
-
}
|
|
2662
|
-
if (typeof node === "number" || typeof node === "boolean") {
|
|
2663
|
-
scalars.add(node);
|
|
2664
|
-
return;
|
|
2665
|
-
}
|
|
2666
|
-
if (Array.isArray(node)) {
|
|
2667
|
-
node.forEach((item, i) => walk(item, [...path, i], [...shapes, node.length]));
|
|
2668
|
-
return;
|
|
2669
|
-
}
|
|
2670
|
-
if (isPlainObject(node)) {
|
|
2671
|
-
const own = new Set(Object.keys(node).map(written));
|
|
2672
|
-
for (const [k, v] of Object.entries(node)) {
|
|
2673
|
-
if (!marked(k)) keys.add(k);
|
|
2674
|
-
walk(v, [...path, written(k)], [...shapes, own]);
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
};
|
|
2678
|
-
walk(parsed, [], []);
|
|
2679
|
-
try {
|
|
2680
|
-
collectObjectKeys(JSON.parse(body), keys);
|
|
2681
|
-
} catch {}
|
|
2682
|
-
return {
|
|
2683
|
-
keys,
|
|
2684
|
-
strings,
|
|
2685
|
-
scalars,
|
|
2686
|
-
secretLeaves
|
|
2687
|
-
};
|
|
2487
|
+
function evaluatePureSub(args, bind, pseudo, evaluate) {
|
|
2488
|
+
const [text, variables] = typeof args === "string" ? [args, {}] : Array.isArray(args) && args.length === 2 ? [args[0], args[1]] : [void 0, void 0];
|
|
2489
|
+
if (typeof text !== "string" || mentionsDynamicReference(text) || !isPlainObject(variables)) return;
|
|
2490
|
+
const bound = /* @__PURE__ */ new Map();
|
|
2491
|
+
for (const [name, variable] of Object.entries(variables)) {
|
|
2492
|
+
const evaluated = evaluate(variable);
|
|
2493
|
+
if (evaluated === void 0 || typeof evaluated.value !== "string") return void 0;
|
|
2494
|
+
bound.set(name, evaluated.value);
|
|
2688
2495
|
}
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
if (
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
if (
|
|
2699
|
-
const
|
|
2700
|
-
if (
|
|
2701
|
-
|
|
2702
|
-
cursor = cursor[segment];
|
|
2496
|
+
let out = "";
|
|
2497
|
+
let cursor = 0;
|
|
2498
|
+
for (const match of text.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
2499
|
+
const name = match[2] ?? "";
|
|
2500
|
+
let replacement;
|
|
2501
|
+
if (match[1] === "!") replacement = `\${${name}}`;
|
|
2502
|
+
else if (name === "") replacement = match[0];
|
|
2503
|
+
else if (bound.has(name)) replacement = bound.get(name);
|
|
2504
|
+
else {
|
|
2505
|
+
if (name.includes(".")) return void 0;
|
|
2506
|
+
const value = bindReadName(name, bind, pseudo);
|
|
2507
|
+
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
2508
|
+
replacement = value.value;
|
|
2703
2509
|
}
|
|
2510
|
+
out += text.slice(cursor, match.index) + replacement;
|
|
2511
|
+
cursor = match.index + match[0].length;
|
|
2704
2512
|
}
|
|
2705
|
-
return { value: cursor };
|
|
2513
|
+
return { value: out + text.slice(cursor) };
|
|
2706
2514
|
}
|
|
2707
|
-
function
|
|
2708
|
-
if (
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2515
|
+
function bindReadName(name, bind, pseudo) {
|
|
2516
|
+
if (!name.startsWith("AWS::")) return bind(name);
|
|
2517
|
+
return bind(name) === void 0 ? pseudo(name) : void 0;
|
|
2518
|
+
}
|
|
2519
|
+
function collectRereadConditions(node, names, depth = 0) {
|
|
2520
|
+
if (depth > MAX_REREAD_DEPTH) return false;
|
|
2521
|
+
if (Array.isArray(node)) return node.every((element) => collectRereadConditions(element, names, depth + 1));
|
|
2522
|
+
if (!isPlainObject(node)) return true;
|
|
2523
|
+
if (Object.hasOwn(node, "Fn::If")) {
|
|
2524
|
+
const args = node["Fn::If"];
|
|
2525
|
+
if (!Array.isArray(args) || typeof args[0] !== "string") return false;
|
|
2526
|
+
names.add(args[0]);
|
|
2712
2527
|
}
|
|
2528
|
+
return Object.values(node).every((child) => collectRereadConditions(child, names, depth + 1));
|
|
2713
2529
|
}
|
|
2714
|
-
function
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
return
|
|
2530
|
+
function holdsRereadTrigger(node, depth = 0) {
|
|
2531
|
+
if (depth > MAX_REREAD_DEPTH) return false;
|
|
2532
|
+
if (Array.isArray(node)) return node.some((element) => holdsRereadTrigger(element, depth + 1));
|
|
2533
|
+
if (!isPlainObject(node)) return false;
|
|
2534
|
+
return Object.entries(node).some(([key, child]) => REREAD_TRIGGERS.has(key) || holdsRereadTrigger(child, depth + 1));
|
|
2719
2535
|
}
|
|
2720
|
-
function
|
|
2721
|
-
if (
|
|
2722
|
-
|
|
2536
|
+
function rendersReadTo(spelling, parentSecrets, value) {
|
|
2537
|
+
if (typeof spelling === "string" && typeof value === "string") {
|
|
2538
|
+
if (literalTextHoldsSubFloorSecret(spelling, parentSecrets)) return false;
|
|
2539
|
+
if (spelling === value) return redactForState(spelling, {
|
|
2540
|
+
provenance: "value-scan",
|
|
2541
|
+
secrets: parentSecrets
|
|
2542
|
+
}) === spelling;
|
|
2543
|
+
return rendersLiteralTo(spelling, parentSecrets, value);
|
|
2544
|
+
}
|
|
2545
|
+
if (Array.isArray(spelling) && Array.isArray(value) && spelling.length === value.length) return spelling.every((element, i) => rendersReadTo(element, parentSecrets, value[i]));
|
|
2723
2546
|
return false;
|
|
2724
2547
|
}
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2548
|
+
const REREAD_UNBOUND = Symbol("cdkd.reread.unbound");
|
|
2549
|
+
const REREAD_PARAMETER_FREE = Symbol("cdkd.reread.parameter-free");
|
|
2550
|
+
function diffSideReading(bind, parentSecrets) {
|
|
2551
|
+
return {
|
|
2552
|
+
bind: (name) => {
|
|
2553
|
+
const bound = bind(name);
|
|
2554
|
+
return bound && { value: persistedInheritedParameterValue(parentSecrets, name, bound.value) };
|
|
2555
|
+
},
|
|
2556
|
+
split: (text, delimiter) => splitOutsideDynamicReferences(text, delimiter, (token) => standsForInheritedSecret(parentSecrets, token))
|
|
2557
|
+
};
|
|
2558
|
+
}
|
|
2559
|
+
function rereadUnder(source, bind, parentSecrets, choose) {
|
|
2560
|
+
const pseudo = pseudoBindingOf(parentSecrets);
|
|
2561
|
+
const resolved = evaluatePureRead(source, bind, pseudo, plainSplit, choose);
|
|
2562
|
+
if (resolved === void 0) return void 0;
|
|
2563
|
+
const diffSide = diffSideReading(bind, parentSecrets);
|
|
2564
|
+
const redacted = evaluatePureRead(source, diffSide.bind, pseudo, diffSide.split, choose);
|
|
2565
|
+
if (redacted === void 0) return void 0;
|
|
2566
|
+
if (resolved.value === REREAD_NO_VALUE || redacted.value === REREAD_NO_VALUE) return resolved.value === redacted.value ? REREAD_NO_VALUE : void 0;
|
|
2567
|
+
if (!rendersReadTo(redacted.value, parentSecrets, resolved.value)) return void 0;
|
|
2568
|
+
return {
|
|
2569
|
+
resolved: resolved.value,
|
|
2570
|
+
redacted: redacted.value
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
function namesParameterOnBranches(node, choose, isParameter, depth = 0) {
|
|
2574
|
+
if (depth > MAX_REREAD_DEPTH) return true;
|
|
2575
|
+
if (typeof node === "string") return mentionsDynamicReference(node);
|
|
2576
|
+
if (Array.isArray(node)) return node.some((element) => namesParameterOnBranches(element, choose, isParameter, depth + 1));
|
|
2577
|
+
if (!isPlainObject(node)) return false;
|
|
2578
|
+
if (Object.hasOwn(node, "Fn::If")) {
|
|
2579
|
+
const args = node["Fn::If"];
|
|
2580
|
+
if (Object.keys(node).length !== 1) return true;
|
|
2581
|
+
if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return true;
|
|
2582
|
+
const tookTrue = choose(args[0], node);
|
|
2583
|
+
if (tookTrue === void 0) return true;
|
|
2584
|
+
return namesParameterOnBranches(tookTrue ? args[1] : args[2], choose, isParameter, depth + 1);
|
|
2733
2585
|
}
|
|
2734
|
-
if (
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2586
|
+
if (typeof node["Ref"] === "string" && isParameter(node["Ref"])) return true;
|
|
2587
|
+
const sub = node["Fn::Sub"];
|
|
2588
|
+
const text = typeof sub === "string" ? sub : Array.isArray(sub) ? sub[0] : void 0;
|
|
2589
|
+
if (typeof text === "string") {
|
|
2590
|
+
for (const match of text.matchAll(/\$\{([^}!][^}]*)\}/g)) if (isParameter(match[1].trim()) || isParameter(match[1])) return true;
|
|
2591
|
+
}
|
|
2592
|
+
return Object.values(node).some((child) => namesParameterOnBranches(child, choose, isParameter, depth + 1));
|
|
2593
|
+
}
|
|
2594
|
+
function rereadAssignments(source, bind, parentSecrets, untakenWhenUnbound = () => false, parameterFree) {
|
|
2595
|
+
if (!holdsRereadTrigger(source)) return void 0;
|
|
2596
|
+
const conditions = /* @__PURE__ */ new Set();
|
|
2597
|
+
if (!collectRereadConditions(source, conditions)) return void 0;
|
|
2598
|
+
if (conditions.size > MAX_REREAD_CONDITIONS) return void 0;
|
|
2599
|
+
const names = [...conditions];
|
|
2600
|
+
const out = [];
|
|
2601
|
+
for (let assignment = 0; assignment < 2 ** names.length; assignment++) {
|
|
2602
|
+
const choose = (condition) => Math.floor(assignment / 2 ** names.indexOf(condition)) % 2 === 1;
|
|
2603
|
+
let unbound = false;
|
|
2604
|
+
const tracked = (name) => {
|
|
2605
|
+
const bound = bind(name);
|
|
2606
|
+
if (bound === void 0 && untakenWhenUnbound(name)) unbound = true;
|
|
2607
|
+
return bound;
|
|
2608
|
+
};
|
|
2609
|
+
const reread = rereadUnder(source, tracked, parentSecrets, choose);
|
|
2610
|
+
if (unbound) out.push(REREAD_UNBOUND);
|
|
2611
|
+
else if (reread !== void 0) out.push(reread);
|
|
2612
|
+
else if (parameterFree !== void 0 && !namesParameterOnBranches(source, choose, parameterFree)) out.push(REREAD_PARAMETER_FREE);
|
|
2613
|
+
else out.push(void 0);
|
|
2739
2614
|
}
|
|
2740
2615
|
return out;
|
|
2741
2616
|
}
|
|
2742
|
-
function
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2617
|
+
function rereadParameterExpression(source, bind, parentSecrets) {
|
|
2618
|
+
const assignments = rereadAssignments(source, bind, parentSecrets, void 0, (name) => bind(name) !== void 0);
|
|
2619
|
+
if (assignments === void 0 || assignments.includes(void 0) || assignments.includes(REREAD_UNBOUND)) return;
|
|
2620
|
+
return assignments.find((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE);
|
|
2621
|
+
}
|
|
2622
|
+
function ambiguousRereads(rereads) {
|
|
2623
|
+
return rereads.some((a, i) => rereads.slice(i + 1).some((b) => deepEqualJsonValue(a.resolved, b.resolved) && !deepEqualJsonValue(a.redacted, b.redacted)));
|
|
2624
|
+
}
|
|
2625
|
+
function positionByParameterReread(bag, source, secrets) {
|
|
2626
|
+
const reads = inheritedParameterReads.get(secrets);
|
|
2627
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
2628
|
+
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
2629
|
+
if (!holdsRereadTrigger(source)) return void 0;
|
|
2630
|
+
const bind = (name) => reads.values.has(name) ? { value: reads.values.get(name) } : void 0;
|
|
2631
|
+
let unrecorded = false;
|
|
2632
|
+
const recorded = rereadUnder(source, bind, reads.parent, (_, node) => {
|
|
2633
|
+
const taken = takenIfBranchOf(secrets, node);
|
|
2634
|
+
if (taken === void 0) unrecorded = true;
|
|
2635
|
+
return taken;
|
|
2636
|
+
});
|
|
2637
|
+
let answer;
|
|
2638
|
+
if (!unrecorded) {
|
|
2639
|
+
if (recorded === void 0 || recorded === REREAD_NO_VALUE || !deepEqualJsonValue(recorded.resolved, bag) && !deepEqualJsonValue(recorded.redacted, bag)) return;
|
|
2640
|
+
answer = recorded.redacted;
|
|
2641
|
+
} else {
|
|
2642
|
+
const declared = reads.declared;
|
|
2643
|
+
const assignments = rereadAssignments(source, bind, reads.parent, (name) => declared?.has(name) === true);
|
|
2644
|
+
if (assignments === void 0 || assignments.includes(void 0)) return void 0;
|
|
2645
|
+
const matching = assignments.filter((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE && deepEqualJsonValue(entry.resolved, bag));
|
|
2646
|
+
if (matching.length === 0 || ambiguousRereads(matching)) return void 0;
|
|
2647
|
+
answer = matching[0].redacted;
|
|
2749
2648
|
}
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2649
|
+
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
2650
|
+
if (!deepEqualJsonValue(redactForState(answer, {
|
|
2651
|
+
provenance: "value-scan",
|
|
2652
|
+
secrets
|
|
2653
|
+
}), answer)) return void 0;
|
|
2654
|
+
return answer;
|
|
2754
2655
|
}
|
|
2755
2656
|
|
|
2756
|
-
// src/deployment/secret-redaction/
|
|
2757
|
-
function
|
|
2758
|
-
const
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2657
|
+
// src/deployment/secret-redaction/placeholder-positions.ts
|
|
2658
|
+
function keyedPart(source) {
|
|
2659
|
+
const key = crossStackSourceKey(source);
|
|
2660
|
+
return key === void 0 ? UNKNOWN_PART : { key };
|
|
2661
|
+
}
|
|
2662
|
+
const MAX_PLACEHOLDER_DEPTH = 8;
|
|
2663
|
+
function pushPlaceholderPart(out, part, budget) {
|
|
2664
|
+
if (budget.remaining <= 0) {
|
|
2665
|
+
budget.exhausted = true;
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
budget.remaining -= 1;
|
|
2669
|
+
out.push(part);
|
|
2670
|
+
}
|
|
2671
|
+
function appendValuePlaceholderParts(value, out, budget, depth) {
|
|
2672
|
+
if (budget.exhausted) return;
|
|
2673
|
+
const literal = joinPartLiteralText(value);
|
|
2674
|
+
if (literal !== void 0) return pushPlaceholderPart(out, literal, budget);
|
|
2675
|
+
if (isPlainObject(value) && Object.keys(value).length === 1) {
|
|
2676
|
+
const ref = value["Ref"];
|
|
2677
|
+
if (typeof ref === "string" && ref !== "") return pushPlaceholderPart(out, keyedPart({ Ref: ref }), budget);
|
|
2678
|
+
if (depth >= MAX_PLACEHOLDER_DEPTH) {
|
|
2679
|
+
budget.exhausted = true;
|
|
2762
2680
|
return;
|
|
2763
2681
|
}
|
|
2764
|
-
if (
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
}
|
|
2769
|
-
Object.values(node).forEach(visit);
|
|
2770
|
-
};
|
|
2771
|
-
visit(source);
|
|
2772
|
-
return [...out];
|
|
2682
|
+
if (appendParameterPlaceholderParts(value, out, budget, depth + 1)) return;
|
|
2683
|
+
return pushPlaceholderPart(out, keyedPart(value), budget);
|
|
2684
|
+
}
|
|
2685
|
+
pushPlaceholderPart(out, UNKNOWN_PART, budget);
|
|
2773
2686
|
}
|
|
2774
|
-
function
|
|
2775
|
-
const
|
|
2776
|
-
if (
|
|
2777
|
-
const
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
return "***";
|
|
2787
|
-
}
|
|
2788
|
-
if (placed === void 0) continue;
|
|
2789
|
-
if (placed === TAINTED_WITHOUT_SPAN) continue;
|
|
2790
|
-
if (answer !== void 0 && answer !== placed) return "***";
|
|
2791
|
-
answer = placed;
|
|
2687
|
+
function appendParameterPlaceholderParts(source, out, budget, depth) {
|
|
2688
|
+
const keys = Object.keys(source);
|
|
2689
|
+
if (keys.length !== 1) return false;
|
|
2690
|
+
const key = keys[0];
|
|
2691
|
+
if (key === "Fn::Join") {
|
|
2692
|
+
const args = source[key];
|
|
2693
|
+
if (!Array.isArray(args) || args.length !== 2) return false;
|
|
2694
|
+
const [delimiter, parts] = args;
|
|
2695
|
+
if (typeof delimiter !== "string" || !Array.isArray(parts)) return false;
|
|
2696
|
+
for (let index = 0; index < parts.length && !budget.exhausted; index++) {
|
|
2697
|
+
if (index > 0) pushPlaceholderPart(out, delimiter, budget);
|
|
2698
|
+
appendValuePlaceholderParts(parts[index], out, budget, depth);
|
|
2792
2699
|
}
|
|
2793
|
-
return
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2700
|
+
return true;
|
|
2701
|
+
}
|
|
2702
|
+
if (key === "Fn::Sub") {
|
|
2703
|
+
const args = source[key];
|
|
2704
|
+
let template;
|
|
2705
|
+
let variables = {};
|
|
2706
|
+
if (typeof args === "string") template = args;
|
|
2707
|
+
else if (Array.isArray(args) && args.length === 2 && isPlainObject(args[1])) {
|
|
2708
|
+
template = args[0];
|
|
2709
|
+
variables = args[1];
|
|
2710
|
+
} else return false;
|
|
2711
|
+
if (typeof template !== "string") return false;
|
|
2712
|
+
let cursor = 0;
|
|
2713
|
+
for (const hit of template.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
2714
|
+
if (budget.exhausted) return true;
|
|
2715
|
+
pushPlaceholderPart(out, template.slice(cursor, hit.index), budget);
|
|
2716
|
+
cursor = hit.index + hit[0].length;
|
|
2717
|
+
const name = hit[2] ?? "";
|
|
2718
|
+
if (hit[1] === "!") pushPlaceholderPart(out, `\${${name}}`, budget);
|
|
2719
|
+
else if (name === "") pushPlaceholderPart(out, hit[0], budget);
|
|
2720
|
+
else if (Object.hasOwn(variables, name)) appendValuePlaceholderParts(variables[name], out, budget, depth);
|
|
2721
|
+
else if (name.includes(".")) pushPlaceholderPart(out, keyedPart({ "Fn::GetAtt": name }), budget);
|
|
2722
|
+
else pushPlaceholderPart(out, keyedPart({ Ref: name }), budget);
|
|
2802
2723
|
}
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
return (item) => typeof item === "string" && exposes(item) ? placeString(item) : maskExposed(scan(item));
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
// src/deployment/secret-redaction/redact-path/baseline-mask.ts
|
|
2809
|
-
function isUncertifiedBaselineMaskPosition(properties, path) {
|
|
2810
|
-
if (pathCrossesDottedKey(properties, path)) return false;
|
|
2811
|
-
const [head] = path.split(".");
|
|
2812
|
-
if (head !== void 0 && RENDERED_DEFINITION_KEYS.has(head)) return definitionSourceCarriesSecret(properties);
|
|
2813
|
-
let cursor = properties;
|
|
2814
|
-
for (const segment of path.split(".")) {
|
|
2815
|
-
if (typeof cursor === "string") break;
|
|
2816
|
-
if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor) || !Object.hasOwn(cursor, segment)) return false;
|
|
2817
|
-
cursor = cursor[segment];
|
|
2724
|
+
pushPlaceholderPart(out, template.slice(cursor), budget);
|
|
2725
|
+
return true;
|
|
2818
2726
|
}
|
|
2819
|
-
|
|
2820
|
-
return subtreeHasDynamicReference(cursor) && !holdsMaskLeaf(cursor);
|
|
2727
|
+
return false;
|
|
2821
2728
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2729
|
+
function parameterPlaceholderParts(source, bag) {
|
|
2730
|
+
const budget = {
|
|
2731
|
+
remaining: bag.length * 2 + 16,
|
|
2732
|
+
exhausted: false
|
|
2733
|
+
};
|
|
2734
|
+
const out = [];
|
|
2735
|
+
if (!appendParameterPlaceholderParts(source, out, budget, 0)) return void 0;
|
|
2736
|
+
return budget.exhausted ? void 0 : out;
|
|
2737
|
+
}
|
|
2738
|
+
function positionByParameterPlaceholders(bag, source, secrets) {
|
|
2739
|
+
const associations = crossStackAssociations.get(secrets);
|
|
2740
|
+
const spanned = positionByRecordedParameterSpans(bag, source, secrets, associations);
|
|
2741
|
+
if (spanned !== void 0) return spanned;
|
|
2742
|
+
const parts = parameterPlaceholderParts(source, bag);
|
|
2743
|
+
if (parts === void 0) return void 0;
|
|
2744
|
+
const before = ["", ""];
|
|
2745
|
+
const after = ["", ""];
|
|
2746
|
+
let side = before;
|
|
2747
|
+
let unknown = false;
|
|
2748
|
+
let certified = 0;
|
|
2749
|
+
const spans = [];
|
|
2750
|
+
for (const part of parts) {
|
|
2751
|
+
let rendered;
|
|
2752
|
+
let persisted;
|
|
2753
|
+
if (typeof part === "string") {
|
|
2754
|
+
rendered = part;
|
|
2755
|
+
persisted = part;
|
|
2756
|
+
} else {
|
|
2757
|
+
let expression;
|
|
2758
|
+
let plaintext = "";
|
|
2759
|
+
if (part !== UNKNOWN_PART) {
|
|
2760
|
+
const association = associations?.get(part.key);
|
|
2761
|
+
if (association !== void 0 && typeof association !== "symbol") {
|
|
2762
|
+
plaintext = association.plaintext;
|
|
2763
|
+
expression = certifiedExpressionForLeaf(secrets, association, plaintext);
|
|
2764
|
+
}
|
|
2765
|
+
if (expression === void 0) {
|
|
2766
|
+
const inherited = inheritedRenderedSpan(secrets, part.key);
|
|
2767
|
+
if (inherited !== void 0) {
|
|
2768
|
+
plaintext = inherited.value;
|
|
2769
|
+
expression = inherited.spelling;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2833
2772
|
}
|
|
2834
|
-
|
|
2773
|
+
const pseudo = expression === void 0 && part !== UNKNOWN_PART ? inheritedPseudoSpan(secrets, part.key) : void 0;
|
|
2774
|
+
if (pseudo !== void 0) {
|
|
2775
|
+
side[0] += pseudo;
|
|
2776
|
+
side[1] += pseudo;
|
|
2777
|
+
continue;
|
|
2778
|
+
}
|
|
2779
|
+
if (expression === void 0) {
|
|
2780
|
+
if (unknown) return void 0;
|
|
2781
|
+
unknown = true;
|
|
2782
|
+
side = after;
|
|
2783
|
+
continue;
|
|
2784
|
+
}
|
|
2785
|
+
rendered = plaintext;
|
|
2786
|
+
persisted = expression;
|
|
2787
|
+
certified += 1;
|
|
2788
|
+
spans.push([
|
|
2789
|
+
side,
|
|
2790
|
+
side[0].length,
|
|
2791
|
+
plaintext.length
|
|
2792
|
+
]);
|
|
2835
2793
|
}
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
if (isSourcePlainLiteral(bag, source, rules)) return bag;
|
|
2839
|
-
const rerendered = rerenderedSourceLiteral(bag, source, secrets, rules);
|
|
2840
|
-
if (rerendered !== void 0) return rerendered;
|
|
2841
|
-
if ((typeof bag === "string" || Array.isArray(bag)) && isPlainObject(source)) {
|
|
2842
|
-
if (attributionRefusedReadsOf(source, secrets) === "masked") return "***";
|
|
2843
|
-
const inherited = positionByInheritedParameter(bag, source, secrets);
|
|
2844
|
-
if (inherited !== void 0) return inherited;
|
|
2845
|
-
const reread = positionByParameterReread(bag, source, secrets);
|
|
2846
|
-
if (reread !== void 0) return reread;
|
|
2794
|
+
side[0] += rendered;
|
|
2795
|
+
side[1] += persisted;
|
|
2847
2796
|
}
|
|
2848
|
-
if (
|
|
2849
|
-
|
|
2797
|
+
if (certified === 0) return void 0;
|
|
2798
|
+
let persisted;
|
|
2799
|
+
if (!unknown) {
|
|
2800
|
+
if (before[0] !== bag) return void 0;
|
|
2801
|
+
persisted = before[1];
|
|
2802
|
+
} else {
|
|
2803
|
+
if (bag.length < before[0].length + after[0].length) return void 0;
|
|
2804
|
+
if (!bag.startsWith(before[0]) || !bag.endsWith(after[0])) return void 0;
|
|
2805
|
+
const middle = bag.slice(before[0].length, bag.length - after[0].length);
|
|
2806
|
+
if (redactForState(middle, {
|
|
2850
2807
|
provenance: "value-scan",
|
|
2851
2808
|
secrets
|
|
2852
|
-
});
|
|
2853
|
-
|
|
2854
|
-
try {
|
|
2855
|
-
substituted = positionBySubstitutionSpans(bag, source, secrets, rules, valueScan);
|
|
2856
|
-
} catch {
|
|
2857
|
-
return "***";
|
|
2858
|
-
}
|
|
2859
|
-
const tainted = substituted === TAINTED_WITHOUT_SPAN;
|
|
2860
|
-
if (!tainted && substituted !== void 0) return substituted;
|
|
2861
|
-
try {
|
|
2862
|
-
const answered = positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, tainted ? void 0 : () => positionByLiteralRendering(bag, source, secrets, rules, valueScan));
|
|
2863
|
-
if (answered !== void 0) return answered;
|
|
2864
|
-
} catch (error) {
|
|
2865
|
-
if (tainted) return "***";
|
|
2866
|
-
throw error;
|
|
2867
|
-
}
|
|
2868
|
-
if (tainted) return "***";
|
|
2869
|
-
if (attributionRefusedReadsOf(source, secrets) !== void 0) return "***";
|
|
2870
|
-
}
|
|
2871
|
-
if (Array.isArray(bag) && isPlainObject(source) && listHoldsConsumedSecret(bag, source, secrets)) try {
|
|
2872
|
-
return positionListByCrossStackSource(bag, source, secrets) ?? "***";
|
|
2873
|
-
} catch {
|
|
2874
|
-
return "***";
|
|
2875
|
-
}
|
|
2876
|
-
if (Array.isArray(bag) && isPlainObject(source) && attributionRefusedReadsOf(source, secrets)) {
|
|
2877
|
-
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
2878
|
-
return positionedList !== void 0 ? positionedList : "***";
|
|
2879
|
-
}
|
|
2880
|
-
if (Array.isArray(bag) && isPlainObject(source)) {
|
|
2881
|
-
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
2882
|
-
if (positionedList !== void 0) return positionedList;
|
|
2883
|
-
}
|
|
2884
|
-
if (Array.isArray(bag) && Array.isArray(source)) {
|
|
2885
|
-
const key = identityKeyFor(bag, source);
|
|
2886
|
-
if (key !== void 0) {
|
|
2887
|
-
const sourceIndexById = /* @__PURE__ */ new Map();
|
|
2888
|
-
source.forEach((item, i) => {
|
|
2889
|
-
sourceIndexById.set(item[key], i);
|
|
2890
|
-
});
|
|
2891
|
-
let orderPreserved = true;
|
|
2892
|
-
const partnerIndex = bag.map((item, i) => {
|
|
2893
|
-
const j = sourceIndexById.get(item[key]);
|
|
2894
|
-
if (j === void 0) return -1;
|
|
2895
|
-
if (j !== i) orderPreserved = false;
|
|
2896
|
-
return j;
|
|
2897
|
-
});
|
|
2898
|
-
const positionalIsExact = rules.descendArrays && bag.length === source.length && orderPreserved;
|
|
2899
|
-
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
2900
|
-
return bag.map((item, i) => {
|
|
2901
|
-
const j = partnerIndex[i];
|
|
2902
|
-
if (j >= 0) return redactByPath(item, source[j], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
2903
|
-
if (positionalIsExact) return redactByPath(item, source[i], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
2904
|
-
return unpaired !== void 0 ? unpaired(item) : redactForState(item, {
|
|
2905
|
-
provenance: "value-scan",
|
|
2906
|
-
secrets
|
|
2907
|
-
});
|
|
2908
|
-
});
|
|
2909
|
-
}
|
|
2910
|
-
if (rules.descendArrays && bag.length === source.length) return bag.map((item, i) => redactByPath(item, source[i], secrets, rules, secretExpressions, bagIsSameGeneration));
|
|
2911
|
-
if (rules.descendArrays && bag.length < source.length) {
|
|
2912
|
-
const kept = sourceElementsKeptFor(source, bag.length, secrets);
|
|
2913
|
-
if (kept !== void 0 && keptLiteralsCorroborate(kept, bag, secrets)) return bag.map((item, i) => redactByPath(item, kept[i], secrets, rules, secretExpressions, bagIsSameGeneration));
|
|
2914
|
-
}
|
|
2915
|
-
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
2916
|
-
if (unpaired !== void 0) return bag.map(unpaired);
|
|
2809
|
+
}) !== middle) return void 0;
|
|
2810
|
+
persisted = before[1] + middle + after[1];
|
|
2917
2811
|
}
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2812
|
+
const afterStart = bag.length - after[0].length;
|
|
2813
|
+
return acceptedPlaceholderRendering(bag, persisted, spans.map(([side, offset, length]) => [(side === before ? 0 : afterStart) + offset, length]), secrets);
|
|
2814
|
+
}
|
|
2815
|
+
function acceptedPlaceholderRendering(bag, persisted, spans, secrets) {
|
|
2816
|
+
for (const plaintext of secrets.keys()) {
|
|
2817
|
+
if (plaintext.length < 4) continue;
|
|
2818
|
+
for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
|
|
2819
|
+
const end = at + plaintext.length;
|
|
2820
|
+
for (const [start, length] of spans) if (at < start + length && end > start && (at < start || end > start + length)) return void 0;
|
|
2926
2821
|
}
|
|
2927
|
-
return out;
|
|
2928
2822
|
}
|
|
2929
|
-
|
|
2823
|
+
if (redactForState(persisted, {
|
|
2930
2824
|
provenance: "value-scan",
|
|
2931
2825
|
secrets
|
|
2932
|
-
});
|
|
2933
|
-
|
|
2934
|
-
function positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, render) {
|
|
2935
|
-
const rendered = render?.();
|
|
2936
|
-
if (rendered !== void 0) return rendered;
|
|
2937
|
-
const certified = positionByCrossStackSource(bag, source, secrets);
|
|
2938
|
-
if (certified !== void 0) return certified;
|
|
2939
|
-
const placeheld = positionByParameterPlaceholders(bag, source, secrets);
|
|
2940
|
-
if (placeheld !== void 0) return placeheld;
|
|
2941
|
-
const positioned = positionByIntrinsicSkeleton(bag, source, secrets, secretExpressions);
|
|
2942
|
-
if (positioned !== void 0) return positioned;
|
|
2943
|
-
return positionByIntrinsicFrame(bag, source, secrets, secretExpressions, bagIsSameGeneration);
|
|
2826
|
+
}) !== persisted) return void 0;
|
|
2827
|
+
return persisted;
|
|
2944
2828
|
}
|
|
2945
|
-
function
|
|
2946
|
-
const
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2829
|
+
function positionByRecordedParameterSpans(bag, source, secrets, associations) {
|
|
2830
|
+
const resolution = intrinsicLeafResolutionOf(secrets, source);
|
|
2831
|
+
if (resolution === void 0 || resolution.output !== bag) return void 0;
|
|
2832
|
+
const recorded = resolution.parameterSpans;
|
|
2833
|
+
if (recorded === void 0) return void 0;
|
|
2834
|
+
let previousEnd = 0;
|
|
2835
|
+
let cursor = 0;
|
|
2836
|
+
let persisted = "";
|
|
2837
|
+
const gaps = [];
|
|
2838
|
+
const certified = [];
|
|
2839
|
+
for (const { start, length, key } of recorded) {
|
|
2840
|
+
if (!(start >= previousEnd && length > 0 && start + length <= bag.length)) return void 0;
|
|
2841
|
+
previousEnd = start + length;
|
|
2842
|
+
const text = bag.slice(start, start + length);
|
|
2843
|
+
const association = associations?.get(key);
|
|
2844
|
+
const expression = (association !== void 0 && typeof association !== "symbol" ? certifiedExpressionForLeaf(secrets, association, text) : void 0) ?? inheritedRenderedSpan(secrets, key, text)?.spelling;
|
|
2845
|
+
if (expression === void 0) continue;
|
|
2846
|
+
const gap = bag.slice(cursor, start);
|
|
2847
|
+
gaps.push(gap);
|
|
2848
|
+
persisted += gap + expression;
|
|
2849
|
+
certified.push([start, length]);
|
|
2850
|
+
cursor = start + length;
|
|
2950
2851
|
}
|
|
2951
|
-
if (
|
|
2952
|
-
const
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
return (value) => redactForState(value, {
|
|
2852
|
+
if (certified.length === 0) return void 0;
|
|
2853
|
+
const tail = bag.slice(cursor);
|
|
2854
|
+
gaps.push(tail);
|
|
2855
|
+
persisted += tail;
|
|
2856
|
+
for (const gap of gaps) if (redactForState(gap, {
|
|
2957
2857
|
provenance: "value-scan",
|
|
2958
2858
|
secrets
|
|
2959
|
-
});
|
|
2859
|
+
}) !== gap) return void 0;
|
|
2860
|
+
return acceptedPlaceholderRendering(bag, persisted, certified, secrets);
|
|
2960
2861
|
}
|
|
2961
2862
|
|
|
2962
|
-
// src/deployment/secret-redaction/
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
const
|
|
2967
|
-
const
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
addScalarSpelling(scalarKeep, value);
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
const bodies = [];
|
|
2977
|
-
for (const key of ["DefinitionString", "Definition"]) {
|
|
2978
|
-
if (!Object.hasOwn(source, key)) continue;
|
|
2979
|
-
const body = source[key];
|
|
2980
|
-
if (typeof body === "string") bodies.push(body);
|
|
2981
|
-
else if (isPlainObject(body)) bodies.push(JSON.stringify(body));
|
|
2982
|
-
}
|
|
2983
|
-
for (const body of bodies) {
|
|
2984
|
-
let rendered = body;
|
|
2985
|
-
for (const [name, value] of scalars) rendered = rendered.split(`\${${name}}`).join(value);
|
|
2986
|
-
for (const text of rendered === body ? [body] : [body, rendered]) {
|
|
2987
|
-
keep.add(text);
|
|
2988
|
-
try {
|
|
2989
|
-
const parsed = JSON.parse(text);
|
|
2990
|
-
for (const leaf of wholeStringLeavesOf(parsed)) keep.add(leaf);
|
|
2991
|
-
collectScalarLeaves(parsed, scalarKeep);
|
|
2992
|
-
collectObjectKeys(parsed, keyKeep);
|
|
2993
|
-
} catch {}
|
|
2994
|
-
}
|
|
2995
|
-
}
|
|
2996
|
-
const sentinel = sentinelDefinitionOf(source);
|
|
2997
|
-
if (sentinel !== void 0) {
|
|
2998
|
-
for (const leaf of sentinel.strings) keep.add(leaf);
|
|
2999
|
-
for (const leaf of sentinel.secretLeaves) if (leaf.asWritten !== void 0) keep.add(leaf.asWritten);
|
|
3000
|
-
for (const leaf of sentinel.scalars) scalarKeep.add(leaf);
|
|
3001
|
-
for (const key of sentinel.keys) keyKeep.add(key);
|
|
2863
|
+
// src/deployment/secret-redaction/identity-keys.ts
|
|
2864
|
+
const ARRAY_IDENTITY_KEYS = ["Name", "Key"];
|
|
2865
|
+
function isUniquelyKeyedBy(items, key) {
|
|
2866
|
+
if (items.length === 0) return false;
|
|
2867
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2868
|
+
for (const item of items) {
|
|
2869
|
+
if (!isPlainObject(item) || !Object.hasOwn(item, key)) return false;
|
|
2870
|
+
const id = item[key];
|
|
2871
|
+
if (typeof id !== "string" || id === "") return false;
|
|
2872
|
+
if (seen.has(id)) return false;
|
|
2873
|
+
seen.add(id);
|
|
3002
2874
|
}
|
|
3003
|
-
return
|
|
3004
|
-
strings: keep,
|
|
3005
|
-
scalars: scalarKeep,
|
|
3006
|
-
keys: keyKeep,
|
|
3007
|
-
sentinel
|
|
3008
|
-
};
|
|
2875
|
+
return true;
|
|
3009
2876
|
}
|
|
3010
|
-
function
|
|
3011
|
-
if (
|
|
3012
|
-
if (typeof value !== "string") return false;
|
|
3013
|
-
if (isSingleDynamicReferenceToken(value) && spanNamesResolvableService(value)) return true;
|
|
3014
|
-
return (value.includes("{{resolve:") || value.includes("***") || value.includes("${")) && rendered.has(value);
|
|
2877
|
+
function identityKeyFor(bag, source) {
|
|
2878
|
+
for (const key of ARRAY_IDENTITY_KEYS) if (isUniquelyKeyedBy(bag, key) && isUniquelyKeyedBy(source, key)) return key;
|
|
3015
2879
|
}
|
|
3016
|
-
function
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
}
|
|
3021
|
-
try {
|
|
3022
|
-
const parsed = JSON.parse(value);
|
|
3023
|
-
if (typeof parsed === "number" || typeof parsed === "boolean") into.add(parsed);
|
|
3024
|
-
} catch {}
|
|
2880
|
+
function positionListByCrossStackSource(bag, source, secrets) {
|
|
2881
|
+
const association = associationForSource(source, secrets);
|
|
2882
|
+
if (association === void 0) return void 0;
|
|
2883
|
+
return certifiedListForLeaf(secrets, association, bag);
|
|
3025
2884
|
}
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
2885
|
+
|
|
2886
|
+
// src/deployment/secret-redaction/redact-path/array-drop.ts
|
|
2887
|
+
const NEVER_DROPPING_INTRINSICS = /* @__PURE__ */ new Set([
|
|
2888
|
+
"Fn::Join",
|
|
2889
|
+
"Fn::Sub",
|
|
2890
|
+
"Fn::Select",
|
|
2891
|
+
"Fn::Split",
|
|
2892
|
+
"Fn::GetAtt"
|
|
2893
|
+
]);
|
|
2894
|
+
function arrayElementDrop(element, depth = 0) {
|
|
2895
|
+
if (depth > 16) return "unknown";
|
|
2896
|
+
if (!isPlainObject(element)) return "never";
|
|
2897
|
+
if (Object.hasOwn(element, "Ref")) return element["Ref"] === "AWS::NoValue" ? "always" : "never";
|
|
2898
|
+
const keys = Object.keys(element);
|
|
2899
|
+
if (keys.filter((key) => key.startsWith("Fn::") || key === "Condition").length === 0) return "never";
|
|
2900
|
+
if (keys.length !== 1) return "unknown";
|
|
2901
|
+
if (NEVER_DROPPING_INTRINSICS.has(keys[0])) return "never";
|
|
2902
|
+
if (keys[0] !== "Fn::If") return "unknown";
|
|
2903
|
+
const args = element["Fn::If"];
|
|
2904
|
+
if (!Array.isArray(args) || args.length !== 3) return "unknown";
|
|
2905
|
+
const branches = [arrayElementDrop(args[1], depth + 1), arrayElementDrop(args[2], depth + 1)];
|
|
2906
|
+
if (branches.includes("unknown")) return "unknown";
|
|
2907
|
+
if (branches.every((branch) => branch === "never")) return "never";
|
|
2908
|
+
if (branches.every((branch) => branch === "always")) return "always";
|
|
2909
|
+
return "maybe";
|
|
3033
2910
|
}
|
|
3034
|
-
function
|
|
3035
|
-
|
|
3036
|
-
if (
|
|
3037
|
-
if (
|
|
3038
|
-
|
|
3039
|
-
return mark ? POSITION_UNCERTIFIED : "***";
|
|
3040
|
-
}
|
|
3041
|
-
if (value === null || typeof value !== "object") return value;
|
|
3042
|
-
const memo = seen.get(value);
|
|
3043
|
-
if (memo !== void 0) return memo;
|
|
3044
|
-
if (Array.isArray(value)) {
|
|
3045
|
-
const out = [];
|
|
3046
|
-
seen.set(value, out);
|
|
3047
|
-
for (const item of value) out.push(refuseUncertifiedSubtree(item, sourceLiterals, mark, scalarLiterals, seen));
|
|
3048
|
-
return out;
|
|
3049
|
-
}
|
|
3050
|
-
if (isPlainObject(value) && hasPlainPrototype(value)) {
|
|
3051
|
-
const out = Object.create(null);
|
|
3052
|
-
seen.set(value, out);
|
|
3053
|
-
for (const [k, v] of Object.entries(value)) out[k] = refuseUncertifiedSubtree(v, sourceLiterals, mark, scalarLiterals, seen);
|
|
3054
|
-
return out;
|
|
2911
|
+
function sourceElementsKeptFor(source, bagLength, secrets) {
|
|
2912
|
+
const recorded = secrets && droppedArrayElementsOf(secrets, source);
|
|
2913
|
+
if (recorded !== void 0) {
|
|
2914
|
+
if (source.length - recorded.length !== bagLength) return void 0;
|
|
2915
|
+
return source.filter((_, i) => !recorded.includes(i));
|
|
3055
2916
|
}
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
2917
|
+
const drops = source.map((element) => arrayElementDrop(element));
|
|
2918
|
+
if (drops.includes("unknown")) return void 0;
|
|
2919
|
+
const always = drops.filter((drop) => drop === "always").length;
|
|
2920
|
+
const maybe = drops.filter((drop) => drop === "maybe").length;
|
|
2921
|
+
const dropped = source.length - bagLength;
|
|
2922
|
+
let dropMaybe;
|
|
2923
|
+
if (dropped === always) dropMaybe = false;
|
|
2924
|
+
else if (dropped === always + maybe) dropMaybe = true;
|
|
2925
|
+
else return void 0;
|
|
2926
|
+
return source.filter((_, i) => drops[i] === "never" || drops[i] === "maybe" && !dropMaybe);
|
|
3059
2927
|
}
|
|
3060
|
-
function
|
|
3061
|
-
|
|
3062
|
-
return refuseUncertifiedSubtree(bag, wholeStringLeavesOf(source), mark);
|
|
2928
|
+
function keptLiteralsCorroborate(kept, bag, secrets) {
|
|
2929
|
+
return kept.every((element, i) => keptElementCorroborates(element, bag[i], secrets));
|
|
3063
2930
|
}
|
|
3064
|
-
function
|
|
3065
|
-
|
|
2931
|
+
function isIntrinsicNode(value) {
|
|
2932
|
+
if (!isPlainObject(value)) return false;
|
|
2933
|
+
const keys = Object.keys(value);
|
|
2934
|
+
return keys.length === 1 && (keys[0] === "Ref" || keys[0].startsWith("Fn::"));
|
|
3066
2935
|
}
|
|
3067
|
-
function
|
|
3068
|
-
if (
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
}
|
|
3073
|
-
if (mixedLeafMayCarryPublicReference(source, secrets, bag)) return mark ? POSITION_DECIDED : bag;
|
|
3074
|
-
if (learn) learnMixedLeafNeedle(learn, bag, source);
|
|
3075
|
-
return mark ? POSITION_DECIDED : source;
|
|
3076
|
-
}
|
|
3077
|
-
if (failClosed === true && isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source) && Object.keys(bag).some((k) => RENDERED_DEFINITION_KEYS.has(k)) && definitionSourceCarriesSecret(source)) {
|
|
3078
|
-
const keep = renderedDefinitionLiterals(source);
|
|
3079
|
-
const out = Object.create(null);
|
|
3080
|
-
const rest = Object.create(null);
|
|
3081
|
-
for (const [k, v] of Object.entries(bag)) if (!RENDERED_DEFINITION_KEYS.has(k)) rest[k] = v;
|
|
3082
|
-
const walkedRest = refuseUncertifiedReadbackPositions(rest, source, secrets, failClosed, learn, mark);
|
|
3083
|
-
for (const [k, v] of Object.entries(bag)) {
|
|
3084
|
-
if (!RENDERED_DEFINITION_KEYS.has(k)) {
|
|
3085
|
-
out[k] = walkedRest[k];
|
|
3086
|
-
continue;
|
|
3087
|
-
}
|
|
3088
|
-
if (someKeyIsUnspelled(v, (key) => keep.keys.has(key))) {
|
|
3089
|
-
out[k] = mark ? POSITION_UNCERTIFIED : "***";
|
|
3090
|
-
continue;
|
|
3091
|
-
}
|
|
3092
|
-
let positioned = Object.hasOwn(source, k) ? refuseUncertifiedReadbackPositions(v, source[k], secrets, failClosed, learn, mark) : v;
|
|
3093
|
-
let misaligned = false;
|
|
3094
|
-
for (const leaf of keep.sentinel?.secretLeaves ?? []) {
|
|
3095
|
-
const at = alignedSecretLeaf(positioned, leaf);
|
|
3096
|
-
if (at === void 0) {
|
|
3097
|
-
misaligned = true;
|
|
3098
|
-
break;
|
|
3099
|
-
}
|
|
3100
|
-
if (!certifiedAtSecretPosition(at.value, keep.strings)) positioned = replaceAtPath(positioned, leaf.path, mark ? POSITION_UNCERTIFIED : "***");
|
|
3101
|
-
}
|
|
3102
|
-
if (misaligned) {
|
|
3103
|
-
out[k] = mark ? POSITION_UNCERTIFIED : "***";
|
|
3104
|
-
continue;
|
|
3105
|
-
}
|
|
3106
|
-
out[k] = refuseUncertifiedSubtree(positioned, keep.strings, mark, keep.scalars);
|
|
3107
|
-
}
|
|
3108
|
-
return out;
|
|
3109
|
-
}
|
|
3110
|
-
if (!subtreeHasDynamicReference(source)) return bag;
|
|
3111
|
-
if (isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source)) {
|
|
3112
|
-
const out = Object.create(null);
|
|
3113
|
-
for (const [k, v] of Object.entries(bag)) out[k] = Object.hasOwn(source, k) ? refuseUncertifiedReadbackPositions(v, source[k], secrets, failClosed, learn, mark) : v;
|
|
3114
|
-
return out;
|
|
3115
|
-
}
|
|
3116
|
-
if (Array.isArray(bag) && Array.isArray(source)) {
|
|
3117
|
-
const key = identityKeyFor(bag, source);
|
|
3118
|
-
if (key === void 0) {
|
|
3119
|
-
if (!unkeyedArrayPairsByAnchors(bag, source)) return refuseAgainstSource(bag, source, failClosed, mark);
|
|
3120
|
-
return bag.map((item, i) => refuseUncertifiedReadbackPositions(item, source[i], secrets, failClosed, learn, mark));
|
|
3121
|
-
}
|
|
3122
|
-
const sourceByIdentity = /* @__PURE__ */ new Map();
|
|
3123
|
-
for (const item of source) sourceByIdentity.set(item[key], item);
|
|
3124
|
-
const orphanLiterals = unpairedSourceCarriesReference(source, key, new Set(bag.map((item) => item[key]))) && failClosed === true ? wholeStringLeavesOf(source) : void 0;
|
|
3125
|
-
return bag.map((item) => {
|
|
3126
|
-
const partner = sourceByIdentity.get(item[key]);
|
|
3127
|
-
return partner === void 0 ? orphanLiterals !== void 0 ? refuseUncertifiedSubtree(item, orphanLiterals, mark) : item : refuseUncertifiedReadbackPositions(item, partner, secrets, failClosed, learn, mark);
|
|
3128
|
-
});
|
|
2936
|
+
function keptElementCorroborates(source, bag, secrets, depth = 0) {
|
|
2937
|
+
if (depth > 16) return false;
|
|
2938
|
+
if (typeof source === "string") {
|
|
2939
|
+
if (!source.includes("{{resolve:")) return source === bag;
|
|
2940
|
+
return isSingleDynamicReferenceToken(source) && resolvedPlaintextOf(secrets, source) === bag;
|
|
3129
2941
|
}
|
|
3130
|
-
|
|
2942
|
+
if (source === null || typeof source !== "object") return source === bag;
|
|
2943
|
+
if (isIntrinsicNode(source)) return true;
|
|
2944
|
+
if (Array.isArray(source)) return Array.isArray(bag) && bag.length === source.length && source.every((element, i) => keptElementCorroborates(element, bag[i], secrets, depth + 1));
|
|
2945
|
+
if (!isPlainObject(source) || !isPlainObject(bag)) return false;
|
|
2946
|
+
if (Object.keys(bag).some((key) => !Object.hasOwn(source, key))) return false;
|
|
2947
|
+
return Object.entries(source).every(([key, value]) => Object.hasOwn(bag, key) ? keptElementCorroborates(value, bag[key], secrets, depth + 1) : arrayElementDrop(value) === "always" || arrayElementDrop(value) === "maybe");
|
|
2948
|
+
}
|
|
2949
|
+
function corroboratesWhateverResolves(source, depth = 0) {
|
|
2950
|
+
if (depth > 16) return false;
|
|
2951
|
+
if (typeof source === "string") return !source.includes("{{resolve:");
|
|
2952
|
+
if (source === null || typeof source !== "object") return true;
|
|
2953
|
+
if (isIntrinsicNode(source)) return true;
|
|
2954
|
+
if (Array.isArray(source)) return source.every((element) => arrayElementDrop(element) === "never" && corroboratesWhateverResolves(element, depth + 1));
|
|
2955
|
+
if (!isPlainObject(source)) return false;
|
|
2956
|
+
if (Object.keys(source).some((key) => key === "Ref" || key.startsWith("Fn::"))) return false;
|
|
2957
|
+
return Object.values(source).every((value) => arrayElementDrop(value) !== "unknown" && corroboratesWhateverResolves(value, depth + 1));
|
|
2958
|
+
}
|
|
2959
|
+
function arrayPairsWhateverDrops(source) {
|
|
2960
|
+
if (!source.some((element) => isPlainObject(element) && (Object.hasOwn(element, "Fn::If") || element["Ref"] === "AWS::NoValue" || Array.isArray(element["Fn::FindInMap"]) && element["Fn::FindInMap"].length > 3))) return true;
|
|
2961
|
+
return source.every((element) => corroboratesWhateverResolves(element));
|
|
3131
2962
|
}
|
|
3132
2963
|
|
|
3133
|
-
// src/deployment/secret-redaction/
|
|
3134
|
-
function
|
|
3135
|
-
|
|
3136
|
-
if (Array.isArray(value)) return value.some(isDistinguishingAnchor);
|
|
3137
|
-
if (isPlainObject(value)) return Object.values(value).some(isDistinguishingAnchor);
|
|
3138
|
-
return false;
|
|
2964
|
+
// src/deployment/secret-redaction/redact-path/subtree.ts
|
|
2965
|
+
function isReadbackProjectedFromState(rules) {
|
|
2966
|
+
return rules.trustAnyExpression && !rules.descendArrays && rules.sourceIsSameGeneration;
|
|
3139
2967
|
}
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
if (
|
|
3143
|
-
if (
|
|
3144
|
-
|
|
3145
|
-
return JSON.stringify(source) ?? "undefined";
|
|
2968
|
+
function subtreeHasDynamicReference(value) {
|
|
2969
|
+
if (isDynamicReferenceString(value)) return true;
|
|
2970
|
+
if (Array.isArray(value)) return value.some(subtreeHasDynamicReference);
|
|
2971
|
+
if (isPlainObject(value)) return Object.values(value).some(subtreeHasDynamicReference);
|
|
2972
|
+
return false;
|
|
3146
2973
|
}
|
|
3147
|
-
function
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
return
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
return Object.keys(source).every((k) => Object.hasOwn(bag, k) && anchorsCorroboratePairing(bag[k], source[k], anchors));
|
|
3157
|
-
}
|
|
3158
|
-
if (Array.isArray(source)) {
|
|
3159
|
-
if (!Array.isArray(bag) || bag.length !== source.length) return false;
|
|
3160
|
-
return source.every((item, i) => anchorsCorroboratePairing(bag[i], item, anchors));
|
|
2974
|
+
function pathCrossesDottedKey(bag, path) {
|
|
2975
|
+
const segments = path.split(".");
|
|
2976
|
+
let cursor = bag;
|
|
2977
|
+
for (let i = 0; i < segments.length; i++) {
|
|
2978
|
+
if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor)) return false;
|
|
2979
|
+
const rest = segments.slice(i).join(".");
|
|
2980
|
+
for (const key of Object.keys(cursor)) if (key.includes(".") && (rest === key || rest.startsWith(`${key}.`))) return true;
|
|
2981
|
+
if (!Object.hasOwn(cursor, segments[i])) return false;
|
|
2982
|
+
cursor = cursor[segments[i]];
|
|
3161
2983
|
}
|
|
3162
2984
|
return false;
|
|
3163
2985
|
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
for (const [i, item] of source.entries()) {
|
|
3175
|
-
if (!subtreeHasDynamicReference(item)) continue;
|
|
3176
|
-
const signature = anchorSignature(item);
|
|
3177
|
-
if (signatures.has(signature)) return false;
|
|
3178
|
-
signatures.add(signature);
|
|
3179
|
-
if (distinguishingPerElement[i] > 0) continue;
|
|
3180
|
-
if (!isDynamicReferenceString(item) || frameDistinguishing === 0) return false;
|
|
3181
|
-
}
|
|
3182
|
-
return true;
|
|
2986
|
+
|
|
2987
|
+
// src/deployment/secret-redaction/redact-path/definition.ts
|
|
2988
|
+
const DEFINITION_SOURCE_KEYS = [
|
|
2989
|
+
"DefinitionSubstitutions",
|
|
2990
|
+
"DefinitionString",
|
|
2991
|
+
"Definition"
|
|
2992
|
+
];
|
|
2993
|
+
const RENDERED_DEFINITION_KEYS = /* @__PURE__ */ new Set(["Definition", "DefinitionString"]);
|
|
2994
|
+
function definitionSourceCarriesSecret(source) {
|
|
2995
|
+
return DEFINITION_SOURCE_KEYS.some((k) => Object.hasOwn(source, k) && (subtreeHasDynamicReference(source[k]) || carriesSecretMask(source[k])));
|
|
3183
2996
|
}
|
|
3184
|
-
|
|
3185
|
-
const
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
2997
|
+
function nameScalarSecrets(value, secrets) {
|
|
2998
|
+
const byValue = /* @__PURE__ */ new Set();
|
|
2999
|
+
for (const plaintext of secrets.keys()) try {
|
|
3000
|
+
const parsed = JSON.parse(plaintext);
|
|
3001
|
+
if (typeof parsed === "number" && Number.isFinite(parsed) || typeof parsed === "boolean") byValue.add(parsed);
|
|
3002
|
+
} catch {}
|
|
3003
|
+
if (byValue.size === 0) return value;
|
|
3004
|
+
const walk = (node) => {
|
|
3005
|
+
if (typeof node === "number" || typeof node === "boolean") {
|
|
3006
|
+
if (typeof node === "number" && !Number.isFinite(node)) return node;
|
|
3007
|
+
return secrets.has(String(node)) || byValue.has(node) ? "***" : node;
|
|
3008
|
+
}
|
|
3009
|
+
if (Array.isArray(node)) return node.map(walk);
|
|
3010
|
+
if (isPlainObject(node) && hasPlainPrototype(node)) {
|
|
3011
|
+
const out = Object.create(null);
|
|
3012
|
+
for (const [k, v] of Object.entries(node)) out[k] = walk(v);
|
|
3013
|
+
return out;
|
|
3014
|
+
}
|
|
3015
|
+
return node;
|
|
3016
|
+
};
|
|
3017
|
+
return walk(value);
|
|
3198
3018
|
}
|
|
3199
|
-
const
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
"
|
|
3203
|
-
];
|
|
3204
|
-
function spanNamesResolvableService(token) {
|
|
3205
|
-
return SECRET_BEARING_REFERENCE_PREFIXES.some((prefix) => token.startsWith(prefix));
|
|
3019
|
+
const SENTINEL_IN_STRING = "";
|
|
3020
|
+
const SENTINEL_OUT_OF_STRING = "";
|
|
3021
|
+
function substitutionIsSecret(value) {
|
|
3022
|
+
return subtreeHasDynamicReference(value) || value.includes("***");
|
|
3206
3023
|
}
|
|
3207
|
-
function
|
|
3208
|
-
const
|
|
3209
|
-
const
|
|
3210
|
-
|
|
3211
|
-
if (
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
const
|
|
3217
|
-
if (
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3024
|
+
function sentinelDefinitionOf(source) {
|
|
3025
|
+
const subs = source["DefinitionSubstitutions"];
|
|
3026
|
+
const values = /* @__PURE__ */ new Map();
|
|
3027
|
+
if (isPlainObject(subs)) {
|
|
3028
|
+
for (const [name, value] of Object.entries(subs)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values.set(name, String(value));
|
|
3029
|
+
}
|
|
3030
|
+
for (const key of ["DefinitionString", "Definition"]) {
|
|
3031
|
+
if (!Object.hasOwn(source, key)) continue;
|
|
3032
|
+
const raw = source[key];
|
|
3033
|
+
const body = typeof raw === "string" ? raw : isPlainObject(raw) ? JSON.stringify(raw) : void 0;
|
|
3034
|
+
if (body === void 0) continue;
|
|
3035
|
+
if (body.includes(SENTINEL_IN_STRING) || body.includes(SENTINEL_OUT_OF_STRING) || /\\u[eE]00[01]/.test(body)) continue;
|
|
3036
|
+
const names = [];
|
|
3037
|
+
let text = "";
|
|
3038
|
+
let inString = false;
|
|
3039
|
+
let escaped = false;
|
|
3040
|
+
const feed = (c) => {
|
|
3041
|
+
text += c;
|
|
3042
|
+
if (inString) {
|
|
3043
|
+
if (escaped) escaped = false;
|
|
3044
|
+
else if (c === "\\") escaped = true;
|
|
3045
|
+
else if (c === "\"") inString = false;
|
|
3046
|
+
} else if (c === "\"") inString = true;
|
|
3047
|
+
};
|
|
3048
|
+
for (let i = 0; i < body.length; i++) {
|
|
3049
|
+
if (body.startsWith("${", i)) {
|
|
3050
|
+
const end = body.indexOf("}", i + 2);
|
|
3051
|
+
const name = end === -1 ? void 0 : body.slice(i + 2, end);
|
|
3052
|
+
const value = name === void 0 ? void 0 : values.get(name);
|
|
3053
|
+
if (name !== void 0 && value !== void 0) {
|
|
3054
|
+
if (substitutionIsSecret(value)) {
|
|
3055
|
+
const index = names.push(name) - 1;
|
|
3056
|
+
text += inString ? `${SENTINEL_IN_STRING}${index}${SENTINEL_IN_STRING}` : `"${SENTINEL_OUT_OF_STRING}${index}${SENTINEL_OUT_OF_STRING}"`;
|
|
3057
|
+
} else for (const c of value) feed(c);
|
|
3058
|
+
i = end;
|
|
3059
|
+
continue;
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
feed(body[i]);
|
|
3063
|
+
}
|
|
3064
|
+
let parsed;
|
|
3065
|
+
try {
|
|
3066
|
+
parsed = JSON.parse(text);
|
|
3067
|
+
} catch {
|
|
3068
|
+
continue;
|
|
3069
|
+
}
|
|
3070
|
+
const keys = /* @__PURE__ */ new Set();
|
|
3071
|
+
const strings = /* @__PURE__ */ new Set();
|
|
3072
|
+
const scalars = /* @__PURE__ */ new Set();
|
|
3073
|
+
const secretLeaves = [];
|
|
3074
|
+
const marked = (t) => t.includes(SENTINEL_IN_STRING) || t.includes(SENTINEL_OUT_OF_STRING);
|
|
3075
|
+
const outOfString = new RegExp(`^${SENTINEL_OUT_OF_STRING}(\\d+)${SENTINEL_OUT_OF_STRING}$`);
|
|
3076
|
+
const inStringMarkers = new RegExp(`${SENTINEL_IN_STRING}(\\d+)${SENTINEL_IN_STRING}`, "g");
|
|
3077
|
+
const written = (t) => t.replace(inStringMarkers, (_m, i) => `\${${names[Number(i)]}}`);
|
|
3078
|
+
const walk = (node, path, shapes) => {
|
|
3079
|
+
if (typeof node === "string") {
|
|
3080
|
+
const m = outOfString.exec(node);
|
|
3081
|
+
if (m !== null) secretLeaves.push({
|
|
3082
|
+
path,
|
|
3083
|
+
shapes,
|
|
3084
|
+
outOfStringName: names[Number(m[1])],
|
|
3085
|
+
asWritten: void 0
|
|
3086
|
+
});
|
|
3087
|
+
else if (marked(node)) secretLeaves.push({
|
|
3088
|
+
path,
|
|
3089
|
+
shapes,
|
|
3090
|
+
outOfStringName: void 0,
|
|
3091
|
+
asWritten: written(node)
|
|
3092
|
+
});
|
|
3093
|
+
else strings.add(node);
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3096
|
+
if (typeof node === "number" || typeof node === "boolean") {
|
|
3097
|
+
scalars.add(node);
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
if (Array.isArray(node)) {
|
|
3101
|
+
node.forEach((item, i) => walk(item, [...path, i], [...shapes, node.length]));
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
if (isPlainObject(node)) {
|
|
3105
|
+
const own = new Set(Object.keys(node).map(written));
|
|
3106
|
+
for (const [k, v] of Object.entries(node)) {
|
|
3107
|
+
if (!marked(k)) keys.add(k);
|
|
3108
|
+
walk(v, [...path, written(k)], [...shapes, own]);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
walk(parsed, [], []);
|
|
3113
|
+
try {
|
|
3114
|
+
collectObjectKeys(JSON.parse(body), keys);
|
|
3115
|
+
} catch {}
|
|
3116
|
+
return {
|
|
3117
|
+
keys,
|
|
3118
|
+
strings,
|
|
3119
|
+
scalars,
|
|
3120
|
+
secretLeaves
|
|
3121
|
+
};
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
function alignedSecretLeaf(root, leaf) {
|
|
3125
|
+
let cursor = root;
|
|
3126
|
+
for (const [depth, segment] of leaf.path.entries()) {
|
|
3127
|
+
const shape = leaf.shapes[depth];
|
|
3128
|
+
if (typeof shape === "number") {
|
|
3129
|
+
if (!Array.isArray(cursor) || cursor.length !== shape) return void 0;
|
|
3130
|
+
cursor = cursor[segment];
|
|
3131
|
+
} else {
|
|
3132
|
+
if (!isPlainObject(cursor)) return void 0;
|
|
3133
|
+
const own = Object.keys(cursor);
|
|
3134
|
+
if (own.length !== shape.size || own.some((k) => !shape.has(k))) return void 0;
|
|
3135
|
+
if (!Object.hasOwn(cursor, segment)) return void 0;
|
|
3136
|
+
cursor = cursor[segment];
|
|
3137
|
+
}
|
|
3223
3138
|
}
|
|
3224
|
-
return
|
|
3225
|
-
}
|
|
3226
|
-
const SPELLED_SECRET_REFERENCE_PREFIXES = ["{{resolve:secretsmanager:", "{{resolve:ssm-secure:"];
|
|
3227
|
-
function expressionSecretIsInferred(expression) {
|
|
3228
|
-
return !SPELLED_SECRET_REFERENCE_PREFIXES.some((prefix) => expression.startsWith(prefix));
|
|
3229
|
-
}
|
|
3230
|
-
function expressionMaySeedANeedle(expression) {
|
|
3231
|
-
return isRecordedSecretExpression(expression) || SECRET_BEARING_REFERENCE_PREFIXES.some((prefix) => expression.startsWith(prefix));
|
|
3139
|
+
return { value: cursor };
|
|
3232
3140
|
}
|
|
3233
|
-
function
|
|
3234
|
-
if (
|
|
3235
|
-
if (
|
|
3236
|
-
|
|
3141
|
+
function collectObjectKeys(value, into) {
|
|
3142
|
+
if (Array.isArray(value)) for (const item of value) collectObjectKeys(item, into);
|
|
3143
|
+
else if (isPlainObject(value)) for (const [k, v] of Object.entries(value)) {
|
|
3144
|
+
into.add(k);
|
|
3145
|
+
collectObjectKeys(v, into);
|
|
3146
|
+
}
|
|
3237
3147
|
}
|
|
3238
|
-
function
|
|
3239
|
-
const
|
|
3240
|
-
|
|
3241
|
-
const
|
|
3242
|
-
|
|
3243
|
-
learnNeedle(collector, plaintext, token);
|
|
3148
|
+
function spelledKeysOf(properties) {
|
|
3149
|
+
const keys = /* @__PURE__ */ new Set();
|
|
3150
|
+
collectObjectKeys(properties, keys);
|
|
3151
|
+
for (const key of sentinelDefinitionOf(properties)?.keys ?? []) keys.add(key);
|
|
3152
|
+
return keys;
|
|
3244
3153
|
}
|
|
3245
|
-
function
|
|
3246
|
-
|
|
3154
|
+
function someKeyIsUnspelled(value, spelled) {
|
|
3155
|
+
if (Array.isArray(value)) return value.some((item) => someKeyIsUnspelled(item, spelled));
|
|
3156
|
+
if (isPlainObject(value)) return Object.entries(value).some(([k, v]) => !spelled(k) || someKeyIsUnspelled(v, spelled));
|
|
3157
|
+
return false;
|
|
3247
3158
|
}
|
|
3248
|
-
function
|
|
3249
|
-
|
|
3159
|
+
function nameDefinitionSecrets(value, source, secrets) {
|
|
3160
|
+
if (value === null || typeof value !== "object") return value;
|
|
3161
|
+
const sentinel = sentinelDefinitionOf(source);
|
|
3162
|
+
if (sentinel === void 0) {
|
|
3163
|
+
const plaintexts = [...secrets.keys()].filter((p) => p !== "");
|
|
3164
|
+
const keyHoldsSecret = (key) => plaintexts.some((p) => key === p || p.length >= 4 && key.includes(p));
|
|
3165
|
+
if (someKeyIsUnspelled(value, (key) => !keyHoldsSecret(key))) return "***";
|
|
3166
|
+
return nameScalarSecrets(value, secrets);
|
|
3167
|
+
}
|
|
3168
|
+
if (someKeyIsUnspelled(value, (key) => sentinel.keys.has(key))) return "***";
|
|
3169
|
+
let out = value;
|
|
3170
|
+
for (const leaf of sentinel.secretLeaves) {
|
|
3171
|
+
if (alignedSecretLeaf(out, leaf) === void 0) return "***";
|
|
3172
|
+
if (leaf.outOfStringName !== void 0) out = replaceAtPath(out, leaf.path, "***");
|
|
3173
|
+
}
|
|
3174
|
+
return out;
|
|
3250
3175
|
}
|
|
3251
|
-
function
|
|
3252
|
-
if (
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3176
|
+
function replaceAtPath(root, path, leaf) {
|
|
3177
|
+
if (path.length === 0) return leaf;
|
|
3178
|
+
const [head, ...rest] = path;
|
|
3179
|
+
if (Array.isArray(root)) {
|
|
3180
|
+
const copy = [...root];
|
|
3181
|
+
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
3182
|
+
return copy;
|
|
3256
3183
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
return scanDecision;
|
|
3184
|
+
const copy = Object.create(null);
|
|
3185
|
+
Object.assign(copy, root);
|
|
3186
|
+
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
3187
|
+
return copy;
|
|
3262
3188
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
const
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3189
|
+
|
|
3190
|
+
// src/deployment/secret-redaction/redact-path/unplaced-list-elements.ts
|
|
3191
|
+
function consumedPlaintextsUnder(source, secrets) {
|
|
3192
|
+
const out = /* @__PURE__ */ new Set();
|
|
3193
|
+
const visit = (node) => {
|
|
3194
|
+
if (Array.isArray(node)) {
|
|
3195
|
+
node.forEach(visit);
|
|
3196
|
+
return;
|
|
3197
|
+
}
|
|
3198
|
+
if (!isPlainObject(node)) return;
|
|
3199
|
+
for (const token of referencesConsumedBy(secrets, node)) {
|
|
3200
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
3201
|
+
if (plaintext !== void 0 && plaintext !== "") out.add(plaintext);
|
|
3202
|
+
}
|
|
3203
|
+
Object.values(node).forEach(visit);
|
|
3271
3204
|
};
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
return
|
|
3278
|
-
|
|
3279
|
-
|
|
3205
|
+
visit(source);
|
|
3206
|
+
return [...out];
|
|
3207
|
+
}
|
|
3208
|
+
function placeUnpairedListElements(source, secrets, rules, scan) {
|
|
3209
|
+
const plaintexts = consumedPlaintextsUnder(source, secrets);
|
|
3210
|
+
if (plaintexts.length === 0) return void 0;
|
|
3211
|
+
const copies = [...physicalNameCopiesOf.get(secrets) ?? []].filter((c) => c !== "");
|
|
3212
|
+
const exposes = (text) => plaintexts.some((plaintext) => exposedAt(text, plaintext, copies).length > 0);
|
|
3213
|
+
const placeString = (item) => {
|
|
3214
|
+
let answer;
|
|
3215
|
+
for (const candidate of source) {
|
|
3216
|
+
let placed;
|
|
3217
|
+
try {
|
|
3218
|
+
placed = positionBySubstitutionSpans(item, candidate, secrets, rules, scan);
|
|
3219
|
+
} catch {
|
|
3220
|
+
return "***";
|
|
3221
|
+
}
|
|
3222
|
+
if (placed === void 0) continue;
|
|
3223
|
+
if (placed === TAINTED_WITHOUT_SPAN) continue;
|
|
3224
|
+
if (answer !== void 0 && answer !== placed) return "***";
|
|
3225
|
+
answer = placed;
|
|
3226
|
+
}
|
|
3227
|
+
return answer ?? "***";
|
|
3228
|
+
};
|
|
3229
|
+
const maskExposed = (value) => {
|
|
3230
|
+
if (typeof value === "string") return exposes(value) ? "***" : value;
|
|
3231
|
+
if (Array.isArray(value)) return value.map(maskExposed);
|
|
3232
|
+
if (isPlainObject(value) && hasPlainPrototype(value)) {
|
|
3233
|
+
const out = Object.create(null);
|
|
3234
|
+
for (const [k, v] of Object.entries(value)) out[k] = maskExposed(v);
|
|
3235
|
+
return out;
|
|
3236
|
+
}
|
|
3237
|
+
return value;
|
|
3280
3238
|
};
|
|
3239
|
+
return (item) => typeof item === "string" && exposes(item) ? placeString(item) : maskExposed(scan(item));
|
|
3281
3240
|
}
|
|
3282
3241
|
|
|
3283
|
-
// src/deployment/secret-redaction/redact-
|
|
3284
|
-
function
|
|
3285
|
-
|
|
3286
|
-
const
|
|
3287
|
-
if (
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3242
|
+
// src/deployment/secret-redaction/redact-path/baseline-mask.ts
|
|
3243
|
+
function isUncertifiedBaselineMaskPosition(properties, path) {
|
|
3244
|
+
if (pathCrossesDottedKey(properties, path)) return false;
|
|
3245
|
+
const [head] = path.split(".");
|
|
3246
|
+
if (head !== void 0 && RENDERED_DEFINITION_KEYS.has(head)) return definitionSourceCarriesSecret(properties);
|
|
3247
|
+
let cursor = properties;
|
|
3248
|
+
for (const segment of path.split(".")) {
|
|
3249
|
+
if (typeof cursor === "string") break;
|
|
3250
|
+
if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor) || !Object.hasOwn(cursor, segment)) return false;
|
|
3251
|
+
cursor = cursor[segment];
|
|
3252
|
+
}
|
|
3253
|
+
if (typeof cursor === "string") return isDynamicReferenceString(cursor) && !isMaskLeaf(cursor);
|
|
3254
|
+
return subtreeHasDynamicReference(cursor) && !holdsMaskLeaf(cursor);
|
|
3255
|
+
}
|
|
3256
|
+
|
|
3257
|
+
// src/deployment/secret-redaction/redact-path.ts
|
|
3258
|
+
function redactByPath(bag, source, secrets, rules, secretExpressions, bagIsSameGeneration) {
|
|
3259
|
+
if (isDynamicReferenceString(source) && typeof bag === "string") {
|
|
3260
|
+
if (isSingleDynamicReferenceToken(source) && (rules.trustAnyExpression || isKnownSecretExpression(source, secretExpressions))) {
|
|
3261
|
+
if (!rules.sourceIsSameGeneration && isSingleDynamicReferenceToken(bag)) {
|
|
3262
|
+
if (!spanNamesResolvableService(bag)) return redactForState(bag, {
|
|
3263
|
+
provenance: "value-scan",
|
|
3264
|
+
secrets
|
|
3265
|
+
});
|
|
3266
|
+
return secrets.get(bag) ?? bag;
|
|
3267
|
+
}
|
|
3268
|
+
return source;
|
|
3269
|
+
}
|
|
3270
|
+
return positionByEmbeddedSpan(bag, source, secrets, bagIsSameGeneration);
|
|
3271
|
+
}
|
|
3272
|
+
if (isSourcePlainLiteral(bag, source, rules)) return bag;
|
|
3273
|
+
const rerendered = rerenderedSourceLiteral(bag, source, secrets, rules);
|
|
3274
|
+
if (rerendered !== void 0) return rerendered;
|
|
3275
|
+
if ((typeof bag === "string" || Array.isArray(bag)) && isPlainObject(source)) {
|
|
3276
|
+
if (attributionRefusedReadsOf(source, secrets) === "masked") return "***";
|
|
3277
|
+
const inherited = positionByInheritedParameter(bag, source, secrets);
|
|
3278
|
+
if (inherited !== void 0) return inherited;
|
|
3279
|
+
const reread = positionByParameterReread(bag, source, secrets);
|
|
3280
|
+
if (reread !== void 0) return reread;
|
|
3281
|
+
}
|
|
3282
|
+
if (typeof bag === "string" && isPlainObject(source)) {
|
|
3283
|
+
const valueScan = (text) => redactForState(text, {
|
|
3302
3284
|
provenance: "value-scan",
|
|
3303
3285
|
secrets
|
|
3304
3286
|
});
|
|
3287
|
+
let substituted;
|
|
3288
|
+
try {
|
|
3289
|
+
substituted = positionBySubstitutionSpans(bag, source, secrets, rules, valueScan);
|
|
3290
|
+
} catch {
|
|
3291
|
+
return "***";
|
|
3292
|
+
}
|
|
3293
|
+
const tainted = substituted === TAINTED_WITHOUT_SPAN;
|
|
3294
|
+
const subFloorRead = attributionRefusedReadsOf(source, secrets) !== void 0;
|
|
3295
|
+
const checked = (answer) => subFloorRead && keepsInheritedSubFloorText(answer, secrets) ? "***" : answer;
|
|
3296
|
+
if (substituted !== TAINTED_WITHOUT_SPAN && substituted !== void 0) return checked(substituted);
|
|
3297
|
+
try {
|
|
3298
|
+
const answered = positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, tainted ? void 0 : () => positionByLiteralRendering(bag, source, secrets, rules, valueScan));
|
|
3299
|
+
if (answered !== void 0) return checked(answered);
|
|
3300
|
+
} catch (error) {
|
|
3301
|
+
if (tainted) return "***";
|
|
3302
|
+
throw error;
|
|
3303
|
+
}
|
|
3304
|
+
if (tainted) return "***";
|
|
3305
|
+
if (subFloorRead) return scannedSubFloorRead(bag, source, secrets);
|
|
3305
3306
|
}
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
});
|
|
3311
|
-
if (record.observedProperties) next.observedProperties = redactAtProvenance(record.observedProperties, secrets, sourceProperties ?? next.properties, observedProvenance ?? (sourceProperties !== void 0 ? "template-sourced" : secrets.size === 0 && observedClaimed ? "state-baseline" : "state-readback"), observedClaimed);
|
|
3312
|
-
return next;
|
|
3313
|
-
}
|
|
3314
|
-
function withoutPhysicalNameCopies(secrets, run) {
|
|
3315
|
-
const names = physicalNameCopiesOf.get(secrets);
|
|
3316
|
-
if (names === void 0) return run();
|
|
3317
|
-
physicalNameCopiesOf.delete(secrets);
|
|
3318
|
-
try {
|
|
3319
|
-
return run();
|
|
3320
|
-
} finally {
|
|
3321
|
-
physicalNameCopiesOf.set(secrets, names);
|
|
3307
|
+
if (Array.isArray(bag) && isPlainObject(source) && listHoldsConsumedSecret(bag, source, secrets)) try {
|
|
3308
|
+
return positionListByCrossStackSource(bag, source, secrets) ?? "***";
|
|
3309
|
+
} catch {
|
|
3310
|
+
return "***";
|
|
3322
3311
|
}
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
const names = new Set(previous);
|
|
3327
|
-
for (const id of ids) if (id !== "") names.add(id);
|
|
3328
|
-
physicalNameCopiesOf.set(secrets, names);
|
|
3329
|
-
try {
|
|
3330
|
-
return run();
|
|
3331
|
-
} finally {
|
|
3332
|
-
if (previous === void 0) physicalNameCopiesOf.delete(secrets);
|
|
3333
|
-
else physicalNameCopiesOf.set(secrets, previous);
|
|
3312
|
+
if (Array.isArray(bag) && isPlainObject(source) && attributionRefusedReadsOf(source, secrets)) {
|
|
3313
|
+
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
3314
|
+
return positionedList !== void 0 ? positionedList : "***";
|
|
3334
3315
|
}
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
if (Array.isArray(stored)) {
|
|
3339
|
-
if (!Array.isArray(legacy) || !Array.isArray(current)) return stored;
|
|
3340
|
-
if (legacy.length !== stored.length || current.length !== stored.length) return stored;
|
|
3341
|
-
let changed = false;
|
|
3342
|
-
const out = stored.map((item, i) => {
|
|
3343
|
-
const next = repairPhysicalNameCopyLeaves(item, legacy[i], current[i]);
|
|
3344
|
-
if (next !== item) changed = true;
|
|
3345
|
-
return next;
|
|
3346
|
-
});
|
|
3347
|
-
return changed ? out : stored;
|
|
3316
|
+
if (Array.isArray(bag) && isPlainObject(source)) {
|
|
3317
|
+
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
3318
|
+
if (positionedList !== void 0) return positionedList;
|
|
3348
3319
|
}
|
|
3349
|
-
if (
|
|
3350
|
-
|
|
3351
|
-
if (
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
const
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3320
|
+
if (Array.isArray(bag) && Array.isArray(source)) {
|
|
3321
|
+
const key = identityKeyFor(bag, source);
|
|
3322
|
+
if (key !== void 0) {
|
|
3323
|
+
const sourceIndexById = /* @__PURE__ */ new Map();
|
|
3324
|
+
source.forEach((item, i) => {
|
|
3325
|
+
sourceIndexById.set(item[key], i);
|
|
3326
|
+
});
|
|
3327
|
+
let orderPreserved = true;
|
|
3328
|
+
const partnerIndex = bag.map((item, i) => {
|
|
3329
|
+
const j = sourceIndexById.get(item[key]);
|
|
3330
|
+
if (j === void 0) return -1;
|
|
3331
|
+
if (j !== i) orderPreserved = false;
|
|
3332
|
+
return j;
|
|
3333
|
+
});
|
|
3334
|
+
const positionalIsExact = rules.descendArrays && bag.length === source.length && orderPreserved;
|
|
3335
|
+
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
3336
|
+
return bag.map((item, i) => {
|
|
3337
|
+
const j = partnerIndex[i];
|
|
3338
|
+
if (j >= 0) return redactByPath(item, source[j], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
3339
|
+
if (positionalIsExact) return redactByPath(item, source[i], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
3340
|
+
return unpaired !== void 0 ? unpaired(item) : redactForState(item, {
|
|
3341
|
+
provenance: "value-scan",
|
|
3342
|
+
secrets
|
|
3343
|
+
});
|
|
3344
|
+
});
|
|
3362
3345
|
}
|
|
3363
|
-
return
|
|
3346
|
+
if (rules.descendArrays && bag.length === source.length) return bag.map((item, i) => redactByPath(item, source[i], secrets, rules, secretExpressions, bagIsSameGeneration));
|
|
3347
|
+
if (rules.descendArrays && bag.length < source.length) {
|
|
3348
|
+
const kept = sourceElementsKeptFor(source, bag.length, secrets);
|
|
3349
|
+
if (kept !== void 0 && keptLiteralsCorroborate(kept, bag, secrets)) return bag.map((item, i) => redactByPath(item, kept[i], secrets, rules, secretExpressions, bagIsSameGeneration));
|
|
3350
|
+
}
|
|
3351
|
+
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
3352
|
+
if (unpaired !== void 0) return bag.map(unpaired);
|
|
3364
3353
|
}
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
if (names === void 0) return [];
|
|
3370
|
-
const pairs = [];
|
|
3371
|
-
withoutPhysicalNameCopies(legacySecrets, () => {
|
|
3372
|
-
for (const name of names) {
|
|
3373
|
-
const legacy = redactForState(name, {
|
|
3354
|
+
if (isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source)) {
|
|
3355
|
+
const out = Object.create(null);
|
|
3356
|
+
for (const [k, v] of Object.entries(bag)) {
|
|
3357
|
+
out[k] = Object.hasOwn(source, k) ? redactByPath(v, source[k], secrets, rules, secretExpressions, bagIsSameGeneration) : redactForState(v, {
|
|
3374
3358
|
provenance: "value-scan",
|
|
3375
|
-
secrets
|
|
3359
|
+
secrets
|
|
3376
3360
|
});
|
|
3377
|
-
if (
|
|
3361
|
+
if (secrets.size > 0 && RENDERED_DEFINITION_KEYS.has(k) && definitionSourceCarriesSecret(source)) out[k] = nameDefinitionSecrets(out[k], source, secrets);
|
|
3378
3362
|
}
|
|
3363
|
+
return out;
|
|
3364
|
+
}
|
|
3365
|
+
return redactForState(bag, {
|
|
3366
|
+
provenance: "value-scan",
|
|
3367
|
+
secrets
|
|
3379
3368
|
});
|
|
3380
|
-
return pairs;
|
|
3381
3369
|
}
|
|
3382
|
-
function
|
|
3383
|
-
|
|
3384
|
-
if (
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
const next = replaceEmbeddedPhysicalNameRewrites(item, pairs);
|
|
3393
|
-
if (next !== item) changed = true;
|
|
3394
|
-
return next;
|
|
3395
|
-
});
|
|
3396
|
-
return changed ? out : value;
|
|
3397
|
-
}
|
|
3398
|
-
if (value !== null && typeof value === "object") {
|
|
3399
|
-
let out;
|
|
3400
|
-
for (const [key, item] of Object.entries(value)) {
|
|
3401
|
-
const next = replaceEmbeddedPhysicalNameRewrites(item, pairs);
|
|
3402
|
-
if (next !== item) {
|
|
3403
|
-
out ??= { ...value };
|
|
3404
|
-
out[key] = next;
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
return out ?? value;
|
|
3408
|
-
}
|
|
3409
|
-
return value;
|
|
3370
|
+
function positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, render) {
|
|
3371
|
+
const rendered = render?.();
|
|
3372
|
+
if (rendered !== void 0) return rendered;
|
|
3373
|
+
const certified = positionByCrossStackSource(bag, source, secrets);
|
|
3374
|
+
if (certified !== void 0) return certified;
|
|
3375
|
+
const placeheld = positionByParameterPlaceholders(bag, source, secrets);
|
|
3376
|
+
if (placeheld !== void 0) return placeheld;
|
|
3377
|
+
const positioned = positionByIntrinsicSkeleton(bag, source, secrets, secretExpressions);
|
|
3378
|
+
if (positioned !== void 0) return positioned;
|
|
3379
|
+
return positionByIntrinsicFrame(bag, source, secrets, secretExpressions, bagIsSameGeneration);
|
|
3410
3380
|
}
|
|
3411
|
-
function
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
return repaired === target ? repaired : stored;
|
|
3417
|
-
}
|
|
3418
|
-
if (Array.isArray(stored)) {
|
|
3419
|
-
if (!Array.isArray(target) || target.length !== stored.length) return stored;
|
|
3420
|
-
let changed = false;
|
|
3421
|
-
const out = stored.map((item, i) => {
|
|
3422
|
-
const next = repairEmbeddedPhysicalNamesTowards(item, target[i], pairs);
|
|
3423
|
-
if (next !== item) changed = true;
|
|
3424
|
-
return next;
|
|
3425
|
-
});
|
|
3426
|
-
return changed ? out : stored;
|
|
3427
|
-
}
|
|
3428
|
-
if (stored !== null && typeof stored === "object") {
|
|
3429
|
-
if (target === null || typeof target !== "object" || Array.isArray(target)) return stored;
|
|
3430
|
-
const t = target;
|
|
3431
|
-
let out;
|
|
3432
|
-
for (const [key, value] of Object.entries(stored)) {
|
|
3433
|
-
if (!Object.hasOwn(t, key)) continue;
|
|
3434
|
-
const next = repairEmbeddedPhysicalNamesTowards(value, t[key], pairs);
|
|
3435
|
-
if (next !== value) {
|
|
3436
|
-
out ??= { ...stored };
|
|
3437
|
-
out[key] = next;
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
return out ?? stored;
|
|
3381
|
+
function listHoldsConsumedSecret(bag, source, secrets) {
|
|
3382
|
+
const plaintexts = [];
|
|
3383
|
+
for (const token of referencesConsumedBy(secrets, source)) {
|
|
3384
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
3385
|
+
if (plaintext !== void 0 && plaintext !== "") plaintexts.push(plaintext);
|
|
3441
3386
|
}
|
|
3442
|
-
return
|
|
3387
|
+
if (plaintexts.length === 0) return false;
|
|
3388
|
+
const holds = (value) => typeof value === "string" ? plaintexts.some((plaintext) => value.includes(plaintext)) : Array.isArray(value) ? value.some(holds) : value !== null && typeof value === "object" && Object.values(value).some(holds);
|
|
3389
|
+
return holds(bag);
|
|
3443
3390
|
}
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3391
|
+
function listValueScan(secrets) {
|
|
3392
|
+
return (value) => redactForState(value, {
|
|
3393
|
+
provenance: "value-scan",
|
|
3394
|
+
secrets
|
|
3395
|
+
});
|
|
3448
3396
|
}
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
const
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
}), refused, bag, marks, derived.inferred);
|
|
3463
|
-
}
|
|
3464
|
-
const regex = buildNeedleRegex(substringNeedlesOf(secrets));
|
|
3465
|
-
const wholeValueExpr = (s) => s === "" ? void 0 : secrets.get(s);
|
|
3466
|
-
const physicalNames = physicalNameCopiesOf.get(secrets);
|
|
3467
|
-
let vouched;
|
|
3468
|
-
const vouchedExpressions = () => vouched ??= new Set(secrets.values());
|
|
3469
|
-
const expressionFor = (match) => {
|
|
3470
|
-
return secrets.get(match) ?? "***";
|
|
3471
|
-
};
|
|
3472
|
-
const scanLeaf = (value, needles) => {
|
|
3473
|
-
const spans = isDynamicReferenceString(value) ? resolvableReferenceSpans(value, vouchedExpressions()) : [];
|
|
3474
|
-
const names = physicalNameSpans(physicalNames, value);
|
|
3475
|
-
const kept = (start, end) => isStrictlyInsideASpan(spans, start, end) || names.some((n) => n.start <= start && end <= n.end);
|
|
3476
|
-
if (!legacyOverlapScan.has(secrets)) {
|
|
3477
|
-
const matches = everyMatch(value, needles);
|
|
3478
|
-
const redacted = matches.filter((m) => !kept(m.start, m.end));
|
|
3479
|
-
if (cutsContainmentNeedle(value, secrets, redacted)) {
|
|
3480
|
-
overlapAnswered.add(secrets);
|
|
3481
|
-
return "***";
|
|
3482
|
-
}
|
|
3483
|
-
const overlapping = redactOverlappingMatches(value, matches, redacted, expressionFor);
|
|
3484
|
-
if (overlapping !== void 0) {
|
|
3485
|
-
overlapAnswered.add(secrets);
|
|
3486
|
-
return overlapping;
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
return value.replace(needles, (match, offset) => {
|
|
3490
|
-
if (kept(offset, offset + match.length)) return match;
|
|
3491
|
-
return expressionFor(match);
|
|
3492
|
-
});
|
|
3493
|
-
};
|
|
3494
|
-
const walk = (value) => {
|
|
3495
|
-
if (typeof value === "string") {
|
|
3496
|
-
if (physicalNames?.has(value) === true) return value;
|
|
3497
|
-
const whole = wholeValueExpr(value);
|
|
3498
|
-
if (whole !== void 0) return whole;
|
|
3499
|
-
if (isSingleDynamicReferenceToken(value) && spanNamesResolvableService(value)) return value;
|
|
3500
|
-
if (!regex) return value;
|
|
3501
|
-
regex.lastIndex = 0;
|
|
3502
|
-
if (!regex.test(value)) return value;
|
|
3503
|
-
return scanLeaf(value, regex);
|
|
3397
|
+
|
|
3398
|
+
// src/deployment/secret-redaction/readback-certification.ts
|
|
3399
|
+
function renderedDefinitionLiterals(source) {
|
|
3400
|
+
const keep = /* @__PURE__ */ new Set();
|
|
3401
|
+
const scalarKeep = /* @__PURE__ */ new Set();
|
|
3402
|
+
const keyKeep = /* @__PURE__ */ new Set();
|
|
3403
|
+
const subs = source["DefinitionSubstitutions"];
|
|
3404
|
+
const scalars = [];
|
|
3405
|
+
if (isPlainObject(subs)) {
|
|
3406
|
+
for (const [name, value] of Object.entries(subs)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
3407
|
+
scalars.push([name, String(value)]);
|
|
3408
|
+
if (typeof value === "string") keep.add(value);
|
|
3409
|
+
addScalarSpelling(scalarKeep, value);
|
|
3504
3410
|
}
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3411
|
+
}
|
|
3412
|
+
const bodies = [];
|
|
3413
|
+
for (const key of ["DefinitionString", "Definition"]) {
|
|
3414
|
+
if (!Object.hasOwn(source, key)) continue;
|
|
3415
|
+
const body = source[key];
|
|
3416
|
+
if (typeof body === "string") bodies.push(body);
|
|
3417
|
+
else if (isPlainObject(body)) bodies.push(JSON.stringify(body));
|
|
3418
|
+
}
|
|
3419
|
+
for (const body of bodies) {
|
|
3420
|
+
let rendered = body;
|
|
3421
|
+
for (const [name, value] of scalars) rendered = rendered.split(`\${${name}}`).join(value);
|
|
3422
|
+
for (const text of rendered === body ? [body] : [body, rendered]) {
|
|
3423
|
+
keep.add(text);
|
|
3424
|
+
try {
|
|
3425
|
+
const parsed = JSON.parse(text);
|
|
3426
|
+
for (const leaf of wholeStringLeavesOf(parsed)) keep.add(leaf);
|
|
3427
|
+
collectScalarLeaves(parsed, scalarKeep);
|
|
3428
|
+
collectObjectKeys(parsed, keyKeep);
|
|
3429
|
+
} catch {}
|
|
3516
3430
|
}
|
|
3517
|
-
|
|
3431
|
+
}
|
|
3432
|
+
const sentinel = sentinelDefinitionOf(source);
|
|
3433
|
+
if (sentinel !== void 0) {
|
|
3434
|
+
for (const leaf of sentinel.strings) keep.add(leaf);
|
|
3435
|
+
for (const leaf of sentinel.secretLeaves) if (leaf.asWritten !== void 0) keep.add(leaf.asWritten);
|
|
3436
|
+
for (const leaf of sentinel.scalars) scalarKeep.add(leaf);
|
|
3437
|
+
for (const key of sentinel.keys) keyKeep.add(key);
|
|
3438
|
+
}
|
|
3439
|
+
return {
|
|
3440
|
+
strings: keep,
|
|
3441
|
+
scalars: scalarKeep,
|
|
3442
|
+
keys: keyKeep,
|
|
3443
|
+
sentinel
|
|
3518
3444
|
};
|
|
3519
|
-
return walk(bag);
|
|
3520
3445
|
}
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3446
|
+
function certifiedAtSecretPosition(value, rendered) {
|
|
3447
|
+
if (typeof value === "symbol") return true;
|
|
3448
|
+
if (typeof value !== "string") return false;
|
|
3449
|
+
if (isSingleDynamicReferenceToken(value) && spanNamesResolvableService(value)) return true;
|
|
3450
|
+
return (value.includes("{{resolve:") || value.includes("***") || value.includes("${")) && rendered.has(value);
|
|
3525
3451
|
}
|
|
3526
|
-
function
|
|
3527
|
-
if (
|
|
3528
|
-
|
|
3452
|
+
function addScalarSpelling(into, value) {
|
|
3453
|
+
if (typeof value !== "string") {
|
|
3454
|
+
into.add(value);
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3529
3457
|
try {
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3458
|
+
const parsed = JSON.parse(value);
|
|
3459
|
+
if (typeof parsed === "number" || typeof parsed === "boolean") into.add(parsed);
|
|
3460
|
+
} catch {}
|
|
3461
|
+
}
|
|
3462
|
+
function collectScalarLeaves(value, into) {
|
|
3463
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
3464
|
+
into.add(value);
|
|
3465
|
+
return;
|
|
3533
3466
|
}
|
|
3467
|
+
if (Array.isArray(value)) for (const item of value) collectScalarLeaves(item, into);
|
|
3468
|
+
else if (isPlainObject(value)) for (const item of Object.values(value)) collectScalarLeaves(item, into);
|
|
3534
3469
|
}
|
|
3535
|
-
function
|
|
3536
|
-
if (typeof
|
|
3537
|
-
|
|
3538
|
-
return
|
|
3470
|
+
function refuseUncertifiedSubtree(value, sourceLiterals, mark, scalarLiterals, seen = /* @__PURE__ */ new Map()) {
|
|
3471
|
+
if (scalarLiterals !== void 0 && (typeof value === "number" || typeof value === "boolean") && !scalarLiterals.has(value)) return mark ? POSITION_UNCERTIFIED : "***";
|
|
3472
|
+
if (typeof value === "string") {
|
|
3473
|
+
if (isSingleDynamicReferenceToken(value) && spanNamesResolvableService(value) || sourceLiterals.has(value)) return value;
|
|
3474
|
+
if (value === "") return value;
|
|
3475
|
+
return mark ? POSITION_UNCERTIFIED : "***";
|
|
3539
3476
|
}
|
|
3540
|
-
if (
|
|
3541
|
-
|
|
3477
|
+
if (value === null || typeof value !== "object") return value;
|
|
3478
|
+
const memo = seen.get(value);
|
|
3479
|
+
if (memo !== void 0) return memo;
|
|
3480
|
+
if (Array.isArray(value)) {
|
|
3481
|
+
const out = [];
|
|
3482
|
+
seen.set(value, out);
|
|
3483
|
+
for (const item of value) out.push(refuseUncertifiedSubtree(item, sourceLiterals, mark, scalarLiterals, seen));
|
|
3542
3484
|
return out;
|
|
3543
3485
|
}
|
|
3544
|
-
if (
|
|
3545
|
-
const c = current;
|
|
3546
|
-
for (const [key, value] of Object.entries(legacy)) if (Object.hasOwn(c, key)) differingStringLeaves(value, c[key], out);
|
|
3547
|
-
}
|
|
3548
|
-
return out;
|
|
3549
|
-
}
|
|
3550
|
-
function legacyLeavesWithoutMask(legacy) {
|
|
3551
|
-
if (typeof legacy === "string") return legacy.includes("***") ? void 0 : legacy;
|
|
3552
|
-
if (Array.isArray(legacy)) return legacy.map(legacyLeavesWithoutMask);
|
|
3553
|
-
if (legacy !== null && typeof legacy === "object") {
|
|
3486
|
+
if (isPlainObject(value) && hasPlainPrototype(value)) {
|
|
3554
3487
|
const out = Object.create(null);
|
|
3555
|
-
|
|
3488
|
+
seen.set(value, out);
|
|
3489
|
+
for (const [k, v] of Object.entries(value)) out[k] = refuseUncertifiedSubtree(v, sourceLiterals, mark, scalarLiterals, seen);
|
|
3556
3490
|
return out;
|
|
3557
3491
|
}
|
|
3558
|
-
return
|
|
3492
|
+
if (ArrayBuffer.isView(value)) return mark ? POSITION_UNCERTIFIED : "***";
|
|
3493
|
+
seen.set(value, value);
|
|
3494
|
+
return value;
|
|
3559
3495
|
}
|
|
3560
|
-
function
|
|
3561
|
-
if (
|
|
3562
|
-
|
|
3563
|
-
if (legacy !== null && typeof legacy === "object") {
|
|
3564
|
-
const out = Object.create(null);
|
|
3565
|
-
for (const [key, value] of Object.entries(legacy)) out[key] = legacyReferenceLeavesOnly(value);
|
|
3566
|
-
return out;
|
|
3567
|
-
}
|
|
3568
|
-
return legacy;
|
|
3496
|
+
function refuseAgainstSource(bag, source, failClosed, mark) {
|
|
3497
|
+
if (failClosed !== true) return bag;
|
|
3498
|
+
return refuseUncertifiedSubtree(bag, wholeStringLeavesOf(source), mark);
|
|
3569
3499
|
}
|
|
3570
|
-
function
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
});
|
|
3583
|
-
return changed ? out : value;
|
|
3500
|
+
function unpairedSourceCarriesReference(source, key, bagIdentities) {
|
|
3501
|
+
return source.some((item) => !bagIdentities.has(item[key]) && subtreeHasDynamicReference(item));
|
|
3502
|
+
}
|
|
3503
|
+
function refuseUncertifiedReadbackPositions(bag, source, secrets, failClosed, learn, mark) {
|
|
3504
|
+
if (isDynamicReferenceString(source) && typeof bag === "string") {
|
|
3505
|
+
if (isSingleDynamicReferenceToken(source)) {
|
|
3506
|
+
if (learn) learnWholeTokenNeedle(learn, bag, source);
|
|
3507
|
+
return mark ? POSITION_DECIDED : source;
|
|
3508
|
+
}
|
|
3509
|
+
if (mixedLeafMayCarryPublicReference(source, secrets, bag)) return mark ? POSITION_DECIDED : bag;
|
|
3510
|
+
if (learn) learnMixedLeafNeedle(learn, bag, source);
|
|
3511
|
+
return mark ? POSITION_DECIDED : source;
|
|
3584
3512
|
}
|
|
3585
|
-
if (
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3513
|
+
if (failClosed === true && isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source) && Object.keys(bag).some((k) => RENDERED_DEFINITION_KEYS.has(k)) && definitionSourceCarriesSecret(source)) {
|
|
3514
|
+
const keep = renderedDefinitionLiterals(source);
|
|
3515
|
+
const out = Object.create(null);
|
|
3516
|
+
const rest = Object.create(null);
|
|
3517
|
+
for (const [k, v] of Object.entries(bag)) if (!RENDERED_DEFINITION_KEYS.has(k)) rest[k] = v;
|
|
3518
|
+
const walkedRest = refuseUncertifiedReadbackPositions(rest, source, secrets, failClosed, learn, mark);
|
|
3519
|
+
for (const [k, v] of Object.entries(bag)) {
|
|
3520
|
+
if (!RENDERED_DEFINITION_KEYS.has(k)) {
|
|
3521
|
+
out[k] = walkedRest[k];
|
|
3522
|
+
continue;
|
|
3523
|
+
}
|
|
3524
|
+
if (someKeyIsUnspelled(v, (key) => keep.keys.has(key))) {
|
|
3525
|
+
out[k] = mark ? POSITION_UNCERTIFIED : "***";
|
|
3526
|
+
continue;
|
|
3527
|
+
}
|
|
3528
|
+
let positioned = Object.hasOwn(source, k) ? refuseUncertifiedReadbackPositions(v, source[k], secrets, failClosed, learn, mark) : v;
|
|
3529
|
+
let misaligned = false;
|
|
3530
|
+
for (const leaf of keep.sentinel?.secretLeaves ?? []) {
|
|
3531
|
+
const at = alignedSecretLeaf(positioned, leaf);
|
|
3532
|
+
if (at === void 0) {
|
|
3533
|
+
misaligned = true;
|
|
3534
|
+
break;
|
|
3535
|
+
}
|
|
3536
|
+
if (!certifiedAtSecretPosition(at.value, keep.strings)) positioned = replaceAtPath(positioned, leaf.path, mark ? POSITION_UNCERTIFIED : "***");
|
|
3537
|
+
}
|
|
3538
|
+
if (misaligned) {
|
|
3539
|
+
out[k] = mark ? POSITION_UNCERTIFIED : "***";
|
|
3540
|
+
continue;
|
|
3592
3541
|
}
|
|
3542
|
+
out[k] = refuseUncertifiedSubtree(positioned, keep.strings, mark, keep.scalars);
|
|
3593
3543
|
}
|
|
3594
|
-
return out
|
|
3595
|
-
}
|
|
3596
|
-
return value;
|
|
3597
|
-
}
|
|
3598
|
-
function everyMatch(value, needles) {
|
|
3599
|
-
const matches = [];
|
|
3600
|
-
needles.lastIndex = 0;
|
|
3601
|
-
for (let m = needles.exec(value); m !== null; m = needles.exec(value)) {
|
|
3602
|
-
matches.push({
|
|
3603
|
-
start: m.index,
|
|
3604
|
-
end: m.index + m[0].length
|
|
3605
|
-
});
|
|
3606
|
-
needles.lastIndex = m.index + 1;
|
|
3544
|
+
return out;
|
|
3607
3545
|
}
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
let overlap = false;
|
|
3614
|
-
for (const m of matches) {
|
|
3615
|
-
if (m.start < reach) overlap = true;
|
|
3616
|
-
reach = Math.max(reach, m.end);
|
|
3546
|
+
if (!subtreeHasDynamicReference(source)) return bag;
|
|
3547
|
+
if (isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source)) {
|
|
3548
|
+
const out = Object.create(null);
|
|
3549
|
+
for (const [k, v] of Object.entries(bag)) out[k] = Object.hasOwn(source, k) ? refuseUncertifiedReadbackPositions(v, source[k], secrets, failClosed, learn, mark) : v;
|
|
3550
|
+
return out;
|
|
3617
3551
|
}
|
|
3618
|
-
if (
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
let j = i + 1;
|
|
3624
|
-
for (; j < redacted.length && redacted[j].start < end; j++) end = Math.max(end, redacted[j].end);
|
|
3625
|
-
const cluster = redacted.slice(i, j);
|
|
3626
|
-
out += value.slice(cursor, cluster[0].start);
|
|
3627
|
-
for (let at = cluster[0].start; at < end;) {
|
|
3628
|
-
const tile = cluster.find((m) => m.start === at);
|
|
3629
|
-
if (tile === void 0) return "***";
|
|
3630
|
-
out += expressionFor(value.slice(tile.start, tile.end));
|
|
3631
|
-
at = tile.end;
|
|
3552
|
+
if (Array.isArray(bag) && Array.isArray(source)) {
|
|
3553
|
+
const key = identityKeyFor(bag, source);
|
|
3554
|
+
if (key === void 0) {
|
|
3555
|
+
if (!unkeyedArrayPairsByAnchors(bag, source)) return refuseAgainstSource(bag, source, failClosed, mark);
|
|
3556
|
+
return bag.map((item, i) => refuseUncertifiedReadbackPositions(item, source[i], secrets, failClosed, learn, mark));
|
|
3632
3557
|
}
|
|
3633
|
-
|
|
3634
|
-
|
|
3558
|
+
const sourceByIdentity = /* @__PURE__ */ new Map();
|
|
3559
|
+
for (const item of source) sourceByIdentity.set(item[key], item);
|
|
3560
|
+
const orphanLiterals = unpairedSourceCarriesReference(source, key, new Set(bag.map((item) => item[key]))) && failClosed === true ? wholeStringLeavesOf(source) : void 0;
|
|
3561
|
+
return bag.map((item) => {
|
|
3562
|
+
const partner = sourceByIdentity.get(item[key]);
|
|
3563
|
+
return partner === void 0 ? orphanLiterals !== void 0 ? refuseUncertifiedSubtree(item, orphanLiterals, mark) : item : refuseUncertifiedReadbackPositions(item, partner, secrets, failClosed, learn, mark);
|
|
3564
|
+
});
|
|
3635
3565
|
}
|
|
3636
|
-
return
|
|
3566
|
+
return refuseAgainstSource(bag, source, failClosed, mark);
|
|
3637
3567
|
}
|
|
3638
3568
|
|
|
3639
|
-
// src/deployment/secret-redaction/
|
|
3640
|
-
function
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
if (
|
|
3644
|
-
|
|
3645
|
-
return maskMatchSpans(text, printingNeedles(noLogOnly ? secrets.keys() : [...secrets.keys(), ...logOnly]), "***");
|
|
3569
|
+
// src/deployment/secret-redaction/anchors.ts
|
|
3570
|
+
function isDistinguishingAnchor(value) {
|
|
3571
|
+
if (typeof value === "string") return value !== "";
|
|
3572
|
+
if (Array.isArray(value)) return value.some(isDistinguishingAnchor);
|
|
3573
|
+
if (isPlainObject(value)) return Object.values(value).some(isDistinguishingAnchor);
|
|
3574
|
+
return false;
|
|
3646
3575
|
}
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
if (
|
|
3650
|
-
|
|
3576
|
+
const ANCHOR_REFERENCE_MASK = "<ref>";
|
|
3577
|
+
function anchorSignature(source) {
|
|
3578
|
+
if (isDynamicReferenceString(source)) return ANCHOR_REFERENCE_MASK;
|
|
3579
|
+
if (Array.isArray(source)) return `[${source.map(anchorSignature).sort().join(",")}]`;
|
|
3580
|
+
if (isPlainObject(source)) return `{${Object.keys(source).sort().map((k) => `${JSON.stringify(k)}:${anchorSignature(source[k])}`).join(",")}}`;
|
|
3581
|
+
return JSON.stringify(source) ?? "undefined";
|
|
3651
3582
|
}
|
|
3652
|
-
function
|
|
3653
|
-
|
|
3583
|
+
function anchorsCorroboratePairing(bag, source, anchors) {
|
|
3584
|
+
if (!subtreeHasDynamicReference(source)) {
|
|
3585
|
+
if (!deepEqualJsonValue(bag, source)) return false;
|
|
3586
|
+
if (isDistinguishingAnchor(source)) anchors.distinguishing += 1;
|
|
3587
|
+
return true;
|
|
3588
|
+
}
|
|
3589
|
+
if (isDynamicReferenceString(source)) return typeof bag === "string";
|
|
3590
|
+
if (isPlainObject(source)) {
|
|
3591
|
+
if (!isPlainObject(bag)) return false;
|
|
3592
|
+
return Object.keys(source).every((k) => Object.hasOwn(bag, k) && anchorsCorroboratePairing(bag[k], source[k], anchors));
|
|
3593
|
+
}
|
|
3594
|
+
if (Array.isArray(source)) {
|
|
3595
|
+
if (!Array.isArray(bag) || bag.length !== source.length) return false;
|
|
3596
|
+
return source.every((item, i) => anchorsCorroboratePairing(bag[i], item, anchors));
|
|
3597
|
+
}
|
|
3598
|
+
return false;
|
|
3654
3599
|
}
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
const
|
|
3658
|
-
const
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
chain.push(current);
|
|
3663
|
-
current = current.cause;
|
|
3600
|
+
function unkeyedArrayPairsByAnchors(bag, source) {
|
|
3601
|
+
if (bag.length !== source.length) return false;
|
|
3602
|
+
const distinguishingPerElement = [];
|
|
3603
|
+
for (const [i, item] of source.entries()) {
|
|
3604
|
+
const anchors = { distinguishing: 0 };
|
|
3605
|
+
if (!anchorsCorroboratePairing(bag[i], item, anchors)) return false;
|
|
3606
|
+
distinguishingPerElement.push(anchors.distinguishing);
|
|
3664
3607
|
}
|
|
3665
|
-
|
|
3608
|
+
const frameDistinguishing = source.reduce((total, item, i) => subtreeHasDynamicReference(item) ? total : total + distinguishingPerElement[i], 0);
|
|
3609
|
+
const signatures = /* @__PURE__ */ new Set();
|
|
3610
|
+
for (const [i, item] of source.entries()) {
|
|
3611
|
+
if (!subtreeHasDynamicReference(item)) continue;
|
|
3612
|
+
const signature = anchorSignature(item);
|
|
3613
|
+
if (signatures.has(signature)) return false;
|
|
3614
|
+
signatures.add(signature);
|
|
3615
|
+
if (distinguishingPerElement[i] > 0) continue;
|
|
3616
|
+
if (!isDynamicReferenceString(item) || frameDistinguishing === 0) return false;
|
|
3617
|
+
}
|
|
3618
|
+
return true;
|
|
3666
3619
|
}
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3620
|
+
const POSITION_DECIDED = Symbol("position decided by a position pass");
|
|
3621
|
+
const POSITION_UNCERTIFIED = Symbol("position refused by a position pass");
|
|
3622
|
+
function learnNeedle(collector, plaintext, expression) {
|
|
3623
|
+
if (plaintext.length < 4) return;
|
|
3624
|
+
if (collector.poisoned.has(plaintext)) return;
|
|
3625
|
+
if (expressionSecretIsInferred(expression)) collector.inferred.add(plaintext);
|
|
3626
|
+
const already = collector.needles.get(plaintext);
|
|
3627
|
+
if (already === void 0) {
|
|
3628
|
+
collector.needles.set(plaintext, expression);
|
|
3672
3629
|
return;
|
|
3673
3630
|
}
|
|
3631
|
+
if (already === expression) return;
|
|
3632
|
+
collector.needles.delete(plaintext);
|
|
3633
|
+
collector.poisoned.add(plaintext);
|
|
3674
3634
|
}
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3635
|
+
const SECRET_BEARING_REFERENCE_PREFIXES = [
|
|
3636
|
+
"{{resolve:secretsmanager:",
|
|
3637
|
+
"{{resolve:ssm-secure:",
|
|
3638
|
+
"{{resolve:ssm:"
|
|
3639
|
+
];
|
|
3640
|
+
function spanNamesResolvableService(token) {
|
|
3641
|
+
return SECRET_BEARING_REFERENCE_PREFIXES.some((prefix) => token.startsWith(prefix));
|
|
3682
3642
|
}
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3643
|
+
function resolvableReferenceSpans(value, vouchedExpressions) {
|
|
3644
|
+
const spans = dynamicReferenceSpans(value).filter((span) => spanNamesResolvableService(value.slice(span.start, span.end)));
|
|
3645
|
+
const starts = new Set(spans.map((span) => span.start));
|
|
3646
|
+
for (const prefix of SECRET_BEARING_REFERENCE_PREFIXES) for (let at = value.indexOf(prefix); at >= 0; at = value.indexOf(prefix, at + 1)) {
|
|
3647
|
+
if (starts.has(at)) continue;
|
|
3648
|
+
DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = at;
|
|
3649
|
+
const match = DYNAMIC_REFERENCE_TOKEN_SCAN.exec(value);
|
|
3650
|
+
DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = 0;
|
|
3651
|
+
if (match?.index !== at) continue;
|
|
3652
|
+
const end = at + match[0].length;
|
|
3653
|
+
if (!vouchedExpressions.has(value.slice(at, end))) continue;
|
|
3654
|
+
spans.push({
|
|
3655
|
+
start: at,
|
|
3656
|
+
end
|
|
3657
|
+
});
|
|
3658
|
+
starts.add(at);
|
|
3659
|
+
}
|
|
3660
|
+
return spans;
|
|
3693
3661
|
}
|
|
3694
|
-
const
|
|
3695
|
-
function
|
|
3696
|
-
return
|
|
3662
|
+
const SPELLED_SECRET_REFERENCE_PREFIXES = ["{{resolve:secretsmanager:", "{{resolve:ssm-secure:"];
|
|
3663
|
+
function expressionSecretIsInferred(expression) {
|
|
3664
|
+
return !SPELLED_SECRET_REFERENCE_PREFIXES.some((prefix) => expression.startsWith(prefix));
|
|
3697
3665
|
}
|
|
3698
|
-
function
|
|
3699
|
-
|
|
3700
|
-
return Array.isArray(value) ? proto === Array.prototype : proto === Object.prototype || proto === null;
|
|
3666
|
+
function expressionMaySeedANeedle(expression) {
|
|
3667
|
+
return isRecordedSecretExpression(expression) || SECRET_BEARING_REFERENCE_PREFIXES.some((prefix) => expression.startsWith(prefix));
|
|
3701
3668
|
}
|
|
3702
|
-
function
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
for (const key of Reflect.ownKeys(node)) {
|
|
3707
|
-
const descriptor = Object.getOwnPropertyDescriptor(node, key);
|
|
3708
|
-
if (descriptor) entries.push([key, descriptor]);
|
|
3709
|
-
}
|
|
3710
|
-
const isArray = Array.isArray(node);
|
|
3711
|
-
return {
|
|
3712
|
-
proto: Object.getPrototypeOf(node),
|
|
3713
|
-
isArray,
|
|
3714
|
-
length: isArray ? Object.getOwnPropertyDescriptor(node, "length") : void 0,
|
|
3715
|
-
extensible: Object.isExtensible(node),
|
|
3716
|
-
entries
|
|
3717
|
-
};
|
|
3718
|
-
} catch {
|
|
3719
|
-
return;
|
|
3720
|
-
}
|
|
3669
|
+
function learnWholeTokenNeedle(collector, bag, source) {
|
|
3670
|
+
if (isSingleDynamicReferenceToken(bag)) return;
|
|
3671
|
+
if (!expressionMaySeedANeedle(source)) return;
|
|
3672
|
+
learnNeedle(collector, bag, source);
|
|
3721
3673
|
}
|
|
3722
|
-
function
|
|
3723
|
-
|
|
3724
|
-
if (
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
let changed = false;
|
|
3729
|
-
let frontier = [value];
|
|
3730
|
-
for (let depth = 0; frontier.length > 0 && depth < 20; depth++) {
|
|
3731
|
-
const next = [];
|
|
3732
|
-
for (const node of frontier) {
|
|
3733
|
-
if (seen.has(node)) continue;
|
|
3734
|
-
seen.add(node);
|
|
3735
|
-
const read = readFieldNode(node);
|
|
3736
|
-
if (!read) continue;
|
|
3737
|
-
nodes.set(node, read);
|
|
3738
|
-
for (const [, descriptor] of read.entries) {
|
|
3739
|
-
if (!("value" in descriptor)) continue;
|
|
3740
|
-
const child = descriptor.value;
|
|
3741
|
-
if (typeof child === "string") {
|
|
3742
|
-
if (!changed && maskText(child) !== child) changed = true;
|
|
3743
|
-
} else if (typeof child === "object" && child !== null) next.push(child);
|
|
3744
|
-
}
|
|
3745
|
-
}
|
|
3746
|
-
frontier = next;
|
|
3747
|
-
}
|
|
3748
|
-
if (!changed) return value;
|
|
3749
|
-
const copies = /* @__PURE__ */ new Map();
|
|
3750
|
-
for (const [node, read] of nodes) copies.set(node, read.isArray ? new Array(read.length?.value ?? 0) : Object.create(read.proto));
|
|
3751
|
-
for (const [node, read] of nodes) {
|
|
3752
|
-
const copy = copies.get(node);
|
|
3753
|
-
for (const [key, original] of read.entries) {
|
|
3754
|
-
if (key === "length" && read.isArray) continue;
|
|
3755
|
-
const descriptor = { ...original };
|
|
3756
|
-
if ("value" in descriptor) {
|
|
3757
|
-
const child = descriptor.value;
|
|
3758
|
-
if (typeof child === "string") descriptor.value = maskText(child);
|
|
3759
|
-
else if (typeof child === "object" && child !== null && copies.has(child)) descriptor.value = copies.get(child);
|
|
3760
|
-
}
|
|
3761
|
-
Object.defineProperty(copy, key, descriptor);
|
|
3762
|
-
}
|
|
3763
|
-
if (read.length?.writable === false) Object.defineProperty(copy, "length", { writable: false });
|
|
3764
|
-
if (!read.extensible) Object.preventExtensions(copy);
|
|
3765
|
-
}
|
|
3766
|
-
return copies.get(value) ?? value;
|
|
3767
|
-
} catch {
|
|
3768
|
-
return value;
|
|
3769
|
-
}
|
|
3674
|
+
function learnMixedLeafNeedle(collector, bag, source) {
|
|
3675
|
+
const frame = singleSpanFrame(bag, source);
|
|
3676
|
+
if (frame === void 0) return;
|
|
3677
|
+
const { token, middle: plaintext } = frame;
|
|
3678
|
+
if (!expressionMaySeedANeedle(token)) return;
|
|
3679
|
+
learnNeedle(collector, plaintext, token);
|
|
3770
3680
|
}
|
|
3771
|
-
function
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
const
|
|
3780
|
-
const
|
|
3781
|
-
|
|
3782
|
-
if (key === "message" || key === "cause" || key === "stack") continue;
|
|
3783
|
-
const descriptor = Object.getOwnPropertyDescriptor(link, key);
|
|
3784
|
-
if (!descriptor) continue;
|
|
3785
|
-
descriptors[key] = typeof key === "string" && CLASSIFIER_IDENTIFIER_FIELDS.has(key) && typeof descriptor.value === "string" || isAuxiliaryAnchor(key, descriptor) || isCreatedBeforeFailureMark(key, descriptor) ? descriptor : maskDescriptorValue(descriptor, maskText);
|
|
3786
|
-
if (descriptors[key] !== descriptor) changed = true;
|
|
3787
|
-
}
|
|
3788
|
-
let cause = Object.getOwnPropertyDescriptor(link, "cause");
|
|
3789
|
-
if (cause && !("value" in cause && cause.value instanceof Error)) {
|
|
3790
|
-
const masked = maskDescriptorValue(cause, maskText);
|
|
3791
|
-
if (masked !== cause) changed = true;
|
|
3792
|
-
cause = masked;
|
|
3793
|
-
}
|
|
3794
|
-
if (message !== link.message || maskedStack !== stack) changed = true;
|
|
3795
|
-
return {
|
|
3796
|
-
message,
|
|
3797
|
-
stack: maskedStack,
|
|
3798
|
-
descriptors,
|
|
3799
|
-
cause
|
|
3800
|
-
};
|
|
3801
|
-
});
|
|
3802
|
-
if (!changed) return error;
|
|
3803
|
-
const clones = /* @__PURE__ */ new Map();
|
|
3804
|
-
for (const [i, original] of chain.entries()) {
|
|
3805
|
-
const { message, stack, descriptors } = links[i];
|
|
3806
|
-
const clone = Object.create(Object.getPrototypeOf(original), descriptors);
|
|
3807
|
-
Object.defineProperty(clone, "message", {
|
|
3808
|
-
value: message,
|
|
3809
|
-
writable: true,
|
|
3810
|
-
enumerable: false,
|
|
3811
|
-
configurable: true
|
|
3812
|
-
});
|
|
3813
|
-
if (stack !== void 0) Object.defineProperty(clone, "stack", {
|
|
3814
|
-
value: stack,
|
|
3815
|
-
writable: true,
|
|
3816
|
-
enumerable: false,
|
|
3817
|
-
configurable: true
|
|
3818
|
-
});
|
|
3819
|
-
clones.set(original, clone);
|
|
3820
|
-
}
|
|
3821
|
-
for (const [i, original] of chain.entries()) {
|
|
3822
|
-
const causeDescriptor = links[i].cause;
|
|
3823
|
-
if (!causeDescriptor) continue;
|
|
3824
|
-
const clone = clones.get(original);
|
|
3825
|
-
const causeValue = original.cause;
|
|
3826
|
-
const replacement = causeValue instanceof Error ? clones.get(causeValue) : void 0;
|
|
3827
|
-
Object.defineProperty(clone, "cause", replacement ? {
|
|
3828
|
-
value: replacement,
|
|
3829
|
-
writable: true,
|
|
3830
|
-
enumerable: causeDescriptor.enumerable === true,
|
|
3831
|
-
configurable: true
|
|
3832
|
-
} : causeDescriptor);
|
|
3681
|
+
function asChild(marks, key) {
|
|
3682
|
+
return isPlainObject(marks) && hasPlainPrototype(marks) ? marks[key] : void 0;
|
|
3683
|
+
}
|
|
3684
|
+
function asIndex(marks, index) {
|
|
3685
|
+
return Array.isArray(marks) ? marks[index] : void 0;
|
|
3686
|
+
}
|
|
3687
|
+
function preferPositionDecisions(scanned, refused, bag, marks, inferred) {
|
|
3688
|
+
if (isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(refused) && isPlainObject(scanned)) {
|
|
3689
|
+
const out = Object.create(null);
|
|
3690
|
+
for (const [k, v] of Object.entries(refused)) out[k] = preferPositionDecisions(scanned[k], v, bag[k], asChild(marks, k), inferred);
|
|
3691
|
+
return out;
|
|
3833
3692
|
}
|
|
3834
|
-
return
|
|
3693
|
+
if (Array.isArray(bag) && Array.isArray(refused) && Array.isArray(scanned) && refused.length === bag.length && scanned.length === bag.length) return refused.map((item, i) => preferPositionDecisions(scanned[i], item, bag[i], asIndex(marks, i), inferred));
|
|
3694
|
+
if (typeof bag !== "string" || marks === POSITION_DECIDED) return refused;
|
|
3695
|
+
const scanDecision = scanned === bag ? inferred.get(bag) ?? scanned : scanned;
|
|
3696
|
+
if (marks === POSITION_UNCERTIFIED && !(typeof scanDecision === "string" && isSingleDynamicReferenceToken(scanDecision))) return refused;
|
|
3697
|
+
return scanDecision;
|
|
3835
3698
|
}
|
|
3836
|
-
function
|
|
3837
|
-
|
|
3699
|
+
function deriveReadbackNeedles(bag, source, secrets, rules) {
|
|
3700
|
+
if (!isReadbackProjectedFromState(rules)) return void 0;
|
|
3701
|
+
if (secrets.size > 0) return void 0;
|
|
3702
|
+
if (!subtreeHasDynamicReference(source)) return void 0;
|
|
3703
|
+
const collector = {
|
|
3704
|
+
needles: /* @__PURE__ */ new Map(),
|
|
3705
|
+
poisoned: /* @__PURE__ */ new Set(),
|
|
3706
|
+
inferred: /* @__PURE__ */ new Set()
|
|
3707
|
+
};
|
|
3708
|
+
refuseUncertifiedReadbackPositions(bag, source, secrets, false, collector);
|
|
3709
|
+
if (collector.needles.size === 0) return void 0;
|
|
3710
|
+
const certain = /* @__PURE__ */ new Map();
|
|
3711
|
+
const inferred = /* @__PURE__ */ new Map();
|
|
3712
|
+
for (const [plaintext, expression] of collector.needles) (collector.inferred.has(plaintext) ? inferred : certain).set(plaintext, expression);
|
|
3713
|
+
return {
|
|
3714
|
+
certain,
|
|
3715
|
+
inferred
|
|
3716
|
+
};
|
|
3838
3717
|
}
|
|
3839
3718
|
|
|
3840
|
-
// src/deployment/secret-redaction/
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3719
|
+
// src/deployment/secret-redaction/redact-state/scrub-record.ts
|
|
3720
|
+
function scrubResourceRecord(record, secrets, sourceProperties, observedProvenance, claims = {}) {
|
|
3721
|
+
const propertiesClaimed = claims.properties === "same-generation";
|
|
3722
|
+
const observedClaimed = claims.observed === "same-generation";
|
|
3723
|
+
if (secrets.size === 0 && sourceProperties === void 0 && !record.observedProperties) return record;
|
|
3724
|
+
const next = { ...record };
|
|
3725
|
+
next.properties = claims.propertiesPositioned === true ? record.properties : sourceProperties === void 0 ? redactForState(record.properties, {
|
|
3726
|
+
provenance: "value-scan",
|
|
3727
|
+
secrets
|
|
3728
|
+
}) : redactAtProvenance(record.properties, secrets, sourceProperties, "template-derived", propertiesClaimed);
|
|
3729
|
+
if (record.attributes) {
|
|
3730
|
+
const ownId = record.physicalId;
|
|
3731
|
+
const ids = [...attributeIdCopiesOf.get(secrets) ?? []];
|
|
3732
|
+
if (typeof ownId === "string" && ownId !== "") ids.push(ownId);
|
|
3733
|
+
const attributes = record.attributes;
|
|
3734
|
+
next.attributes = ids.length > 0 ? withPhysicalNameCopies(secrets, ids, () => redactForState(attributes, {
|
|
3735
|
+
provenance: "value-scan",
|
|
3736
|
+
secrets
|
|
3737
|
+
})) : redactForState(attributes, {
|
|
3738
|
+
provenance: "value-scan",
|
|
3739
|
+
secrets
|
|
3740
|
+
});
|
|
3860
3741
|
}
|
|
3861
|
-
|
|
3742
|
+
const attemptedItems = record.unsettledItems;
|
|
3743
|
+
if (typeof attemptedItems === "object" && attemptedItems !== null && !Array.isArray(attemptedItems)) next.unsettledItems = redactForState(attemptedItems, {
|
|
3744
|
+
provenance: "value-scan",
|
|
3745
|
+
secrets
|
|
3746
|
+
});
|
|
3747
|
+
if (record.observedProperties) next.observedProperties = redactAtProvenance(record.observedProperties, secrets, sourceProperties ?? next.properties, observedProvenance ?? (sourceProperties !== void 0 ? "template-sourced" : secrets.size === 0 && observedClaimed ? "state-baseline" : "state-readback"), observedClaimed);
|
|
3748
|
+
return next;
|
|
3862
3749
|
}
|
|
3863
|
-
function
|
|
3864
|
-
|
|
3865
|
-
if (
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
const fragments = fragmentsOfNeedleIn(joined, ",", pieces.map((piece) => numeric ? String(Number(piece)) : piece).join(","));
|
|
3872
|
-
if (fragments.size === 0) continue;
|
|
3873
|
-
recordLogOnlyValue(to, needle);
|
|
3874
|
-
for (const fragment of fragments) recordLogOnlyValue(to, fragment);
|
|
3750
|
+
function withoutPhysicalNameCopies(secrets, run) {
|
|
3751
|
+
const names = physicalNameCopiesOf.get(secrets);
|
|
3752
|
+
if (names === void 0) return run();
|
|
3753
|
+
physicalNameCopiesOf.delete(secrets);
|
|
3754
|
+
try {
|
|
3755
|
+
return run();
|
|
3756
|
+
} finally {
|
|
3757
|
+
physicalNameCopiesOf.set(secrets, names);
|
|
3875
3758
|
}
|
|
3876
3759
|
}
|
|
3877
|
-
function
|
|
3878
|
-
|
|
3879
|
-
const
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3760
|
+
function withPhysicalNameCopies(secrets, ids, run) {
|
|
3761
|
+
const previous = physicalNameCopiesOf.get(secrets);
|
|
3762
|
+
const names = new Set(previous);
|
|
3763
|
+
for (const id of ids) if (id !== "") names.add(id);
|
|
3764
|
+
physicalNameCopiesOf.set(secrets, names);
|
|
3765
|
+
try {
|
|
3766
|
+
return run();
|
|
3767
|
+
} finally {
|
|
3768
|
+
if (previous === void 0) physicalNameCopiesOf.delete(secrets);
|
|
3769
|
+
else physicalNameCopiesOf.set(secrets, previous);
|
|
3884
3770
|
}
|
|
3885
3771
|
}
|
|
3886
|
-
function
|
|
3887
|
-
|
|
3888
|
-
if (
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3772
|
+
function repairPhysicalNameCopyLeaves(stored, legacy, current) {
|
|
3773
|
+
if (typeof stored === "string") return typeof legacy === "string" && typeof current === "string" && stored === legacy && current !== legacy ? current : stored;
|
|
3774
|
+
if (Array.isArray(stored)) {
|
|
3775
|
+
if (!Array.isArray(legacy) || !Array.isArray(current)) return stored;
|
|
3776
|
+
if (legacy.length !== stored.length || current.length !== stored.length) return stored;
|
|
3777
|
+
let changed = false;
|
|
3778
|
+
const out = stored.map((item, i) => {
|
|
3779
|
+
const next = repairPhysicalNameCopyLeaves(item, legacy[i], current[i]);
|
|
3780
|
+
if (next !== item) changed = true;
|
|
3781
|
+
return next;
|
|
3782
|
+
});
|
|
3783
|
+
return changed ? out : stored;
|
|
3898
3784
|
}
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3785
|
+
if (stored !== null && typeof stored === "object") {
|
|
3786
|
+
if (legacy === null || typeof legacy !== "object" || Array.isArray(legacy)) return stored;
|
|
3787
|
+
if (current === null || typeof current !== "object" || Array.isArray(current)) return stored;
|
|
3788
|
+
const l = legacy;
|
|
3789
|
+
const c = current;
|
|
3790
|
+
let out;
|
|
3791
|
+
for (const [key, value] of Object.entries(stored)) {
|
|
3792
|
+
if (!Object.hasOwn(l, key) || !Object.hasOwn(c, key)) continue;
|
|
3793
|
+
const next = repairPhysicalNameCopyLeaves(value, l[key], c[key]);
|
|
3794
|
+
if (next !== value) {
|
|
3795
|
+
out ??= { ...stored };
|
|
3796
|
+
out[key] = next;
|
|
3797
|
+
}
|
|
3905
3798
|
}
|
|
3799
|
+
return out ?? stored;
|
|
3906
3800
|
}
|
|
3907
|
-
return
|
|
3801
|
+
return stored;
|
|
3908
3802
|
}
|
|
3909
|
-
function
|
|
3910
|
-
const
|
|
3911
|
-
|
|
3912
|
-
const
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3803
|
+
function embeddedPhysicalNameRewrites(secrets, legacySecrets = secrets) {
|
|
3804
|
+
const names = physicalNameCopiesOf.get(secrets);
|
|
3805
|
+
if (names === void 0) return [];
|
|
3806
|
+
const pairs = [];
|
|
3807
|
+
withoutPhysicalNameCopies(legacySecrets, () => {
|
|
3808
|
+
for (const name of names) {
|
|
3809
|
+
const legacy = redactForState(name, {
|
|
3810
|
+
provenance: "value-scan",
|
|
3811
|
+
secrets: legacySecrets
|
|
3812
|
+
});
|
|
3813
|
+
if (typeof legacy === "string" && legacy !== name && mentionsDynamicReference(legacy) && !isSingleDynamicReferenceToken(legacy) && !mentionsMask(legacy)) pairs.push([legacy, name]);
|
|
3916
3814
|
}
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
seen.add(node);
|
|
3920
|
-
for (const child of Array.isArray(node) ? node : Object.values(node)) walk(child);
|
|
3921
|
-
};
|
|
3922
|
-
walk(value);
|
|
3923
|
-
return leaves;
|
|
3815
|
+
});
|
|
3816
|
+
return pairs;
|
|
3924
3817
|
}
|
|
3925
|
-
function
|
|
3926
|
-
|
|
3818
|
+
function replaceEmbeddedPhysicalNameRewrites(value, pairs) {
|
|
3819
|
+
if (pairs.length === 0) return value;
|
|
3820
|
+
if (typeof value === "string") {
|
|
3821
|
+
let next = value;
|
|
3822
|
+
for (const [legacy, name] of pairs) next = next.split(legacy).join(name);
|
|
3823
|
+
return next;
|
|
3824
|
+
}
|
|
3825
|
+
if (Array.isArray(value)) {
|
|
3826
|
+
let changed = false;
|
|
3827
|
+
const out = value.map((item) => {
|
|
3828
|
+
const next = replaceEmbeddedPhysicalNameRewrites(item, pairs);
|
|
3829
|
+
if (next !== item) changed = true;
|
|
3830
|
+
return next;
|
|
3831
|
+
});
|
|
3832
|
+
return changed ? out : value;
|
|
3833
|
+
}
|
|
3834
|
+
if (value !== null && typeof value === "object") {
|
|
3835
|
+
let out;
|
|
3836
|
+
for (const [key, item] of Object.entries(value)) {
|
|
3837
|
+
const next = replaceEmbeddedPhysicalNameRewrites(item, pairs);
|
|
3838
|
+
if (next !== item) {
|
|
3839
|
+
out ??= { ...value };
|
|
3840
|
+
out[key] = next;
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
return out ?? value;
|
|
3844
|
+
}
|
|
3845
|
+
return value;
|
|
3927
3846
|
}
|
|
3928
|
-
function
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
if (
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3847
|
+
function repairEmbeddedPhysicalNamesTowards(stored, target, pairs) {
|
|
3848
|
+
if (pairs.length === 0) return stored;
|
|
3849
|
+
if (typeof stored === "string") {
|
|
3850
|
+
if (typeof target !== "string" || stored === target) return stored;
|
|
3851
|
+
const repaired = replaceEmbeddedPhysicalNameRewrites(stored, pairs);
|
|
3852
|
+
return repaired === target ? repaired : stored;
|
|
3853
|
+
}
|
|
3854
|
+
if (Array.isArray(stored)) {
|
|
3855
|
+
if (!Array.isArray(target) || target.length !== stored.length) return stored;
|
|
3856
|
+
let changed = false;
|
|
3857
|
+
const out = stored.map((item, i) => {
|
|
3858
|
+
const next = repairEmbeddedPhysicalNamesTowards(item, target[i], pairs);
|
|
3859
|
+
if (next !== item) changed = true;
|
|
3860
|
+
return next;
|
|
3861
|
+
});
|
|
3862
|
+
return changed ? out : stored;
|
|
3863
|
+
}
|
|
3864
|
+
if (stored !== null && typeof stored === "object") {
|
|
3865
|
+
if (target === null || typeof target !== "object" || Array.isArray(target)) return stored;
|
|
3866
|
+
const t = target;
|
|
3867
|
+
let out;
|
|
3868
|
+
for (const [key, value] of Object.entries(stored)) {
|
|
3869
|
+
if (!Object.hasOwn(t, key)) continue;
|
|
3870
|
+
const next = repairEmbeddedPhysicalNamesTowards(value, t[key], pairs);
|
|
3871
|
+
if (next !== value) {
|
|
3872
|
+
out ??= { ...stored };
|
|
3873
|
+
out[key] = next;
|
|
3874
|
+
}
|
|
3936
3875
|
}
|
|
3937
|
-
|
|
3938
|
-
if (Array.isArray(value)) {
|
|
3939
|
-
for (const element of value) record(element);
|
|
3940
|
-
record(value.map((element) => String(element)).join(","));
|
|
3941
|
-
return;
|
|
3876
|
+
return out ?? stored;
|
|
3942
3877
|
}
|
|
3943
|
-
|
|
3878
|
+
return stored;
|
|
3944
3879
|
}
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3880
|
+
|
|
3881
|
+
// src/deployment/secret-redaction/redact-state.ts
|
|
3882
|
+
function redactSecretsForState(bag, secrets, source, rules = TEMPLATE_DERIVED_RULES, bagIsSameGeneration = false) {
|
|
3883
|
+
return flattenEmbeddedNoEchoLeaves(redactSecretsForStatePasses(bag, secrets, source, rules, bagIsSameGeneration), secrets);
|
|
3884
|
+
}
|
|
3885
|
+
function redactSecretsForStatePasses(bag, secrets, source, rules, bagIsSameGeneration) {
|
|
3886
|
+
if (secrets.size === 0 && source === void 0) return bag;
|
|
3887
|
+
if (source !== void 0) {
|
|
3888
|
+
const positioned = redactByPath(bag, source, secrets, rules, recordedExpressionsOf(secrets), bagIsSameGeneration);
|
|
3889
|
+
if (!isReadbackProjectedFromState(rules)) return positioned;
|
|
3890
|
+
const failClosed = rules.failClosedOnUncertifiedPositions === true;
|
|
3891
|
+
const refused = refuseUncertifiedReadbackPositions(positioned, source, secrets, failClosed);
|
|
3892
|
+
const derived = deriveReadbackNeedles(bag, source, secrets, rules);
|
|
3893
|
+
if (derived === void 0) return refused;
|
|
3894
|
+
const marks = refuseUncertifiedReadbackPositions(positioned, source, secrets, failClosed, void 0, true);
|
|
3895
|
+
return preferPositionDecisions(redactForState(bag, {
|
|
3896
|
+
provenance: "value-scan",
|
|
3897
|
+
secrets: derived.certain
|
|
3898
|
+
}), refused, bag, marks, derived.inferred);
|
|
3899
|
+
}
|
|
3900
|
+
const regex = buildNeedleRegex(substringNeedlesOf(secrets));
|
|
3901
|
+
const wholeValueExpr = (s) => s === "" ? void 0 : secrets.get(s);
|
|
3902
|
+
const physicalNames = physicalNameCopiesOf.get(secrets);
|
|
3903
|
+
let vouched;
|
|
3904
|
+
const vouchedExpressions = () => vouched ??= new Set(secrets.values());
|
|
3905
|
+
const expressionFor = (match) => {
|
|
3906
|
+
return secrets.get(match) ?? "***";
|
|
3907
|
+
};
|
|
3908
|
+
const scanLeaf = (value, needles) => {
|
|
3909
|
+
const spans = isDynamicReferenceString(value) ? resolvableReferenceSpans(value, vouchedExpressions()) : [];
|
|
3910
|
+
const names = physicalNameSpans(physicalNames, value);
|
|
3911
|
+
const kept = (start, end) => isStrictlyInsideASpan(spans, start, end) || names.some((n) => n.start <= start && end <= n.end);
|
|
3912
|
+
if (!legacyOverlapScan.has(secrets)) {
|
|
3913
|
+
const matches = everyMatch(value, needles);
|
|
3914
|
+
const redacted = matches.filter((m) => !kept(m.start, m.end));
|
|
3915
|
+
if (cutsContainmentNeedle(value, secrets, redacted)) {
|
|
3916
|
+
overlapAnswered.add(secrets);
|
|
3917
|
+
return "***";
|
|
3918
|
+
}
|
|
3919
|
+
const overlapping = redactOverlappingMatches(value, matches, redacted, expressionFor);
|
|
3920
|
+
if (overlapping !== void 0) {
|
|
3921
|
+
overlapAnswered.add(secrets);
|
|
3922
|
+
return overlapping;
|
|
3923
|
+
}
|
|
3958
3924
|
}
|
|
3959
|
-
|
|
3960
|
-
|
|
3925
|
+
return value.replace(needles, (match, offset) => {
|
|
3926
|
+
if (kept(offset, offset + match.length)) return match;
|
|
3927
|
+
return expressionFor(match);
|
|
3928
|
+
});
|
|
3961
3929
|
};
|
|
3962
|
-
const
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
return;
|
|
3930
|
+
const walk = (value) => {
|
|
3931
|
+
if (typeof value === "string") {
|
|
3932
|
+
if (physicalNames?.has(value) === true) return value;
|
|
3933
|
+
const whole = wholeValueExpr(value);
|
|
3934
|
+
if (whole !== void 0) return whole;
|
|
3935
|
+
if (isSingleDynamicReferenceToken(value) && spanNamesResolvableService(value)) return value;
|
|
3936
|
+
if (!regex) return value;
|
|
3937
|
+
regex.lastIndex = 0;
|
|
3938
|
+
if (!regex.test(value)) return value;
|
|
3939
|
+
return scanLeaf(value, regex);
|
|
3969
3940
|
}
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3941
|
+
if (Array.isArray(value)) return value.map(walk);
|
|
3942
|
+
if (value !== null && typeof value === "object") {
|
|
3943
|
+
if (isOrdinaryDate(value)) {
|
|
3944
|
+
const persisted = value.toJSON();
|
|
3945
|
+
if (typeof persisted !== "string") return value;
|
|
3946
|
+
const scanned = walk(persisted);
|
|
3947
|
+
return scanned === persisted ? value : scanned;
|
|
3948
|
+
}
|
|
3949
|
+
const out = Object.create(null);
|
|
3950
|
+
for (const [k, v] of Object.entries(value)) out[k] = walk(v);
|
|
3951
|
+
return out;
|
|
3973
3952
|
}
|
|
3953
|
+
return value;
|
|
3974
3954
|
};
|
|
3975
|
-
walk(
|
|
3976
|
-
return delimiters;
|
|
3955
|
+
return walk(bag);
|
|
3977
3956
|
}
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
for (const needle of logOnly) if (!corpus.has(needle)) corpus.set(needle, "***");
|
|
3983
|
-
return corpus;
|
|
3957
|
+
const legacyOverlapScan = /* @__PURE__ */ new WeakSet();
|
|
3958
|
+
const overlapAnswered = /* @__PURE__ */ new WeakSet();
|
|
3959
|
+
function overlapRuleAnswered(secrets) {
|
|
3960
|
+
return overlapAnswered.has(secrets);
|
|
3984
3961
|
}
|
|
3985
|
-
function
|
|
3986
|
-
|
|
3962
|
+
function withLegacyOverlapScan(secrets, run) {
|
|
3963
|
+
if (legacyOverlapScan.has(secrets)) return run();
|
|
3964
|
+
legacyOverlapScan.add(secrets);
|
|
3965
|
+
try {
|
|
3966
|
+
return run();
|
|
3967
|
+
} finally {
|
|
3968
|
+
legacyOverlapScan.delete(secrets);
|
|
3969
|
+
}
|
|
3987
3970
|
}
|
|
3988
|
-
function
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
for (const [plaintext, expression] of bag) if (!union.has(plaintext)) union.set(plaintext, expression);
|
|
3993
|
-
carryLogOnlyValues(bag, union);
|
|
3971
|
+
function differingStringLeaves(legacy, current, out = []) {
|
|
3972
|
+
if (typeof legacy === "string" && typeof current === "string") {
|
|
3973
|
+
if (legacy !== current) out.push([legacy, current]);
|
|
3974
|
+
return out;
|
|
3994
3975
|
}
|
|
3995
|
-
|
|
3976
|
+
if (Array.isArray(legacy) && Array.isArray(current) && legacy.length === current.length) {
|
|
3977
|
+
legacy.forEach((item, i) => differingStringLeaves(item, current[i], out));
|
|
3978
|
+
return out;
|
|
3979
|
+
}
|
|
3980
|
+
if (legacy !== null && current !== null && typeof legacy === "object" && typeof current === "object" && !Array.isArray(legacy) && !Array.isArray(current)) {
|
|
3981
|
+
const c = current;
|
|
3982
|
+
for (const [key, value] of Object.entries(legacy)) if (Object.hasOwn(c, key)) differingStringLeaves(value, c[key], out);
|
|
3983
|
+
}
|
|
3984
|
+
return out;
|
|
3996
3985
|
}
|
|
3997
|
-
function
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
3986
|
+
function legacyLeavesWithoutMask(legacy) {
|
|
3987
|
+
if (typeof legacy === "string") return legacy.includes("***") ? void 0 : legacy;
|
|
3988
|
+
if (Array.isArray(legacy)) return legacy.map(legacyLeavesWithoutMask);
|
|
3989
|
+
if (legacy !== null && typeof legacy === "object") {
|
|
3990
|
+
const out = Object.create(null);
|
|
3991
|
+
for (const [key, value] of Object.entries(legacy)) out[key] = legacyLeavesWithoutMask(value);
|
|
3992
|
+
return out;
|
|
3993
|
+
}
|
|
3994
|
+
return legacy;
|
|
3995
|
+
}
|
|
3996
|
+
function legacyReferenceLeavesOnly(legacy) {
|
|
3997
|
+
if (typeof legacy === "string") return legacy.includes("{{resolve:") ? legacy : void 0;
|
|
3998
|
+
if (Array.isArray(legacy)) return legacy.map(legacyReferenceLeavesOnly);
|
|
3999
|
+
if (legacy !== null && typeof legacy === "object") {
|
|
4000
|
+
const out = Object.create(null);
|
|
4001
|
+
for (const [key, value] of Object.entries(legacy)) out[key] = legacyReferenceLeavesOnly(value);
|
|
4002
|
+
return out;
|
|
4003
|
+
}
|
|
4004
|
+
return legacy;
|
|
4005
|
+
}
|
|
4006
|
+
function replaceWholeLeaves(value, pairs) {
|
|
4007
|
+
if (pairs.length === 0) return value;
|
|
4008
|
+
if (typeof value === "string") {
|
|
4009
|
+
const hit = pairs.find(([legacy]) => legacy === value);
|
|
4010
|
+
return hit === void 0 ? value : hit[1];
|
|
4011
|
+
}
|
|
4012
|
+
if (Array.isArray(value)) {
|
|
4013
|
+
let changed = false;
|
|
4014
|
+
const out = value.map((item) => {
|
|
4015
|
+
const next = replaceWholeLeaves(item, pairs);
|
|
4016
|
+
if (next !== item) changed = true;
|
|
4017
|
+
return next;
|
|
4018
|
+
});
|
|
4019
|
+
return changed ? out : value;
|
|
4020
|
+
}
|
|
4021
|
+
if (value !== null && typeof value === "object") {
|
|
4022
|
+
let out;
|
|
4023
|
+
for (const [key, item] of Object.entries(value)) {
|
|
4024
|
+
const next = replaceWholeLeaves(item, pairs);
|
|
4025
|
+
if (next !== item) {
|
|
4026
|
+
out ??= Object.assign(Object.create(null), value);
|
|
4027
|
+
out[key] = next;
|
|
4009
4028
|
}
|
|
4010
|
-
scanned = printingNeedles(needles);
|
|
4011
|
-
stamp = now;
|
|
4012
4029
|
}
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4030
|
+
return out ?? value;
|
|
4031
|
+
}
|
|
4032
|
+
return value;
|
|
4016
4033
|
}
|
|
4017
|
-
function
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4034
|
+
function everyMatch(value, needles) {
|
|
4035
|
+
const matches = [];
|
|
4036
|
+
needles.lastIndex = 0;
|
|
4037
|
+
for (let m = needles.exec(value); m !== null; m = needles.exec(value)) {
|
|
4038
|
+
matches.push({
|
|
4039
|
+
start: m.index,
|
|
4040
|
+
end: m.index + m[0].length
|
|
4041
|
+
});
|
|
4042
|
+
needles.lastIndex = m.index + 1;
|
|
4043
|
+
}
|
|
4044
|
+
needles.lastIndex = 0;
|
|
4045
|
+
return matches;
|
|
4021
4046
|
}
|
|
4022
|
-
function
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
const
|
|
4026
|
-
|
|
4047
|
+
function redactOverlappingMatches(value, matches, redacted, expressionFor) {
|
|
4048
|
+
let reach = 0;
|
|
4049
|
+
let overlap = false;
|
|
4050
|
+
for (const m of matches) {
|
|
4051
|
+
if (m.start < reach) overlap = true;
|
|
4052
|
+
reach = Math.max(reach, m.end);
|
|
4053
|
+
}
|
|
4054
|
+
if (!overlap) return void 0;
|
|
4055
|
+
let out = "";
|
|
4056
|
+
let cursor = 0;
|
|
4057
|
+
for (let i = 0; i < redacted.length;) {
|
|
4058
|
+
let end = redacted[i].end;
|
|
4059
|
+
let j = i + 1;
|
|
4060
|
+
for (; j < redacted.length && redacted[j].start < end; j++) end = Math.max(end, redacted[j].end);
|
|
4061
|
+
const cluster = redacted.slice(i, j);
|
|
4062
|
+
out += value.slice(cursor, cluster[0].start);
|
|
4063
|
+
for (let at = cluster[0].start; at < end;) {
|
|
4064
|
+
const tile = cluster.find((m) => m.start === at);
|
|
4065
|
+
if (tile === void 0) return "***";
|
|
4066
|
+
out += expressionFor(value.slice(tile.start, tile.end));
|
|
4067
|
+
at = tile.end;
|
|
4068
|
+
}
|
|
4069
|
+
cursor = end;
|
|
4070
|
+
i = j;
|
|
4071
|
+
}
|
|
4072
|
+
return out + value.slice(cursor);
|
|
4027
4073
|
}
|
|
4028
4074
|
|
|
4029
4075
|
// src/deployment/secret-redaction/reference-provenance.ts
|
|
@@ -4431,6 +4477,7 @@ function literalTextHoldsSubFloorSecret(spelling, secrets) {
|
|
|
4431
4477
|
if (expression === "***") continue;
|
|
4432
4478
|
if (pieces.some((piece) => piece.includes(plaintext))) return true;
|
|
4433
4479
|
}
|
|
4480
|
+
for (const plaintext of inheritedSubFloorPlaintexts.get(secrets) ?? []) if (pieces.some((piece) => piece.includes(plaintext))) return true;
|
|
4434
4481
|
return false;
|
|
4435
4482
|
}
|
|
4436
4483
|
function renderedLiteralSpans(spelling, secrets, value) {
|
|
@@ -6137,5 +6184,5 @@ function enclosingDeadlineRemainingMs() {
|
|
|
6137
6184
|
return deadlineScope.getStore()?.remainingMs() ?? Number.POSITIVE_INFINITY;
|
|
6138
6185
|
}
|
|
6139
6186
|
|
|
6140
|
-
export { isTerminalDbWaitStatus as $,
|
|
6141
|
-
//# sourceMappingURL=resource-deadline-
|
|
6187
|
+
export { isTerminalDbWaitStatus as $, setPasteableAwsCaBundle as $i, SPELLED_SECRET_REFERENCE_PREFIXES as $n, recordPhysicalNameCopy as $r, markAuxiliaryFailure as $t, importRemedyCommand as A, recordMaskOnlyValuesIn as Ai, redactForState as An, recordLogOnlySplitFragments as Ar, canonicalizeRoute53QueryName as At, isMarkedNotGone as B, maskMatchSpans as Bi, differingStringLeaves as Bn, embedsFreshNoEchoValue as Br, createMaskedRetryLogger as Bt, withoutServerErrorRetries as C, markNoEchoParameterClass as Ci, recordIntrinsicLeafResolution as Cn, hasLogOnlyValues as Cr, recordedPrincipalsRepair as Ct, holderRefusalMask as D, recordDerivedMaskOnlyValue as Di, literalTextHoldsSubFloorSecret as Dn, logOnlyValuesOf as Dr, interruptWatchListenerCount as Dt, assertRegionMatch as E, provenPublicValue as Ei, resolvedPlaintextOf as En, logOnlyValueCount as Er, endCommandInterruptScope as Et, quotedRemedyLogicalId as F, withoutNoEchoParameterEntries as Fi, passProvenanceFor as Fn, errorCauseChain as Fr, packCompositeId as Ft, observeThenDisableProtection as G, formatLockExpiry as Gi, withLegacyOverlapScan as Gn, nestedStackRowTagSpellingOf as Gr, RETRY_AUXILIARY_OWNER as Gt, compensateProtectionFlip as H, buildForceUnlockCommand as Hi, legacyReferenceLeavesOnly as Hn, recordRecoverableMaskedOutput as Hr, maskDeep as Ht, readNameProperty as I, WHOLE_DYNAMIC_REFERENCE_PATTERN as Ii, passReadVersionsFor as In, maskRecordedSecretsInText as Ir, resourceTypeShown as It, userPoolProtectionSite as J, recoveryCommandFlags as Ji, repairPhysicalNameCopyLeaves as Jn, recordTakenIfBranch as Jr, createdBeforeFailure as Jt, rdsFamilyProtectionSite as K, formatLockOperation as Ki, embeddedPhysicalNameRewrites as Kn, staticTemplateText as Kr, carryCreatedBeforeFailure as Kt, refusalTypeShown as L, isDynamicReferenceString as Li, recordReferenceProvenanceEntry as Ln, maskSecretsInError as Lr, segmentAfterAnchor as Lt, isPlainImportValue as M, recordNoEchoParameterFreshValue as Mi, openRecordingScope as Mn, shareLogOnlyValues as Mr, compositeIdSeparatorRefusal as Mt, isQuotableImportValue as N, recordProvenPublicExpression as Ni, recordSecretResolution as Nn, unionOfSecretBags as Nr, compositeIdSkipResult as Nt, holderRefusalRun as O, recordFreshNoEchoValuesIn as Oi, mixedLiteralAnswered as On, printingCorpusOf as Or, isInterruptedWaitError as Ot, normalizeAwsTagsToCfn as P, wholeStringLeavesOf as Pi, hasPassProvenance as Pn, createSecretMasker as Pr, logicalIdShown as Pt, isProceedDbStatus as Q, WAIT_CONDITION_SIGNAL_PREFIX as Qi, withoutPhysicalNameCopies as Qn, recordAttributeIdCopy as Qr, isAuxiliaryMarkOf as Qt, remedyLogicalId as R, isPlainObject as Ri, recordReferenceResolution as Rn, maskSecretsInText as Rr, stateOrphanRecordRemedy as Rt, setBounded as S, isSecretExpressionByVerdictOrSpelling as Si, mergeResolvedPairs as Sn, createUnionSecretMasker as Sr, readRecordedPrincipals as St, RESOURCE_NOT_FOUND as T, pinScopedSecretVerdict as Ti, redactionClaimOf as Tn, literalSplitDelimitersOf as Tr, beginCommandInterruptScope as Tt, deleteWithProtectionCompensation as U, buildLockContentionMessage as Ui, overlapRuleAnswered as Un, recoverMaskedOutput as Ur, maskerOrIdentity as Ut, markNotGone as V, UNREPRODUCIBLE_LOCK_CLAUSE as Vi, legacyLeavesWithoutMask as Vn, freshNoEchoLeafPositions as Vr, isSecretDerivedValue as Vt, logGroupProtectionSite as W, forceQuitRecoveryClause as Wi, replaceWholeLeaves as Wn, recordNestedStackParameterExpressions as Wr, withDerivedNameMasks as Wt, deleteAfterProtectionFlipWithFinalSnapshot as X, CUSTOM_RESOURCE_RESPONSE_PREFIX as Xi, scrubResourceRecord as Xn, secretRerenderPairs as Xr, hasCreatedBeforeFailure as Xt, PROTECTION_FLIP_RETRY_WAIT_MS as Y, sanitizeRecoveryValue as Yi, replaceEmbeddedPhysicalNameRewrites as Yn, keepTemplateLiteralLeaves as Yr, createdResourceIdentityBeforeFailure as Yt, isFinalSnapshotNotAvailableRefusal as Z, DEFAULT_STATE_PREFIX as Zi, withPhysicalNameCopies as Zn, physicalNameCopiesOf as Zr, isAuxiliaryFailure as Zt, ambiguousAttemptLead as _, freshNoEchoValuesOf as _i, carryRedactionMarks as _n, recordInheritedParameterValue as _r, SECRET_DERIVED_READ_LIVE as _t, whileEnclosingDeadlinesPaused as a, producerRecordKey as aa, dynamicReferenceSpans as ai, dynamicReferenceOpeners as an, identityKeyFor as ar, ElapsedBudget as at, replayFollowedAmbiguousAttempt as b, isRecordedSecretExpression as bi, markLeafCertifiedBag as bn, carryLogOnlyValues as br, onlySecretDerived as bt, clearCreatedReport as c, noteReferenceConsumed as ci, isMaskRun as cn, standsForInheritedSecret as cr, DELETION_PROTECTION_DOC_POINTER as ct, reportedCreatedResource as d, crossStackSourceKey as di, mentionsMask as dn, templateRereadsAccountId as dr, isAwsCliLiteral as dt, setPasteableAwsProfile as ea, attributionRefusedParameters as ei, markCreatedBeforeFailure as en, spanNamesResolvableService as er, PROTECTION_FLIP_REUSE_WINDOW_MS as et, retractCreatedResource as f, recordCrossStackExpression as fi, mentionsMaskedIdSegment as fn, carriesInheritedRedaction as fr, pasteableAwsCommand as ft, RecentIdSet as g, contradictProvenPublicExpression as gi, valueMentionsDynamicReference as gn, recordInheritedParameterRead as gr, RESOLVED_PREVIOUS_PRINCIPAL_KEYS as gt, CREATION_DATE_SKEW_MARGIN_MS as h, carryFreshNoEchoMark as hi, usableRecordedName as hn, inheritedRenderedToken as hr, IAM_PRINCIPAL_NAME as ht, outsideEnclosingDeadlines as i, producerCoordinateKey as ia, DYNAMIC_REFERENCE_TOKEN_SCAN as ii, dynamicReferenceBody as in, arrayPairsWhateverDrops as ir, runDeleteAttempt as it, isPlainImportJson as j, recordNoEchoAttributeValues as ji, foldRecording as jn, recordLogOnlyValue as jr, compositeIdFormatMessage as jt, VALUE_NOT_SHOWN as k, recordMaskOnlyValue as ki, withLegacyMixedScan as kn, recordLogOnlyParameterValue as kr, startInterruptWatch as kt, collectCreatedResources as l, withConsumptionScope as li, mentionsDynamicReference as ln, inheritedPseudoValue as lr, UNNAMEABLE_ID_CLAUSE as lt, AmbiguousCreateLatch as m, carriesSecretMask as mi, recordedSecrecyOf as mn, inheritedParameterExpression as mr, renderDisableCommand as mt, enclosingDeadlineRemainingMs as n, injectiveKey as na, containsCarriedSubFloorText as ni, replayMadeAnotherResource as nn, spelledKeysOf as nr, isTerminalDeleteFailure as nt, withResourceDeadline as o, dynamicReferenceTokens as oi, holdsMaskLeaf as on, rereadParameterExpression as or, ElapsedBudgetRegistry as ot, AMBIGUOUS_LATCH_TTL_MS as p, splitGetAttStringForm as pi, opensDynamicReferenceTo as pn, inheritNestedStackParameterAssociations as pr, protectedReplacementAdvice as pt, settleProtectionFlip as q, formatLockOwner as qi, repairEmbeddedPhysicalNamesTowards as qn, recordDroppedArrayElements as qr, clearCreatedBeforeFailure as qt, formatWarnElapsed as r, injectiveKeyPrefix as ra, isCarriedSubFloorText as ri, countDynamicReferenceOpenings as rn, pathCrossesDottedKey as rr, protectionFlipKey as rt, CreatedResourceSink as s, consumptionScopeOpenFor as si, isMaskLeaf as sn, splitOutsideDynamicReferences as sr, monotonicNowMs as st, enclosingDeadlineExpired as t, withPasteableAwsProfile as ta, carriesSubFloorEvidence as ti, markSupersedesEarlierCreate as tn, isUncertifiedBaselineMaskPosition as tr, ProtectionFlipRegistry as tt, reportCreatedResource as u, withoutConsumptionStamps as ui, mentionsDynamicReferenceTo as un, recordInheritedPseudoParameters as ur, WITHHELD_AWS_COMMAND as ut, createAttemptKey as v, isMaskOnlyPlaintext as vi, intrinsicLeafResolutionOf as vn, redactInheritedParameterValue as vr, diffPrincipalNames as vt, DriftReadRefusedError as w, noEchoParameterPlaintextsOf as wi, recordIntrinsicLeafResolutionAs as wn, hasMaskableValues as wr, withUnchangedSecretPrincipalLists as wt, replayedSendWindow as x, isScopedSecretVerdict as xi, markSameGenerationBag as xn, carryLogOnlyValuesCarriedBy as xr, readPrincipalLists as xt, isInsideWindow as y, isNoEchoParameterPlaintext as yi, isSameGenerationBag as yn, withdrawRenderedParameterSpelling as yr, holdsSecretDerivedEntry as yt, resolveExplicitPhysicalId as z, isSingleDynamicReferenceToken as zi, snapshotPassProvenance as zn, carriesFreshNoEchoValue as zr, createMaskedLogSinks as zt };
|
|
6188
|
+
//# sourceMappingURL=resource-deadline-0dfvU7D5.js.map
|