@cdkd/cli 0.372.0 → 0.373.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-B9_o60dB.js → ambient-client-defaults-1yRnA0Re.js} +3 -3
- package/dist/{ambient-client-defaults-B9_o60dB.js.map → ambient-client-defaults-1yRnA0Re.js.map} +1 -1
- package/dist/{asg-provider-D6gQPSZu.js → asg-provider-3uPCjYQK.js} +8 -8
- package/dist/{asg-provider-D6gQPSZu.js.map → asg-provider-3uPCjYQK.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/{created-resource-sink-CxezDoaQ.js → created-resource-sink-CBOr1ShX.js} +4 -4
- package/dist/{created-resource-sink-CxezDoaQ.js.map → created-resource-sink-CBOr1ShX.js.map} +1 -1
- package/dist/{custom-resource-runtime-BiP0vn3W.js → custom-resource-runtime-DURpNFOa.js} +6 -6
- package/dist/{custom-resource-runtime-BiP0vn3W.js.map → custom-resource-runtime-DURpNFOa.js.map} +1 -1
- package/dist/{db-associated-roles-BfvrD9UK.js → db-associated-roles-BbvtfXqW.js} +2 -2
- package/dist/{db-associated-roles-BfvrD9UK.js.map → db-associated-roles-BbvtfXqW.js.map} +1 -1
- package/dist/{delete-started-BtXSEHsh.js → delete-started-yz9plykR.js} +4 -4
- package/dist/{delete-started-BtXSEHsh.js.map → delete-started-yz9plykR.js.map} +1 -1
- package/dist/{deploy-engine-D6iEbD4R.js → deploy-engine-C12Ygjb-.js} +3416 -614
- package/dist/deploy-engine-C12Ygjb-.js.map +1 -0
- package/dist/{ec2-termination-protection-DXZyU3Q0.js → ec2-termination-protection-UZAZ2Hzv.js} +3 -3
- package/dist/{ec2-termination-protection-DXZyU3Q0.js.map → ec2-termination-protection-UZAZ2Hzv.js.map} +1 -1
- package/dist/{ecr-uri-C0JbYdmm.js → ecr-uri-C74u9FtL.js} +2 -2
- package/dist/{ecr-uri-C0JbYdmm.js.map → ecr-uri-C74u9FtL.js.map} +1 -1
- package/dist/{emr-cluster-provider-BCu1qq9J.js → emr-cluster-provider-2ezuxbz3.js} +10 -10
- package/dist/{emr-cluster-provider-BCu1qq9J.js.map → emr-cluster-provider-2ezuxbz3.js.map} +1 -1
- package/dist/{expected-bucket-owner-C2OXO5oD.js → expected-bucket-owner-0yx_Q4Hl.js} +2 -2
- package/dist/{expected-bucket-owner-C2OXO5oD.js.map → expected-bucket-owner-0yx_Q4Hl.js.map} +1 -1
- package/dist/{iam-role-provider-DFBJRsvA.js → iam-role-provider-CZtZQJRp.js} +12 -12
- package/dist/{iam-role-provider-DFBJRsvA.js.map → iam-role-provider-CZtZQJRp.js.map} +1 -1
- package/dist/{identity-read-denied-C17mECu-.js → identity-read-denied-DBsqwW85.js} +5 -5
- package/dist/{identity-read-denied-C17mECu-.js.map → identity-read-denied-DBsqwW85.js.map} +1 -1
- package/dist/{image-plan-sEIpoR31.js → image-plan-DW_fg6mx.js} +10 -9
- package/dist/image-plan-DW_fg6mx.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/{logger-BoDS8cs5.js → logger-JtU7m4ph.js} +2 -2
- package/dist/{logger-BoDS8cs5.js.map → logger-JtU7m4ph.js.map} +1 -1
- package/dist/{neptune-provider-CL5WtULJ.js → neptune-provider-ClT-eveS.js} +9 -9
- package/dist/{neptune-provider-CL5WtULJ.js.map → neptune-provider-ClT-eveS.js.map} +1 -1
- package/dist/{program-BBXUa34K.js → program-BPrn1MhZ.js} +381 -1111
- package/dist/program-BPrn1MhZ.js.map +1 -0
- package/dist/{provider-classes-BiWcIBLc.js → provider-classes-Bi3D5zDS.js} +22 -22
- package/dist/{provider-classes-BiWcIBLc.js.map → provider-classes-Bi3D5zDS.js.map} +1 -1
- package/dist/{rds-provider--XBD_TS8.js → rds-provider-D610vnfB.js} +13 -13
- package/dist/{rds-provider--XBD_TS8.js.map → rds-provider-D610vnfB.js.map} +1 -1
- package/dist/{read-replica-apcXpKN9.js → read-replica-Br2tFu0d.js} +3 -3
- package/dist/{read-replica-apcXpKN9.js.map → read-replica-Br2tFu0d.js.map} +1 -1
- package/dist/{redacted-delete-address-S_A40Diz.js → redacted-delete-address-DVgNoeo4.js} +4 -4
- package/dist/{redacted-delete-address-S_A40Diz.js.map → redacted-delete-address-DVgNoeo4.js.map} +1 -1
- package/dist/{replacement-rules-BArdRPgU.js → replacement-rules-BoZMVFdK.js} +2166 -1663
- package/dist/replacement-rules-BoZMVFdK.js.map +1 -0
- package/dist/{resource-deadline-DWvjidOS.js → resource-deadline-BkQ9mJAk.js} +2 -2
- package/dist/{resource-deadline-DWvjidOS.js.map → resource-deadline-BkQ9mJAk.js.map} +1 -1
- package/dist/{restore-source-guard-k9BQAviV.js → restore-source-guard-BkS5tGr5.js} +4 -4
- package/dist/{restore-source-guard-k9BQAviV.js.map → restore-source-guard-BkS5tGr5.js.map} +1 -1
- package/dist/{run-cli-DEVVmR3v.js → run-cli-Ds9QnqnH.js} +2 -2
- package/dist/{run-cli-DEVVmR3v.js.map → run-cli-Ds9QnqnH.js.map} +1 -1
- package/dist/{secret-reference-immutable-0mb2D0J5.js → secret-reference-immutable-BC4abPuQ.js} +7 -7
- package/dist/{secret-reference-immutable-0mb2D0J5.js.map → secret-reference-immutable-BC4abPuQ.js.map} +1 -1
- package/dist/{settle-own-write-members-DPTK_vVK.js → settle-own-write-members-D6wzEt7f.js} +11 -98
- package/dist/settle-own-write-members-D6wzEt7f.js.map +1 -0
- package/dist/{tag-list-B19O4m3W.js → tag-list-UEcqQLzY.js} +4 -4
- package/dist/{tag-list-B19O4m3W.js.map → tag-list-UEcqQLzY.js.map} +1 -1
- package/dist/{version-Byf_RTiH.js → version-Dn0kzidt.js} +2 -2
- package/dist/{version-Byf_RTiH.js.map → version-Dn0kzidt.js.map} +1 -1
- package/package.json +1 -1
- package/dist/deploy-engine-D6iEbD4R.js.map +0 -1
- package/dist/image-plan-sEIpoR31.js.map +0 -1
- package/dist/program-BBXUa34K.js.map +0 -1
- package/dist/replacement-rules-BArdRPgU.js.map +0 -1
- package/dist/settle-own-write-members-DPTK_vVK.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { P as safeMsg, x as SAFE_MSG_ALTERED_CHAR } from "./version-
|
|
2
|
-
import { n as getLogger } from "./logger-
|
|
1
|
+
import { P as safeMsg, x as SAFE_MSG_ALTERED_CHAR } from "./version-Dn0kzidt.js";
|
|
2
|
+
import { n as getLogger } from "./logger-JtU7m4ph.js";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
4
|
import { isDeepStrictEqual } from "node:util";
|
|
4
5
|
|
|
5
6
|
// src/deployment/secret-redaction/rules.ts
|
|
@@ -441,218 +442,117 @@ function storeAssociation(associations, key, expression, plaintext) {
|
|
|
441
442
|
if (seen.expression !== expression || seen.plaintext !== plaintext) associations.set(key, CONFLICTING_CROSS_STACK);
|
|
442
443
|
}
|
|
443
444
|
|
|
445
|
+
// src/deployment/secret-redaction/consumed-references.ts
|
|
446
|
+
const stamps = /* @__PURE__ */ new WeakMap();
|
|
447
|
+
const path = new AsyncLocalStorage();
|
|
448
|
+
const suspended$1 = new AsyncLocalStorage();
|
|
449
|
+
function withoutConsumptionStamps(fn) {
|
|
450
|
+
return suspended$1.run(true, fn);
|
|
451
|
+
}
|
|
452
|
+
function withConsumptionScope(node, fn) {
|
|
453
|
+
return path.run([...path.getStore() ?? [], node], fn);
|
|
454
|
+
}
|
|
455
|
+
function consumptionScopeOpenFor(node) {
|
|
456
|
+
const nodes = path.getStore();
|
|
457
|
+
return nodes !== void 0 && nodes[nodes.length - 1] === node;
|
|
458
|
+
}
|
|
459
|
+
function noteReferenceConsumed(secrets, token) {
|
|
460
|
+
if (suspended$1.getStore() === true) return;
|
|
461
|
+
const nodes = path.getStore();
|
|
462
|
+
if (nodes === void 0 || nodes.length === 0) return;
|
|
463
|
+
let table = stamps.get(secrets);
|
|
464
|
+
if (table === void 0) {
|
|
465
|
+
table = /* @__PURE__ */ new WeakMap();
|
|
466
|
+
stamps.set(secrets, table);
|
|
467
|
+
}
|
|
468
|
+
for (const node of nodes) {
|
|
469
|
+
let set = table.get(node);
|
|
470
|
+
if (set === void 0) {
|
|
471
|
+
set = /* @__PURE__ */ new Set();
|
|
472
|
+
table.set(node, set);
|
|
473
|
+
}
|
|
474
|
+
set.add(token);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function referencesConsumedBy(secrets, node) {
|
|
478
|
+
return stamps.get(secrets)?.get(node) ?? /* @__PURE__ */ new Set();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/deployment/secret-redaction/redact-path/reference-tokens.ts
|
|
482
|
+
const DYNAMIC_REFERENCE_TOKEN_SCAN = new RegExp(`\\{\\{resolve:${DYNAMIC_REFERENCE_INNER}\\}\\}`, "g");
|
|
483
|
+
function dynamicReferenceTokens(value) {
|
|
484
|
+
return value.match(DYNAMIC_REFERENCE_TOKEN_SCAN) ?? [];
|
|
485
|
+
}
|
|
486
|
+
function dynamicReferenceSpans(value) {
|
|
487
|
+
DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = 0;
|
|
488
|
+
const spans = [];
|
|
489
|
+
for (const match of value.matchAll(DYNAMIC_REFERENCE_TOKEN_SCAN)) spans.push({
|
|
490
|
+
start: match.index,
|
|
491
|
+
end: match.index + match[0].length
|
|
492
|
+
});
|
|
493
|
+
return spans;
|
|
494
|
+
}
|
|
495
|
+
function mixedLeafMayCarryPublicReference(source, secrets, readback) {
|
|
496
|
+
if (secrets.size === 0) return mixedLeafProvenPublic(source, secrets, readback);
|
|
497
|
+
return dynamicReferenceTokens(source).some((token) => token.startsWith("{{resolve:ssm:") && !isRecordedSecretExpression(token));
|
|
498
|
+
}
|
|
499
|
+
function mixedLeafProvenPublic(source, secrets, readback) {
|
|
500
|
+
const tokens = dynamicReferenceTokens(source);
|
|
501
|
+
if (tokens.length === 0) return false;
|
|
502
|
+
const values = /* @__PURE__ */ new Map();
|
|
503
|
+
for (const token of tokens) {
|
|
504
|
+
if (!token.startsWith("{{resolve:ssm:")) return false;
|
|
505
|
+
const value = provenPublicValue(secrets, token);
|
|
506
|
+
if (value === void 0) return false;
|
|
507
|
+
values.set(token, value);
|
|
508
|
+
}
|
|
509
|
+
DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = 0;
|
|
510
|
+
return source.replace(DYNAMIC_REFERENCE_TOKEN_SCAN, (token) => values.get(token)) === readback;
|
|
511
|
+
}
|
|
512
|
+
|
|
444
513
|
// src/deployment/secret-redaction/nested-stack/parameter-tables.ts
|
|
445
514
|
const NESTED_STACK_RESOURCE_TYPE = "AWS::CloudFormation::Stack";
|
|
446
515
|
const nestedStackParameterExpressions = /* @__PURE__ */ new WeakMap();
|
|
447
516
|
const renderedParameterSpellings = /* @__PURE__ */ new WeakMap();
|
|
448
517
|
const UNFRAMED_SPELLING = Symbol("cdkd.nested-parameter.unframed-spelling");
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (!Object.hasOwn(resolvedProperties, "Tags") || !Object.hasOwn(sourceProperties, "Tags")) return;
|
|
456
|
-
const resolvedTags = resolvedProperties["Tags"];
|
|
457
|
-
const sourceTags = sourceProperties["Tags"];
|
|
458
|
-
if (!Array.isArray(resolvedTags) || !Array.isArray(sourceTags)) return;
|
|
459
|
-
const sourceByKey = /* @__PURE__ */ new Map();
|
|
460
|
-
const repeated = /* @__PURE__ */ new Set();
|
|
461
|
-
for (const item of sourceTags) {
|
|
462
|
-
if (!isPlainObject(item)) return;
|
|
463
|
-
const key = item["Key"];
|
|
464
|
-
if (typeof key !== "string") return;
|
|
465
|
-
if (sourceByKey.has(key)) repeated.add(key);
|
|
466
|
-
sourceByKey.set(key, item["Value"]);
|
|
467
|
-
}
|
|
468
|
-
const table = /* @__PURE__ */ new Map();
|
|
469
|
-
for (const item of resolvedTags) {
|
|
470
|
-
if (!isPlainObject(item)) continue;
|
|
471
|
-
const key = item["Key"];
|
|
472
|
-
const value = item["Value"];
|
|
473
|
-
if (typeof key !== "string" || typeof value !== "string" || !sourceByKey.has(key)) continue;
|
|
474
|
-
if (repeated.has(key) || table.has(key)) {
|
|
475
|
-
table.set(key, null);
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
const spelling = certifiedSpelling(secrets, sourceByKey.get(key), value);
|
|
479
|
-
if (spelling !== void 0) table.set(key, spelling);
|
|
480
|
-
}
|
|
481
|
-
if (table.size > 0) rowTagSpellings.set(secrets, table);
|
|
482
|
-
else rowTagSpellings.delete(secrets);
|
|
483
|
-
}
|
|
484
|
-
function certifiedSpelling(secrets, source, value) {
|
|
485
|
-
if (typeof source === "string") {
|
|
486
|
-
if (dynamicReferenceSpans(source).length === 0) return source === value ? {
|
|
487
|
-
value,
|
|
488
|
-
spelling: source,
|
|
489
|
-
fromLiteral: true
|
|
490
|
-
} : void 0;
|
|
491
|
-
return rendersLiteralTo(source, secrets, value) ? {
|
|
492
|
-
value,
|
|
493
|
-
spelling: source,
|
|
494
|
-
fromLiteral: true
|
|
495
|
-
} : void 0;
|
|
518
|
+
const attributionRefusedParameters = /* @__PURE__ */ new WeakMap();
|
|
519
|
+
function markAttributionRefusedParameter(secrets, name, kind) {
|
|
520
|
+
let table = attributionRefusedParameters.get(secrets);
|
|
521
|
+
if (table === void 0) {
|
|
522
|
+
table = /* @__PURE__ */ new Map();
|
|
523
|
+
attributionRefusedParameters.set(secrets, table);
|
|
496
524
|
}
|
|
497
|
-
if (
|
|
498
|
-
const spelling = substitutedSpellingOf(secrets, source, value);
|
|
499
|
-
return spelling === void 0 ? void 0 : {
|
|
500
|
-
value,
|
|
501
|
-
spelling,
|
|
502
|
-
fromLiteral: false
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
function nestedStackRowTagSpellingOf(secrets, key, value) {
|
|
506
|
-
const entry = rowTagSpellings.get(secrets)?.get(key);
|
|
507
|
-
return entry !== void 0 && entry !== null && entry.value === value ? entry : void 0;
|
|
525
|
+
if (table.get(name) !== "masked") table.set(name, kind);
|
|
508
526
|
}
|
|
509
527
|
|
|
510
|
-
// src/deployment/secret-redaction/nested-stack/
|
|
511
|
-
function
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const sourceParameters = sourceProperties["Parameters"];
|
|
520
|
-
if (!isPlainObject(resolvedParameters) || !isPlainObject(sourceParameters)) return;
|
|
521
|
-
const positioned = withoutLiteralRendering(() => redactAtProvenance({ ...resolvedParameters }, secrets, sourceParameters, provenance, true));
|
|
522
|
-
let table = nestedStackParameterExpressions.get(secrets);
|
|
523
|
-
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
524
|
-
const sourceLeaf = sourceParameters[name];
|
|
525
|
-
if (typeof resolvedValue !== "string" || typeof sourceLeaf !== "string") continue;
|
|
526
|
-
if (isSingleDynamicReferenceToken(sourceLeaf) || positioned[name] !== sourceLeaf) continue;
|
|
527
|
-
if (!rendersLiteralTo(sourceLeaf, secrets, resolvedValue)) continue;
|
|
528
|
-
let rendered = renderedParameterSpellings.get(secrets);
|
|
529
|
-
if (rendered === void 0) {
|
|
530
|
-
rendered = /* @__PURE__ */ new Map();
|
|
531
|
-
renderedParameterSpellings.set(secrets, rendered);
|
|
532
|
-
}
|
|
533
|
-
const previous = rendered.get(name);
|
|
534
|
-
if (previous === void 0) rendered.set(name, {
|
|
535
|
-
spelling: sourceLeaf,
|
|
536
|
-
value: resolvedValue
|
|
537
|
-
});
|
|
538
|
-
else if (previous?.spelling !== sourceLeaf || previous.value !== resolvedValue) rendered.set(name, null);
|
|
539
|
-
}
|
|
540
|
-
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
541
|
-
if (typeof resolvedValue !== "string" || !secrets.has(resolvedValue)) continue;
|
|
542
|
-
const expression = positioned[name];
|
|
543
|
-
if (typeof expression !== "string") continue;
|
|
544
|
-
if (!isSingleDynamicReferenceToken(expression)) continue;
|
|
545
|
-
const sourceLeaf = sourceParameters[name];
|
|
546
|
-
if (typeof sourceLeaf === "string" && expression !== sourceLeaf) continue;
|
|
547
|
-
if (expression === resolvedValue) continue;
|
|
548
|
-
const seenResolvingTo = plaintextIndexOf(secrets).get(expression);
|
|
549
|
-
if (seenResolvingTo !== void 0 && seenResolvingTo !== resolvedValue) continue;
|
|
550
|
-
if (typeof sourceLeaf === "string" && resolvedPlaintextOf(secrets, expression) !== resolvedValue) continue;
|
|
551
|
-
if (table === void 0) {
|
|
552
|
-
table = /* @__PURE__ */ new Map();
|
|
553
|
-
nestedStackParameterExpressions.set(secrets, table);
|
|
554
|
-
}
|
|
555
|
-
storeAssociation(table, name, expression, resolvedValue);
|
|
556
|
-
}
|
|
557
|
-
const framesByValue = /* @__PURE__ */ new Map();
|
|
558
|
-
const tokensOf = /* @__PURE__ */ new Map();
|
|
559
|
-
const frameSpellings = /* @__PURE__ */ new Map();
|
|
560
|
-
const frameSpellingOf = (name) => {
|
|
561
|
-
if (!frameSpellings.has(name)) frameSpellings.set(name, computeFrameSpelling(name));
|
|
562
|
-
return frameSpellings.get(name);
|
|
563
|
-
};
|
|
564
|
-
const computeFrameSpelling = (name) => {
|
|
565
|
-
const resolvedValue = resolvedParameters[name];
|
|
566
|
-
if (typeof resolvedValue !== "string") return void 0;
|
|
567
|
-
const sourceLeaf = sourceParameters[name];
|
|
568
|
-
if (typeof sourceLeaf === "string") return sourceLeaf;
|
|
569
|
-
if (!isPlainObject(sourceLeaf)) return void 0;
|
|
570
|
-
const written = positioned[name];
|
|
571
|
-
if (typeof written !== "string") return void 0;
|
|
572
|
-
const rendered = intrinsicSkeletonSegments(sourceLeaf)?.map((s) => s === UNKNOWN_PART ? "\0" : s).join("");
|
|
573
|
-
const spans = rendered === void 0 ? [] : dynamicReferenceSpans(rendered);
|
|
574
|
-
if (rendered !== void 0 && spans.length === 1) {
|
|
575
|
-
const [span] = spans;
|
|
576
|
-
const ownToken = rendered.slice(span.start, span.end);
|
|
577
|
-
if (written !== resolvedValue && SPELLED_SECRET_REFERENCE_PREFIXES.some((prefix) => ownToken.startsWith(prefix))) return written;
|
|
578
|
-
}
|
|
579
|
-
const substituted = substitutedSpellingOf(secrets, sourceLeaf, resolvedValue);
|
|
580
|
-
if (substituted === void 0) return void 0;
|
|
581
|
-
return written === resolvedValue || written === substituted ? substituted : void 0;
|
|
582
|
-
};
|
|
583
|
-
const certifiedSpellingOf = (name) => {
|
|
584
|
-
const sourceLeaf = sourceParameters[name];
|
|
585
|
-
if (typeof sourceLeaf === "string") return positioned[name] === sourceLeaf ? sourceLeaf : void 0;
|
|
586
|
-
return frameSpellingOf(name);
|
|
528
|
+
// src/deployment/secret-redaction/nested-stack/refused-parameter-reads.ts
|
|
529
|
+
function attributionRefusedReadsOf(node, secrets) {
|
|
530
|
+
const table = attributionRefusedParameters.get(secrets);
|
|
531
|
+
if (table === void 0 || table.size === 0) return void 0;
|
|
532
|
+
let verdict;
|
|
533
|
+
const note = (name) => {
|
|
534
|
+
const kind = table.get(name);
|
|
535
|
+
if (kind === "masked") verdict = "masked";
|
|
536
|
+
else if (kind === "sub-floor" && verdict === void 0) verdict = "sub-floor";
|
|
587
537
|
};
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
if (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
const frames = framesByValue.get(resolvedValue) ?? /* @__PURE__ */ new Set();
|
|
594
|
-
const unframed = frame === void 0 || resolvedPlaintextOf(secrets, frame.token) !== frame.middle;
|
|
595
|
-
frames.add(unframed ? UNFRAMED_SPELLING : `${frame.prefix.length}:${frame.prefix}${frame.suffix}`);
|
|
596
|
-
framesByValue.set(resolvedValue, frames);
|
|
597
|
-
if (!unframed) {
|
|
598
|
-
const tokens = tokensOf.get(resolvedValue) ?? /* @__PURE__ */ new Set();
|
|
599
|
-
tokens.add(frame.token);
|
|
600
|
-
tokensOf.set(resolvedValue, tokens);
|
|
601
|
-
if (typeof sourceParameters[name] !== "string" && positioned[name] !== spelling) unwrittenValues.add(resolvedValue);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
for (const value of unwrittenValues) if (tokensOf.get(value)?.size !== 1) framesByValue.get(value)?.add(UNFRAMED_SPELLING);
|
|
605
|
-
const rowWithoutParameters = {};
|
|
606
|
-
for (const [key, value] of Object.entries(resolvedProperties)) if (key !== "Parameters") rowWithoutParameters[key] = value;
|
|
607
|
-
const outsideLeaves = wholeStringLeavesOf(rowWithoutParameters);
|
|
608
|
-
const framed = /* @__PURE__ */ new Map();
|
|
609
|
-
const framedByName = [];
|
|
610
|
-
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
611
|
-
if (typeof resolvedValue !== "string") continue;
|
|
612
|
-
const spelling = certifiedSpellingOf(name);
|
|
613
|
-
if (spelling === void 0) continue;
|
|
614
|
-
if (redactForState(resolvedValue, {
|
|
615
|
-
provenance: "value-scan",
|
|
616
|
-
secrets
|
|
617
|
-
}) !== resolvedValue) continue;
|
|
618
|
-
const frame = singleSpanFrame(resolvedValue, spelling);
|
|
619
|
-
if (frame === void 0 || resolvedPlaintextOf(secrets, frame.token) !== frame.middle) continue;
|
|
620
|
-
if (framesByValue.get(resolvedValue)?.size !== 1) continue;
|
|
621
|
-
const isNeedle = resolvedValue.length >= 4;
|
|
622
|
-
const rewrites = (leaf) => leaf === resolvedValue || isNeedle && leaf.includes(resolvedValue);
|
|
623
|
-
let embedded = false;
|
|
624
|
-
for (const leaf of outsideLeaves) if (rewrites(leaf)) {
|
|
625
|
-
embedded = true;
|
|
626
|
-
break;
|
|
538
|
+
const walk = (value, depth) => {
|
|
539
|
+
if (depth > 64 || verdict === "masked") return;
|
|
540
|
+
if (Array.isArray(value)) {
|
|
541
|
+
for (const item of value) walk(item, depth + 1);
|
|
542
|
+
return;
|
|
627
543
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (typeof
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
for (const leaf of wholeStringLeavesOf(other)) if (rewrites(leaf)) {
|
|
635
|
-
embedded = true;
|
|
636
|
-
break;
|
|
544
|
+
if (!isPlainObject(value)) return;
|
|
545
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
546
|
+
if (key === "Ref" && typeof inner === "string") note(inner);
|
|
547
|
+
if (key === "Fn::Sub") {
|
|
548
|
+
const text = typeof inner === "string" ? inner : Array.isArray(inner) ? inner[0] : void 0;
|
|
549
|
+
if (typeof text === "string") for (const match of text.matchAll(/\$\{([^}!][^}]*)\}/g)) note(match[1].split(".")[0]);
|
|
637
550
|
}
|
|
551
|
+
walk(inner, depth + 1);
|
|
638
552
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
spelling,
|
|
643
|
-
resolvedValue
|
|
644
|
-
]);
|
|
645
|
-
if (secrets.get(frame.middle) !== frame.token && tokensOf.get(resolvedValue)?.size !== 1) continue;
|
|
646
|
-
framed.set(resolvedValue, spelling);
|
|
647
|
-
}
|
|
648
|
-
for (const [plaintext, expression] of framed) secrets.set(plaintext, expression);
|
|
649
|
-
for (const [name, expression, plaintext] of framedByName) {
|
|
650
|
-
if (table === void 0) {
|
|
651
|
-
table = /* @__PURE__ */ new Map();
|
|
652
|
-
nestedStackParameterExpressions.set(secrets, table);
|
|
653
|
-
}
|
|
654
|
-
storeAssociation(table, name, expression, plaintext);
|
|
655
|
-
}
|
|
553
|
+
};
|
|
554
|
+
walk(node, 0);
|
|
555
|
+
return verdict;
|
|
656
556
|
}
|
|
657
557
|
|
|
658
558
|
// src/deployment/secret-redaction/physical-name-copies.ts
|
|
@@ -676,1613 +576,2081 @@ function physicalNameSpans(names, value) {
|
|
|
676
576
|
return spans;
|
|
677
577
|
}
|
|
678
578
|
|
|
679
|
-
// src/deployment/secret-redaction/
|
|
680
|
-
function
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
for (const value of fresh) {
|
|
684
|
-
if (freshClass !== void 0 && isNoEchoParameterPlaintext(secrets, value) !== (freshClass === "parameter")) continue;
|
|
685
|
-
if (isMaskOnlyPlaintext(secrets, value) && text.includes(value)) return true;
|
|
686
|
-
}
|
|
687
|
-
return false;
|
|
579
|
+
// src/deployment/secret-redaction/redact-path/json-equality.ts
|
|
580
|
+
function hasPlainPrototype(value) {
|
|
581
|
+
const proto = Object.getPrototypeOf(value);
|
|
582
|
+
return proto === Object.prototype || proto === null;
|
|
688
583
|
}
|
|
689
|
-
function
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
seen.add(node);
|
|
698
|
-
if (Array.isArray(node)) return node.some((item) => walk(item));
|
|
699
|
-
return Object.values(node).some((child) => walk(child));
|
|
700
|
-
};
|
|
701
|
-
return walk(value);
|
|
702
|
-
}
|
|
703
|
-
function freshNoEchoLeafPositions(value, secrets, freshClass) {
|
|
704
|
-
const isFresh = freshNoEchoLeafTest(secrets, freshClass);
|
|
705
|
-
if (isFresh === void 0) return [];
|
|
706
|
-
const leaves = [];
|
|
707
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
708
|
-
const walk = (node, path) => {
|
|
709
|
-
if (typeof node === "string") {
|
|
710
|
-
if (isFresh(node)) leaves.push({
|
|
711
|
-
path,
|
|
712
|
-
plaintext: node
|
|
713
|
-
});
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
if (node === null || typeof node !== "object") return;
|
|
717
|
-
if (ancestors.has(node)) return;
|
|
718
|
-
ancestors.add(node);
|
|
719
|
-
if (Array.isArray(node)) node.forEach((item, index) => walk(item, [...path, index]));
|
|
720
|
-
else for (const [key, child] of Object.entries(node)) walk(child, [...path, key]);
|
|
721
|
-
ancestors.delete(node);
|
|
722
|
-
};
|
|
723
|
-
walk(value, []);
|
|
724
|
-
return leaves;
|
|
725
|
-
}
|
|
726
|
-
function freshNoEchoLeafTest(secrets, freshClass) {
|
|
727
|
-
const all = freshNoEchoValuesOf.get(secrets);
|
|
728
|
-
if (all === void 0 || all.size === 0) return void 0;
|
|
729
|
-
const fresh = freshClass === void 0 ? all : new Set([...all].filter((value) => isNoEchoParameterPlaintext(secrets, value) === (freshClass === "parameter")));
|
|
730
|
-
if (fresh.size === 0) return void 0;
|
|
731
|
-
const needles = containmentNeedlesOf(secrets).filter((needle) => fresh.has(needle));
|
|
732
|
-
return (leaf) => fresh.has(leaf) && isMaskOnlyPlaintext(secrets, leaf) || leaf !== "***" && embedsNeedleOutsideReferences(leaf, needles, secrets);
|
|
733
|
-
}
|
|
734
|
-
function containmentNeedlesOf(secrets) {
|
|
735
|
-
const values = containmentValuesOf.get(secrets);
|
|
736
|
-
if (values === void 0 || values.size === 0) return [];
|
|
737
|
-
const needles = [];
|
|
738
|
-
for (const value of values) if (value.length >= 4 && isMaskOnlyPlaintext(secrets, value)) needles.push(value);
|
|
739
|
-
return needles;
|
|
584
|
+
function isOrdinaryDate(value) {
|
|
585
|
+
if (Object.getPrototypeOf(value) !== Date.prototype) return false;
|
|
586
|
+
try {
|
|
587
|
+
Date.prototype.getTime.call(value);
|
|
588
|
+
} catch {
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
return Reflect.ownKeys(value).length === 0;
|
|
740
592
|
}
|
|
741
|
-
function
|
|
742
|
-
|
|
593
|
+
function deepEqualJsonValue(a, b) {
|
|
594
|
+
if (a === b) return true;
|
|
595
|
+
if (Array.isArray(a)) {
|
|
596
|
+
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
597
|
+
return a.every((item, i) => deepEqualJsonValue(item, b[i]));
|
|
598
|
+
}
|
|
599
|
+
if (isPlainObject(a)) {
|
|
600
|
+
if (!isPlainObject(b)) return false;
|
|
601
|
+
if (!hasPlainPrototype(a) || !hasPlainPrototype(b)) return false;
|
|
602
|
+
const keys = Object.keys(a);
|
|
603
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
604
|
+
return keys.every((k) => Object.hasOwn(b, k) && deepEqualJsonValue(a[k], b[k]));
|
|
605
|
+
}
|
|
606
|
+
return false;
|
|
743
607
|
}
|
|
744
|
-
|
|
745
|
-
|
|
608
|
+
|
|
609
|
+
// src/deployment/secret-redaction/redact-path/template-literal.ts
|
|
610
|
+
function isSourcePlainLiteral(bag, source, rules) {
|
|
611
|
+
return rules.sourceIsTemplate === true && typeof bag === "string" && bag === source && !isDynamicReferenceString(source);
|
|
746
612
|
}
|
|
747
|
-
function
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
if (isStrictlyInsideASpan(spans, at, at + needle.length)) continue;
|
|
754
|
-
names ??= physicalNameSpans(physicalNameCopiesOf.get(secrets), leaf);
|
|
755
|
-
const end = at + needle.length;
|
|
756
|
-
if (names.some((n) => n.start <= at && end <= n.end)) continue;
|
|
757
|
-
found.push({
|
|
758
|
-
start: at,
|
|
759
|
-
end
|
|
760
|
-
});
|
|
761
|
-
if (first) return found;
|
|
613
|
+
function secretRerenderPairs(secrets) {
|
|
614
|
+
const pairs = [];
|
|
615
|
+
for (const [plaintext, expression] of secrets) {
|
|
616
|
+
if (plaintext === "" || expression === "***") continue;
|
|
617
|
+
if (!isSingleDynamicReferenceToken(expression)) continue;
|
|
618
|
+
pairs.push([expression, plaintext]);
|
|
762
619
|
}
|
|
763
|
-
return
|
|
620
|
+
return pairs;
|
|
764
621
|
}
|
|
765
|
-
function
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
if (
|
|
769
|
-
|
|
622
|
+
function rerenderedSourceLiteral(bag, source, secrets, rules) {
|
|
623
|
+
if (typeof bag !== "string" || typeof source !== "string") return void 0;
|
|
624
|
+
if (!isDynamicReferenceString(bag) || isDynamicReferenceString(source)) return void 0;
|
|
625
|
+
if (rules.sourceIsTemplate !== true && secrets.has(source)) return void 0;
|
|
626
|
+
let rendered = bag;
|
|
627
|
+
for (const [expression, plaintext] of secretRerenderPairs(secrets)) rendered = rendered.split(expression).join(plaintext);
|
|
628
|
+
return rendered === source ? source : void 0;
|
|
770
629
|
}
|
|
771
|
-
function
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
if (Array.isArray(
|
|
779
|
-
|
|
780
|
-
const out = node.map((item) => {
|
|
781
|
-
const next = walk(item);
|
|
782
|
-
if (next !== item) changed = true;
|
|
783
|
-
return next;
|
|
784
|
-
});
|
|
785
|
-
return changed ? out : node;
|
|
786
|
-
}
|
|
787
|
-
if (isOrdinaryDate(node)) {
|
|
788
|
-
const persisted = node.toJSON();
|
|
789
|
-
return typeof persisted === "string" && flattens(persisted) ? "***" : node;
|
|
790
|
-
}
|
|
630
|
+
function keepTemplateLiteralLeaves(redacted, raw, template, secrets) {
|
|
631
|
+
if (typeof raw === "string") {
|
|
632
|
+
if (redacted === "***") return redacted;
|
|
633
|
+
if (raw === template && !isDynamicReferenceString(raw)) return raw;
|
|
634
|
+
return rerenderedSourceLiteral(raw, template, secrets, TEMPLATE_SOURCE) ?? redacted;
|
|
635
|
+
}
|
|
636
|
+
if (Array.isArray(raw)) {
|
|
637
|
+
if (!Array.isArray(template) || !Array.isArray(redacted)) return redacted;
|
|
638
|
+
if (redacted.length !== raw.length || template.length !== raw.length) return redacted;
|
|
791
639
|
let out;
|
|
792
|
-
for (
|
|
793
|
-
const
|
|
794
|
-
if (
|
|
795
|
-
out ??= Object.assign(Object.create(null), node);
|
|
796
|
-
out[key] = next;
|
|
640
|
+
for (let i = 0; i < redacted.length; i++) {
|
|
641
|
+
const kept = keepTemplateLiteralLeaves(redacted[i], raw[i], template[i], secrets);
|
|
642
|
+
if (kept !== redacted[i]) (out ??= [...redacted])[i] = kept;
|
|
797
643
|
}
|
|
798
|
-
return out ??
|
|
799
|
-
}
|
|
800
|
-
|
|
644
|
+
return out ?? redacted;
|
|
645
|
+
}
|
|
646
|
+
if (!isPlainRecord(raw) || !isPlainRecord(template) || !isPlainRecord(redacted)) return redacted;
|
|
647
|
+
let out;
|
|
648
|
+
for (const key of Object.keys(redacted)) {
|
|
649
|
+
if (!Object.hasOwn(raw, key) || !Object.hasOwn(template, key)) continue;
|
|
650
|
+
const kept = keepTemplateLiteralLeaves(redacted[key], raw[key], template[key], secrets);
|
|
651
|
+
if (kept === redacted[key]) continue;
|
|
652
|
+
out ??= { ...redacted };
|
|
653
|
+
out[key] = kept;
|
|
654
|
+
}
|
|
655
|
+
return out ?? redacted;
|
|
801
656
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
657
|
+
const TEMPLATE_SOURCE = {
|
|
658
|
+
descendArrays: false,
|
|
659
|
+
trustAnyExpression: false,
|
|
660
|
+
sourceIsSameGeneration: false,
|
|
661
|
+
sourceIsTemplate: true
|
|
662
|
+
};
|
|
663
|
+
function isPlainRecord(value) {
|
|
664
|
+
return isPlainObject(value) && hasPlainPrototype(value);
|
|
806
665
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
666
|
+
|
|
667
|
+
// src/deployment/secret-redaction/resolver-outcomes.ts
|
|
668
|
+
const CONFLICTING = Symbol("cdkd.resolver-outcome.conflicting");
|
|
669
|
+
const takenBranches = /* @__PURE__ */ new WeakMap();
|
|
670
|
+
function recordTakenIfBranch(secrets, source, tookTrueBranch) {
|
|
671
|
+
let taken = takenBranches.get(secrets);
|
|
672
|
+
if (taken === void 0) {
|
|
673
|
+
taken = /* @__PURE__ */ new WeakMap();
|
|
674
|
+
takenBranches.set(secrets, taken);
|
|
675
|
+
}
|
|
676
|
+
const previous = taken.get(source);
|
|
677
|
+
if (previous === void 0) taken.set(source, tookTrueBranch);
|
|
678
|
+
else if (previous !== tookTrueBranch) taken.set(source, CONFLICTING);
|
|
811
679
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
return
|
|
680
|
+
function takenIfBranchOf(secrets, source) {
|
|
681
|
+
const taken = takenBranches.get(secrets)?.get(source);
|
|
682
|
+
return taken === CONFLICTING ? void 0 : taken;
|
|
815
683
|
}
|
|
816
|
-
|
|
817
|
-
|
|
684
|
+
const droppedElements = /* @__PURE__ */ new WeakMap();
|
|
685
|
+
function recordDroppedArrayElements(secrets, source, dropped) {
|
|
686
|
+
let arrays = droppedElements.get(secrets);
|
|
687
|
+
if (arrays === void 0) {
|
|
688
|
+
arrays = /* @__PURE__ */ new WeakMap();
|
|
689
|
+
droppedElements.set(secrets, arrays);
|
|
690
|
+
}
|
|
691
|
+
const previous = arrays.get(source);
|
|
692
|
+
if (previous === void 0) arrays.set(source, [...dropped]);
|
|
693
|
+
else if (previous !== CONFLICTING && (previous.length !== dropped.length || previous.some((index, i) => index !== dropped[i]))) arrays.set(source, CONFLICTING);
|
|
818
694
|
}
|
|
819
|
-
function
|
|
820
|
-
|
|
695
|
+
function droppedArrayElementsOf(secrets, source) {
|
|
696
|
+
const dropped = droppedElements.get(secrets)?.get(source);
|
|
697
|
+
return dropped === CONFLICTING ? void 0 : dropped;
|
|
821
698
|
}
|
|
822
699
|
|
|
823
|
-
// src/deployment/secret-redaction/
|
|
824
|
-
function
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
};
|
|
836
|
-
return visit(value);
|
|
700
|
+
// src/deployment/secret-redaction/redact-path/literal-rendering.ts
|
|
701
|
+
function positionByLiteralRendering(bag, source, secrets, rules, scan) {
|
|
702
|
+
if (rules.sourceIsTemplate !== true || typeof bag !== "string") return void 0;
|
|
703
|
+
if (suspended > 0) return void 0;
|
|
704
|
+
if (!isPlainObject(source)) return void 0;
|
|
705
|
+
visits = 0;
|
|
706
|
+
walking = secrets;
|
|
707
|
+
try {
|
|
708
|
+
return renderLeaf(bag, source, secrets, scan);
|
|
709
|
+
} finally {
|
|
710
|
+
walking = void 0;
|
|
711
|
+
}
|
|
837
712
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
713
|
+
function renderLeaf(bag, source, secrets, scan) {
|
|
714
|
+
const plaintextOf = tokenPlaintexts(secrets);
|
|
715
|
+
const recorded = [...secrets.keys()];
|
|
716
|
+
const copies = [...physicalNameCopiesOf.get(secrets) ?? []];
|
|
717
|
+
const ifArgs = source["Fn::If"];
|
|
718
|
+
if (Object.keys(source).length === 1 && Array.isArray(ifArgs)) {
|
|
719
|
+
if (ifArgs.length !== 3) return void 0;
|
|
720
|
+
const taken = takenIfBranchOf(secrets, source);
|
|
721
|
+
if (taken !== void 0) {
|
|
722
|
+
const branch = taken ? ifArgs[1] : ifArgs[2];
|
|
723
|
+
if (isNoValue(branch)) return void 0;
|
|
724
|
+
const segments = renderSegments(branch, 1);
|
|
725
|
+
return segments === void 0 ? void 0 : placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
|
|
850
726
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
continue;
|
|
727
|
+
const spellings = /* @__PURE__ */ new Set();
|
|
728
|
+
for (const branch of [ifArgs[1], ifArgs[2]]) {
|
|
729
|
+
if (isNoValue(branch)) continue;
|
|
730
|
+
const segments = renderSegments(branch, 1);
|
|
731
|
+
if (segments === void 0 || segments.some((s) => "gap" in s)) return void 0;
|
|
732
|
+
const spelled = placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
|
|
733
|
+
if (spelled !== void 0) spellings.add(spelled);
|
|
854
734
|
}
|
|
855
|
-
|
|
735
|
+
return spellings.size === 1 ? [...spellings][0] : void 0;
|
|
856
736
|
}
|
|
737
|
+
const segments = renderSegments(source, 0);
|
|
738
|
+
if (segments === void 0) return void 0;
|
|
739
|
+
return placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
|
|
857
740
|
}
|
|
858
|
-
function
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
if (
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
return
|
|
741
|
+
function staticTemplateText(node) {
|
|
742
|
+
const outer = walking;
|
|
743
|
+
const outerVisits = visits;
|
|
744
|
+
walking = void 0;
|
|
745
|
+
let segments;
|
|
746
|
+
try {
|
|
747
|
+
segments = renderSegments(node, 0);
|
|
748
|
+
} finally {
|
|
749
|
+
walking = outer;
|
|
750
|
+
visits = outerVisits;
|
|
751
|
+
}
|
|
752
|
+
if (segments === void 0) return void 0;
|
|
753
|
+
let text = "";
|
|
754
|
+
for (const segment of segments) {
|
|
755
|
+
if (!("text" in segment)) return void 0;
|
|
756
|
+
text += segment.text;
|
|
757
|
+
}
|
|
758
|
+
return text;
|
|
876
759
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
760
|
+
let walking;
|
|
761
|
+
let suspended = 0;
|
|
762
|
+
function literalRenderingSuspended() {
|
|
763
|
+
return suspended > 0;
|
|
880
764
|
}
|
|
881
|
-
function
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
if (value === void 0 || text !== void 0 && text !== value) return void 0;
|
|
888
|
-
if (carriesChildOnlyPlaintext(value, childSecrets, reads.parent)) return void 0;
|
|
889
|
-
const spelling = inheritedParameterExpression(reads.parent, name, value);
|
|
890
|
-
if (typeof spelling !== "string") return void 0;
|
|
891
|
-
if (redactForState(spelling, {
|
|
892
|
-
provenance: "value-scan",
|
|
893
|
-
secrets: childSecrets
|
|
894
|
-
}) !== spelling) return void 0;
|
|
895
|
-
return {
|
|
896
|
-
value,
|
|
897
|
-
spelling
|
|
898
|
-
};
|
|
765
|
+
function withoutLiteralRendering(run) {
|
|
766
|
+
suspended++;
|
|
767
|
+
try {
|
|
768
|
+
return run();
|
|
769
|
+
} finally {
|
|
770
|
+
suspended--;
|
|
899
771
|
}
|
|
900
772
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
inheritedParameterReads.set(childSecrets, created);
|
|
912
|
-
return created;
|
|
913
|
-
}
|
|
914
|
-
if (typeof reads === "symbol") return void 0;
|
|
915
|
-
if (reads.parent !== parentSecrets) {
|
|
916
|
-
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
917
|
-
return;
|
|
773
|
+
function templateSegmentsOf(source, secrets) {
|
|
774
|
+
if (suspended > 0) return void 0;
|
|
775
|
+
const outer = walking;
|
|
776
|
+
const outerVisits = visits;
|
|
777
|
+
walking = secrets;
|
|
778
|
+
try {
|
|
779
|
+
return renderSegments(source, 0);
|
|
780
|
+
} finally {
|
|
781
|
+
walking = outer;
|
|
782
|
+
visits = outerVisits;
|
|
918
783
|
}
|
|
919
|
-
return reads;
|
|
920
784
|
}
|
|
921
|
-
function
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
785
|
+
function placeTextPieces(segments, region, plaintextOf = /* @__PURE__ */ new Map()) {
|
|
786
|
+
const anchors = [];
|
|
787
|
+
let leadingGap = false;
|
|
788
|
+
let trailingGap = false;
|
|
789
|
+
let current;
|
|
790
|
+
for (const segment of segments) {
|
|
791
|
+
if ("gap" in segment) {
|
|
792
|
+
if (current !== void 0) {
|
|
793
|
+
anchors.push(current);
|
|
794
|
+
current = void 0;
|
|
795
|
+
} else if (anchors.length === 0) leadingGap = true;
|
|
796
|
+
trailingGap = true;
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
trailingGap = false;
|
|
800
|
+
current ??= {
|
|
801
|
+
rendered: "",
|
|
802
|
+
persisted: ""
|
|
803
|
+
};
|
|
804
|
+
if ("token" in segment) {
|
|
805
|
+
const plaintext = plaintextOf.get(segment.token);
|
|
806
|
+
if (plaintext === void 0) return void 0;
|
|
807
|
+
current.rendered += plaintext;
|
|
808
|
+
current.persisted += segment.token;
|
|
809
|
+
} else {
|
|
810
|
+
current.rendered += segment.text;
|
|
811
|
+
current.persisted += segment.text;
|
|
929
812
|
}
|
|
930
813
|
}
|
|
931
|
-
if (
|
|
932
|
-
|
|
933
|
-
|
|
814
|
+
if (current !== void 0) anchors.push(current);
|
|
815
|
+
if (!leadingGap && !trailingGap && anchors.length <= 1) {
|
|
816
|
+
const only = anchors[0] ?? {
|
|
817
|
+
rendered: "",
|
|
818
|
+
persisted: ""
|
|
819
|
+
};
|
|
820
|
+
if (only.rendered !== region) return void 0;
|
|
821
|
+
return only.persisted === "" ? [] : [{
|
|
822
|
+
text: only.persisted,
|
|
823
|
+
gap: false
|
|
824
|
+
}];
|
|
825
|
+
}
|
|
826
|
+
if (anchors.length === 0) return [{
|
|
827
|
+
text: region,
|
|
828
|
+
gap: true
|
|
829
|
+
}];
|
|
830
|
+
const leftmost = placements(anchors, region, leadingGap, trailingGap, "left");
|
|
831
|
+
const rightmost = placements(anchors, region, leadingGap, trailingGap, "right");
|
|
832
|
+
if (leftmost === void 0 || rightmost === void 0) return void 0;
|
|
833
|
+
if (leftmost.some((at, i) => at !== rightmost[i])) return void 0;
|
|
834
|
+
const out = [];
|
|
835
|
+
let cursor = 0;
|
|
836
|
+
for (let i = 0; i < anchors.length; i++) {
|
|
837
|
+
const at = leftmost[i];
|
|
838
|
+
if (i > 0 || leadingGap) out.push({
|
|
839
|
+
text: region.slice(cursor, at),
|
|
840
|
+
gap: true
|
|
841
|
+
});
|
|
842
|
+
out.push({
|
|
843
|
+
text: anchors[i].persisted,
|
|
844
|
+
gap: false
|
|
845
|
+
});
|
|
846
|
+
cursor = at + anchors[i].rendered.length;
|
|
934
847
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
parameterReadsFor(childSecrets, parentSecrets)?.names.add(parameterName);
|
|
939
|
-
}
|
|
940
|
-
function redactInheritedParameterValue(parentSecrets, parameterName, value) {
|
|
941
|
-
return inheritedParameterExpression(parentSecrets, parameterName, value) ?? redactForState(value, {
|
|
942
|
-
provenance: "value-scan",
|
|
943
|
-
secrets: parentSecrets
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
function positionByInheritedParameter(bag, source, secrets) {
|
|
947
|
-
const keys = Object.keys(source);
|
|
948
|
-
if (keys.length !== 1 || keys[0] !== "Ref") return void 0;
|
|
949
|
-
const name = source["Ref"];
|
|
950
|
-
if (typeof name !== "string") return void 0;
|
|
951
|
-
const reads = inheritedParameterReads.get(secrets);
|
|
952
|
-
if (reads === void 0 || typeof reads === "symbol" || !reads.names.has(name)) return;
|
|
953
|
-
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
954
|
-
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
955
|
-
const answer = redactInheritedParameterValue(reads.parent, name, bag);
|
|
956
|
-
if (!deepEqualJsonValue(redactForState(answer, {
|
|
957
|
-
provenance: "value-scan",
|
|
958
|
-
secrets
|
|
959
|
-
}), answer)) return void 0;
|
|
960
|
-
return answer;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// src/deployment/secret-redaction/nested-stack/pseudo-parameters.ts
|
|
964
|
-
const REREAD_PSEUDO_PARAMETERS = /* @__PURE__ */ new Set([
|
|
965
|
-
"AWS::Region",
|
|
966
|
-
"AWS::Partition",
|
|
967
|
-
"AWS::URLSuffix",
|
|
968
|
-
"AWS::AccountId"
|
|
969
|
-
]);
|
|
970
|
-
function templateRereadsAccountId(template) {
|
|
971
|
-
if (template === void 0) return false;
|
|
972
|
-
const resources = template.Resources !== null && typeof template.Resources === "object" ? template.Resources : void 0;
|
|
973
|
-
const cached = resources && accountRereadVerdicts.get(resources);
|
|
974
|
-
if (cached !== void 0 && cached.outputs === template.Outputs) return cached.verdict;
|
|
975
|
-
const parts = resources ? Object.values(resources) : [];
|
|
976
|
-
if (template.Outputs !== void 0) parts.push(template.Outputs);
|
|
977
|
-
const verdict = parts.some(partRereadsAccountId);
|
|
978
|
-
if (resources) accountRereadVerdicts.set(resources, {
|
|
979
|
-
outputs: template.Outputs,
|
|
980
|
-
verdict
|
|
848
|
+
if (trailingGap) out.push({
|
|
849
|
+
text: region.slice(cursor),
|
|
850
|
+
gap: true
|
|
981
851
|
});
|
|
982
|
-
return
|
|
852
|
+
else if (cursor !== region.length) return void 0;
|
|
853
|
+
return out;
|
|
983
854
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
let
|
|
987
|
-
let
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
855
|
+
function placeAnchors(segments, plaintextOf, bag, scan, plaintexts, physicalNameCopies) {
|
|
856
|
+
const anchors = [];
|
|
857
|
+
let leadingGap = false;
|
|
858
|
+
let trailingGap = false;
|
|
859
|
+
let current;
|
|
860
|
+
for (const segment of segments) {
|
|
861
|
+
if ("gap" in segment) {
|
|
862
|
+
if (current !== void 0) {
|
|
863
|
+
anchors.push(current);
|
|
864
|
+
current = void 0;
|
|
865
|
+
} else if (anchors.length === 0) leadingGap = true;
|
|
866
|
+
trailingGap = true;
|
|
993
867
|
continue;
|
|
994
868
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
const inheritedPseudoParameters = /* @__PURE__ */ new WeakMap();
|
|
1009
|
-
const POISONED_PSEUDO_PARAMETERS = Symbol("cdkd.inherited-pseudo-parameters.poisoned");
|
|
1010
|
-
function recordInheritedPseudoParameters(inheritedSecrets, values) {
|
|
1011
|
-
let table = inheritedPseudoParameters.get(inheritedSecrets);
|
|
1012
|
-
if (table === POISONED_PSEUDO_PARAMETERS) return;
|
|
1013
|
-
if (table === void 0) {
|
|
1014
|
-
table = /* @__PURE__ */ new Map();
|
|
1015
|
-
inheritedPseudoParameters.set(inheritedSecrets, table);
|
|
1016
|
-
}
|
|
1017
|
-
for (const [name, value] of values) {
|
|
1018
|
-
if (!REREAD_PSEUDO_PARAMETERS.has(name) || typeof value !== "string") continue;
|
|
1019
|
-
const known = table.get(name);
|
|
1020
|
-
if (known !== void 0 && known !== value) {
|
|
1021
|
-
inheritedPseudoParameters.set(inheritedSecrets, POISONED_PSEUDO_PARAMETERS);
|
|
1022
|
-
return;
|
|
869
|
+
trailingGap = false;
|
|
870
|
+
current ??= {
|
|
871
|
+
rendered: "",
|
|
872
|
+
persisted: ""
|
|
873
|
+
};
|
|
874
|
+
if ("text" in segment) {
|
|
875
|
+
current.rendered += segment.text;
|
|
876
|
+
current.persisted += segment.text;
|
|
877
|
+
} else {
|
|
878
|
+
const plaintext = plaintextOf.get(segment.token);
|
|
879
|
+
if (plaintext === void 0) return void 0;
|
|
880
|
+
current.rendered += plaintext;
|
|
881
|
+
current.persisted += segment.token;
|
|
1023
882
|
}
|
|
1024
|
-
table.set(name, value);
|
|
1025
883
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
return typeof bound === "string" ? bound : void 0;
|
|
1034
|
-
}
|
|
1035
|
-
function inheritedPseudoSpan(childSecrets, key) {
|
|
1036
|
-
const reads = inheritedParameterReads.get(childSecrets);
|
|
1037
|
-
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
1038
|
-
for (const name of REREAD_PSEUDO_PARAMETERS) if (crossStackSourceKey({ Ref: name }) === key) return inheritedPseudoValue(reads.parent, name);
|
|
1039
|
-
}
|
|
1040
|
-
const REREAD_TRIGGERS = /* @__PURE__ */ new Set([
|
|
1041
|
-
"Fn::Select",
|
|
1042
|
-
"Fn::Split",
|
|
1043
|
-
"Fn::If"
|
|
1044
|
-
]);
|
|
1045
|
-
|
|
1046
|
-
// src/deployment/secret-redaction/resolver-outcomes.ts
|
|
1047
|
-
const CONFLICTING = Symbol("cdkd.resolver-outcome.conflicting");
|
|
1048
|
-
const takenBranches = /* @__PURE__ */ new WeakMap();
|
|
1049
|
-
function recordTakenIfBranch(secrets, source, tookTrueBranch) {
|
|
1050
|
-
let taken = takenBranches.get(secrets);
|
|
1051
|
-
if (taken === void 0) {
|
|
1052
|
-
taken = /* @__PURE__ */ new WeakMap();
|
|
1053
|
-
takenBranches.set(secrets, taken);
|
|
884
|
+
if (current !== void 0) anchors.push(current);
|
|
885
|
+
if (!leadingGap && !trailingGap && anchors.length <= 1) {
|
|
886
|
+
const only = anchors[0] ?? {
|
|
887
|
+
rendered: "",
|
|
888
|
+
persisted: ""
|
|
889
|
+
};
|
|
890
|
+
return only.rendered === bag ? only.persisted : void 0;
|
|
1054
891
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
892
|
+
if (!anchors.some((a) => a.rendered.length > 0)) return void 0;
|
|
893
|
+
const leftmost = placements(anchors, bag, leadingGap, trailingGap, "left");
|
|
894
|
+
const rightmost = placements(anchors, bag, leadingGap, trailingGap, "right");
|
|
895
|
+
if (leftmost === void 0 || rightmost === void 0) return void 0;
|
|
896
|
+
if (leftmost.some((at, i) => at !== rightmost[i])) return void 0;
|
|
897
|
+
const gaps = [];
|
|
898
|
+
const gapRanges = [];
|
|
899
|
+
let persisted = "";
|
|
900
|
+
let cursor = 0;
|
|
901
|
+
for (let i = 0; i < anchors.length; i++) {
|
|
902
|
+
const at = leftmost[i];
|
|
903
|
+
if (i > 0 || leadingGap) {
|
|
904
|
+
const gap = bag.slice(cursor, at);
|
|
905
|
+
gaps.push(gap);
|
|
906
|
+
gapRanges.push([cursor, at]);
|
|
907
|
+
persisted += gap;
|
|
908
|
+
} else if (at !== 0) return;
|
|
909
|
+
persisted += anchors[i].persisted;
|
|
910
|
+
cursor = at + anchors[i].rendered.length;
|
|
1069
911
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
912
|
+
if (trailingGap) {
|
|
913
|
+
const gap = bag.slice(cursor);
|
|
914
|
+
gaps.push(gap);
|
|
915
|
+
gapRanges.push([cursor, bag.length]);
|
|
916
|
+
persisted += gap;
|
|
917
|
+
} else if (cursor !== bag.length) return;
|
|
918
|
+
if (gaps.some((gap) => scan(gap) !== gap)) return void 0;
|
|
919
|
+
const copyRanges = [];
|
|
920
|
+
for (const copy of physicalNameCopies) {
|
|
921
|
+
if (copy === "") continue;
|
|
922
|
+
for (let at = bag.indexOf(copy); at !== -1; at = bag.indexOf(copy, at + 1)) copyRanges.push([at, at + copy.length]);
|
|
923
|
+
}
|
|
924
|
+
for (const plaintext of plaintexts) {
|
|
925
|
+
if (plaintext === "") continue;
|
|
926
|
+
for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
|
|
927
|
+
const end = at + plaintext.length;
|
|
928
|
+
if (!gapRanges.some(([from, to]) => at < to && end > from)) continue;
|
|
929
|
+
if (!copyRanges.some(([from, to]) => at >= from && end <= to && gapRanges.some(([g0, g1]) => from >= g0 && to <= g1))) return void 0;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return persisted;
|
|
1077
933
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
const at = text.indexOf(delimiter, from);
|
|
1095
|
-
if (at === -1) break;
|
|
1096
|
-
const end = at + delimiter.length;
|
|
1097
|
-
const token = spans.find((span) => span.start < end && at < span.end);
|
|
1098
|
-
if (token !== void 0) {
|
|
1099
|
-
from = token.end;
|
|
1100
|
-
continue;
|
|
934
|
+
function placements(anchors, bag, leadingGap, trailingGap, side) {
|
|
935
|
+
const out = new Array(anchors.length);
|
|
936
|
+
if (side === "left") {
|
|
937
|
+
let cursor = 0;
|
|
938
|
+
for (let i = 0; i < anchors.length; i++) {
|
|
939
|
+
const text = anchors[i].rendered;
|
|
940
|
+
const pinnedStart = i === 0 && !leadingGap;
|
|
941
|
+
const pinnedEnd = i === anchors.length - 1 && !trailingGap;
|
|
942
|
+
let at;
|
|
943
|
+
if (pinnedStart) at = 0;
|
|
944
|
+
else if (pinnedEnd) at = bag.length - text.length;
|
|
945
|
+
else at = bag.indexOf(text, cursor);
|
|
946
|
+
if (at < cursor || bag.slice(at, at + text.length) !== text) return void 0;
|
|
947
|
+
if (pinnedEnd && at + text.length !== bag.length) return void 0;
|
|
948
|
+
out[i] = at;
|
|
949
|
+
cursor = at + text.length;
|
|
1101
950
|
}
|
|
1102
|
-
|
|
1103
|
-
cursor = end;
|
|
1104
|
-
from = end;
|
|
951
|
+
return out;
|
|
1105
952
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
953
|
+
let limit = bag.length;
|
|
954
|
+
for (let i = anchors.length - 1; i >= 0; i--) {
|
|
955
|
+
const text = anchors[i].rendered;
|
|
956
|
+
const pinnedStart = i === 0 && !leadingGap;
|
|
957
|
+
const pinnedEnd = i === anchors.length - 1 && !trailingGap;
|
|
958
|
+
let at;
|
|
959
|
+
if (pinnedEnd) at = bag.length - text.length;
|
|
960
|
+
else if (pinnedStart) at = 0;
|
|
961
|
+
else at = limit - text.length < 0 ? -1 : bag.lastIndexOf(text, limit - text.length);
|
|
962
|
+
if (at < 0 || at + text.length > limit || bag.slice(at, at + text.length) !== text) return;
|
|
963
|
+
if (pinnedStart && at !== 0) return void 0;
|
|
964
|
+
out[i] = at;
|
|
965
|
+
limit = at;
|
|
966
|
+
}
|
|
967
|
+
return out;
|
|
1108
968
|
}
|
|
1109
|
-
function
|
|
1110
|
-
return
|
|
969
|
+
function isNoValue(node) {
|
|
970
|
+
return isPlainObject(node) && Object.keys(node).length === 1 && node["Ref"] === "AWS::NoValue";
|
|
1111
971
|
}
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
972
|
+
const MAX_DEPTH = 16;
|
|
973
|
+
const GAP = [{ gap: true }];
|
|
974
|
+
const MAX_SEGMENTS = 512;
|
|
975
|
+
const MAX_VISITS = 4096;
|
|
976
|
+
let visits = 0;
|
|
977
|
+
function renderSegments(node, depth) {
|
|
978
|
+
if (depth === 0) visits = 0;
|
|
979
|
+
if (++visits > MAX_VISITS) return void 0;
|
|
980
|
+
if (depth > MAX_DEPTH) return void 0;
|
|
981
|
+
if (typeof node === "string") return stringSegments(node);
|
|
982
|
+
if (typeof node === "number" || typeof node === "boolean") return [{ text: String(node) }];
|
|
983
|
+
if (!isPlainObject(node) || Object.keys(node).length !== 1) return GAP;
|
|
984
|
+
const [key] = Object.keys(node);
|
|
985
|
+
const args = node[key];
|
|
986
|
+
if (key === "Fn::Join") {
|
|
987
|
+
if (!Array.isArray(args) || args.length !== 2) return GAP;
|
|
988
|
+
const [delimiter, list] = args;
|
|
989
|
+
if (typeof delimiter !== "string" || !Array.isArray(list)) return GAP;
|
|
990
|
+
const glue = stringSegments(delimiter);
|
|
991
|
+
if (glue === void 0) return void 0;
|
|
1118
992
|
const out = [];
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
if (
|
|
1122
|
-
|
|
993
|
+
const parts = list;
|
|
994
|
+
for (let i = 0; i < parts.length; i++) {
|
|
995
|
+
if (i > 0) out.push(...glue);
|
|
996
|
+
const part = renderSegments(parts[i], depth + 1);
|
|
997
|
+
if (part === void 0) return void 0;
|
|
998
|
+
out.push(...part);
|
|
999
|
+
if (out.length > MAX_SEGMENTS) return void 0;
|
|
1123
1000
|
}
|
|
1124
|
-
return
|
|
1001
|
+
return out;
|
|
1125
1002
|
}
|
|
1126
|
-
if (
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
return
|
|
1003
|
+
if (key === "Fn::Sub") {
|
|
1004
|
+
if (typeof args === "string") return subSegments(args, {}, depth);
|
|
1005
|
+
if (Array.isArray(args) && args.length === 2 && typeof args[0] === "string") {
|
|
1006
|
+
const variables = args[1];
|
|
1007
|
+
if (!isPlainObject(variables)) return GAP;
|
|
1008
|
+
return subSegments(args[0], variables, depth);
|
|
1009
|
+
}
|
|
1010
|
+
return GAP;
|
|
1134
1011
|
}
|
|
1135
1012
|
if (key === "Fn::If") {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
return
|
|
1013
|
+
const taken = walking === void 0 ? void 0 : takenIfBranchOf(walking, node);
|
|
1014
|
+
if (taken === void 0 || !Array.isArray(args) || args.length !== 3) return GAP;
|
|
1015
|
+
const branch = taken ? args[1] : args[2];
|
|
1016
|
+
return isNoValue(branch) ? GAP : renderSegments(branch, depth + 1);
|
|
1140
1017
|
}
|
|
1141
|
-
if (key === "Fn::Sub") return evaluatePureSub(args, bind, pseudo, evaluate);
|
|
1142
|
-
if (!Array.isArray(args) || args.length !== 2) return void 0;
|
|
1143
1018
|
if (key === "Fn::Select") {
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
return { value: list.value[position] };
|
|
1150
|
-
}
|
|
1151
|
-
const delimiter = args[0];
|
|
1152
|
-
if (typeof delimiter !== "string") return void 0;
|
|
1153
|
-
if (key === "Fn::Split") {
|
|
1154
|
-
const value = evaluate(args[1]);
|
|
1155
|
-
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
1156
|
-
return { value: split(value.value, delimiter) };
|
|
1157
|
-
}
|
|
1158
|
-
if (key === "Fn::Join") {
|
|
1159
|
-
const parts = evaluate(args[1]);
|
|
1160
|
-
if (parts === void 0 || !Array.isArray(parts.value)) return void 0;
|
|
1161
|
-
if (!parts.value.every((part) => typeof part === "string")) return void 0;
|
|
1162
|
-
return { value: parts.value.join(delimiter) };
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
function evaluatePureSub(args, bind, pseudo, evaluate) {
|
|
1166
|
-
const [text, variables] = typeof args === "string" ? [args, {}] : Array.isArray(args) && args.length === 2 ? [args[0], args[1]] : [void 0, void 0];
|
|
1167
|
-
if (typeof text !== "string" || text.includes("{{resolve:") || !isPlainObject(variables)) return;
|
|
1168
|
-
const bound = /* @__PURE__ */ new Map();
|
|
1169
|
-
for (const [name, variable] of Object.entries(variables)) {
|
|
1170
|
-
const evaluated = evaluate(variable);
|
|
1171
|
-
if (evaluated === void 0 || typeof evaluated.value !== "string") return void 0;
|
|
1172
|
-
bound.set(name, evaluated.value);
|
|
1173
|
-
}
|
|
1174
|
-
let out = "";
|
|
1175
|
-
let cursor = 0;
|
|
1176
|
-
for (const match of text.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
1177
|
-
const name = match[2] ?? "";
|
|
1178
|
-
let replacement;
|
|
1179
|
-
if (match[1] === "!") replacement = `\${${name}}`;
|
|
1180
|
-
else if (name === "") replacement = match[0];
|
|
1181
|
-
else if (bound.has(name)) replacement = bound.get(name);
|
|
1182
|
-
else {
|
|
1183
|
-
if (name.includes(".")) return void 0;
|
|
1184
|
-
const value = bindReadName(name, bind, pseudo);
|
|
1185
|
-
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
1186
|
-
replacement = value.value;
|
|
1187
|
-
}
|
|
1188
|
-
out += text.slice(cursor, match.index) + replacement;
|
|
1189
|
-
cursor = match.index + match[0].length;
|
|
1019
|
+
if (!Array.isArray(args) || args.length !== 2) return GAP;
|
|
1020
|
+
const index = typeof args[0] === "number" ? args[0] : typeof args[0] === "string" && /^\d+$/.test(args[0]) ? Number(args[0]) : void 0;
|
|
1021
|
+
const list = staticList(args[1]);
|
|
1022
|
+
if (index === void 0 || list === void 0 || index >= list.length) return GAP;
|
|
1023
|
+
return renderSegments(list[index], depth + 1);
|
|
1190
1024
|
}
|
|
1191
|
-
return
|
|
1025
|
+
return GAP;
|
|
1192
1026
|
}
|
|
1193
|
-
function
|
|
1194
|
-
if (
|
|
1195
|
-
|
|
1027
|
+
function staticList(node) {
|
|
1028
|
+
if (Array.isArray(node)) return node;
|
|
1029
|
+
if (!isPlainObject(node) || Object.keys(node).length !== 1) return void 0;
|
|
1030
|
+
const split = node["Fn::Split"];
|
|
1031
|
+
if (!Array.isArray(split) || split.length !== 2) return void 0;
|
|
1032
|
+
const [delimiter, text] = split;
|
|
1033
|
+
if (typeof delimiter !== "string" || delimiter === "" || typeof text !== "string") return void 0;
|
|
1034
|
+
if (text.includes("{{resolve:")) return void 0;
|
|
1035
|
+
return text.split(delimiter);
|
|
1196
1036
|
}
|
|
1197
|
-
function
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1037
|
+
function subSegments(text, variables, depth) {
|
|
1038
|
+
const out = [];
|
|
1039
|
+
let at = 0;
|
|
1040
|
+
for (const match of text.matchAll(/\$\{([^}]*)\}/g)) {
|
|
1041
|
+
const literal = stringSegments(text.slice(at, match.index));
|
|
1042
|
+
if (literal === void 0) return void 0;
|
|
1043
|
+
out.push(...literal);
|
|
1044
|
+
const name = match[1];
|
|
1045
|
+
if (name.startsWith("!")) out.push({ text: `\${${name.slice(1)}}` });
|
|
1046
|
+
else if (Object.hasOwn(variables, name)) {
|
|
1047
|
+
const part = renderSegments(variables[name], depth + 1);
|
|
1048
|
+
if (part === void 0) return void 0;
|
|
1049
|
+
out.push(...part);
|
|
1050
|
+
if (out.length > MAX_SEGMENTS) return void 0;
|
|
1051
|
+
} else out.push({ gap: true });
|
|
1052
|
+
at = match.index + match[0].length;
|
|
1205
1053
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
if (Array.isArray(node)) return node.some((element) => holdsRereadTrigger(element, depth + 1));
|
|
1211
|
-
if (!isPlainObject(node)) return false;
|
|
1212
|
-
return Object.entries(node).some(([key, child]) => REREAD_TRIGGERS.has(key) || holdsRereadTrigger(child, depth + 1));
|
|
1054
|
+
const rest = stringSegments(text.slice(at));
|
|
1055
|
+
if (rest === void 0) return void 0;
|
|
1056
|
+
out.push(...rest);
|
|
1057
|
+
return out;
|
|
1213
1058
|
}
|
|
1214
|
-
function
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1059
|
+
function stringSegments(value) {
|
|
1060
|
+
const out = [];
|
|
1061
|
+
let at = 0;
|
|
1062
|
+
for (const span of dynamicReferenceSpans(value)) {
|
|
1063
|
+
const text = value.slice(at, span.start);
|
|
1064
|
+
if (text.includes("{{resolve:")) return void 0;
|
|
1065
|
+
if (text !== "") out.push({ text });
|
|
1066
|
+
out.push({ token: value.slice(span.start, span.end) });
|
|
1067
|
+
at = span.end;
|
|
1221
1068
|
}
|
|
1222
|
-
|
|
1223
|
-
return
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
const REREAD_PARAMETER_FREE = Symbol("cdkd.reread.parameter-free");
|
|
1227
|
-
function diffSideReading(bind, parentSecrets) {
|
|
1228
|
-
return {
|
|
1229
|
-
bind: (name) => {
|
|
1230
|
-
const bound = bind(name);
|
|
1231
|
-
return bound && { value: redactInheritedParameterValue(parentSecrets, name, bound.value) };
|
|
1232
|
-
},
|
|
1233
|
-
split: (text, delimiter) => splitOutsideDynamicReferences(text, delimiter, (token) => standsForInheritedSecret(parentSecrets, token))
|
|
1234
|
-
};
|
|
1069
|
+
const rest = value.slice(at);
|
|
1070
|
+
if (rest.includes("{{resolve:")) return void 0;
|
|
1071
|
+
if (rest !== "") out.push({ text: rest });
|
|
1072
|
+
return out;
|
|
1235
1073
|
}
|
|
1236
|
-
function
|
|
1237
|
-
const
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
return
|
|
1246
|
-
resolved: resolved.value,
|
|
1247
|
-
redacted: redacted.value
|
|
1248
|
-
};
|
|
1074
|
+
function tokenPlaintexts(secrets) {
|
|
1075
|
+
const out = /* @__PURE__ */ new Map();
|
|
1076
|
+
const ambiguous = /* @__PURE__ */ new Set();
|
|
1077
|
+
for (const [token, plaintext] of secretRerenderPairs(secrets)) {
|
|
1078
|
+
const known = out.get(token);
|
|
1079
|
+
if (known !== void 0 && known !== plaintext) ambiguous.add(token);
|
|
1080
|
+
else out.set(token, plaintext);
|
|
1081
|
+
}
|
|
1082
|
+
for (const token of ambiguous) out.delete(token);
|
|
1083
|
+
return out;
|
|
1249
1084
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
if (
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1085
|
+
|
|
1086
|
+
// src/deployment/secret-redaction/redact-path/substitution-spans.ts
|
|
1087
|
+
function substitutionSpans(resolution, bag) {
|
|
1088
|
+
if (!resolution.complete || resolution.output !== bag) return void 0;
|
|
1089
|
+
const valueOf = /* @__PURE__ */ new Map();
|
|
1090
|
+
for (const { token, value, secret } of resolution.substitutions) {
|
|
1091
|
+
const known = valueOf.get(token);
|
|
1092
|
+
if (known === void 0) valueOf.set(token, {
|
|
1093
|
+
value,
|
|
1094
|
+
secret
|
|
1095
|
+
});
|
|
1096
|
+
else if (known !== null && (known.value !== value || known.secret !== secret)) valueOf.set(token, null);
|
|
1262
1097
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1098
|
+
const spans = [];
|
|
1099
|
+
let rendered = "";
|
|
1100
|
+
let cursor = 0;
|
|
1101
|
+
for (const span of dynamicReferenceSpans(resolution.input)) {
|
|
1102
|
+
const token = resolution.input.slice(span.start, span.end);
|
|
1103
|
+
const answer = valueOf.get(token);
|
|
1104
|
+
if (answer === void 0 || answer === null) return void 0;
|
|
1105
|
+
rendered += resolution.input.slice(cursor, span.start);
|
|
1106
|
+
spans.push({
|
|
1107
|
+
start: rendered.length,
|
|
1108
|
+
end: rendered.length + answer.value.length,
|
|
1109
|
+
token,
|
|
1110
|
+
secret: answer.secret
|
|
1111
|
+
});
|
|
1112
|
+
rendered += answer.value;
|
|
1113
|
+
cursor = span.end;
|
|
1268
1114
|
}
|
|
1269
|
-
|
|
1115
|
+
rendered += resolution.input.slice(cursor);
|
|
1116
|
+
return rendered === bag ? spans : void 0;
|
|
1270
1117
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
if (!
|
|
1275
|
-
if (
|
|
1276
|
-
const
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
let unbound = false;
|
|
1281
|
-
const tracked = (name) => {
|
|
1282
|
-
const bound = bind(name);
|
|
1283
|
-
if (bound === void 0 && untakenWhenUnbound(name)) unbound = true;
|
|
1284
|
-
return bound;
|
|
1285
|
-
};
|
|
1286
|
-
const reread = rereadUnder(source, tracked, parentSecrets, choose);
|
|
1287
|
-
if (unbound) out.push(REREAD_UNBOUND);
|
|
1288
|
-
else if (reread !== void 0) out.push(reread);
|
|
1289
|
-
else if (parameterFree !== void 0 && !namesParameterOnBranches(source, choose, parameterFree)) out.push(REREAD_PARAMETER_FREE);
|
|
1290
|
-
else out.push(void 0);
|
|
1118
|
+
const TAINTED_WITHOUT_SPAN = Symbol("tainted-without-span");
|
|
1119
|
+
function positionBySubstitutionSpans(bag, source, secrets, rules, scan) {
|
|
1120
|
+
if (rules.sourceIsTemplate !== true || typeof bag !== "string") return void 0;
|
|
1121
|
+
if (!isPlainObject(source)) return void 0;
|
|
1122
|
+
if (literalRenderingSuspended()) return void 0;
|
|
1123
|
+
const plaintextOf = /* @__PURE__ */ new Map();
|
|
1124
|
+
for (const token of resolvedExpressionsOf(secrets)) {
|
|
1125
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
1126
|
+
if (plaintext !== void 0 && plaintext !== "") plaintextOf.set(token, plaintext);
|
|
1291
1127
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1297
|
-
|
|
1128
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
1129
|
+
for (const token of referencesConsumedBy(secrets, source)) if (plaintextOf.has(token)) consumed.add(token);
|
|
1130
|
+
const tainted = [...consumed].some((t) => bag.includes(plaintextOf.get(t)));
|
|
1131
|
+
const resolution = intrinsicLeafResolutionOf(secrets, source);
|
|
1132
|
+
const spans = resolution === void 0 ? void 0 : substitutionSpans(resolution, bag);
|
|
1133
|
+
if (spans === void 0 || !spans.some((span) => span.secret)) return tainted ? TAINTED_WITHOUT_SPAN : void 0;
|
|
1134
|
+
const segments = templateSegmentsOf(source, secrets) ?? [{ gap: true }];
|
|
1135
|
+
const regions = [[]];
|
|
1136
|
+
let pinned = 0;
|
|
1137
|
+
for (const segment of segments) if ("token" in segment && pinned < spans.length && segment.token === spans[pinned].token) {
|
|
1138
|
+
regions.push([]);
|
|
1139
|
+
pinned++;
|
|
1140
|
+
} else {
|
|
1141
|
+
if ("token" in segment && consumed.has(segment.token)) return "***";
|
|
1142
|
+
regions[regions.length - 1].push(segment);
|
|
1143
|
+
}
|
|
1144
|
+
const aligned = pinned === spans.length;
|
|
1145
|
+
const copies = [...physicalNameCopiesOf.get(secrets) ?? []].filter((c) => c !== "");
|
|
1146
|
+
let persisted = "";
|
|
1147
|
+
let cursor = 0;
|
|
1148
|
+
for (let i = 0; i <= spans.length; i++) {
|
|
1149
|
+
const end = i < spans.length ? spans[i].start : bag.length;
|
|
1150
|
+
const region = bag.slice(cursor, end);
|
|
1151
|
+
const pieces = aligned ? placeTextPieces(regions[i], region, plaintextOf) : void 0;
|
|
1152
|
+
for (const piece of pieces ?? [{
|
|
1153
|
+
text: region,
|
|
1154
|
+
gap: true
|
|
1155
|
+
}]) {
|
|
1156
|
+
if (!piece.gap) {
|
|
1157
|
+
persisted += piece.text;
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
const answer = redactGap(piece.text, secrets, copies, scan);
|
|
1161
|
+
if (answer === "mask") return "***";
|
|
1162
|
+
persisted += answer;
|
|
1163
|
+
}
|
|
1164
|
+
if (i < spans.length) {
|
|
1165
|
+
const span = spans[i];
|
|
1166
|
+
if (span.secret) persisted += span.token;
|
|
1167
|
+
else {
|
|
1168
|
+
const answer = redactGap(bag.slice(span.start, span.end), secrets, copies, scan);
|
|
1169
|
+
if (answer === "mask") return "***";
|
|
1170
|
+
persisted += answer;
|
|
1171
|
+
}
|
|
1172
|
+
cursor = span.end;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return persisted;
|
|
1298
1176
|
}
|
|
1299
|
-
function
|
|
1300
|
-
|
|
1177
|
+
function redactGap(gap, secrets, copies, scan) {
|
|
1178
|
+
for (const plaintext of secrets.keys()) if (plaintext !== "" && exposedAt(gap, plaintext, copies).length > 0) return "mask";
|
|
1179
|
+
const scanned = scan(gap);
|
|
1180
|
+
return typeof scanned === "string" && scanned === gap ? gap : "mask";
|
|
1301
1181
|
}
|
|
1302
|
-
function
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
if (!unrecorded) {
|
|
1316
|
-
if (recorded === void 0 || recorded === REREAD_NO_VALUE || !deepEqualJsonValue(recorded.resolved, bag)) return;
|
|
1317
|
-
answer = recorded.redacted;
|
|
1318
|
-
} else {
|
|
1319
|
-
const declared = reads.declared;
|
|
1320
|
-
const assignments = rereadAssignments(source, bind, reads.parent, (name) => declared?.has(name) === true);
|
|
1321
|
-
if (assignments === void 0 || assignments.includes(void 0)) return void 0;
|
|
1322
|
-
const matching = assignments.filter((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE && deepEqualJsonValue(entry.resolved, bag));
|
|
1323
|
-
if (matching.length === 0 || ambiguousRereads(matching)) return void 0;
|
|
1324
|
-
answer = matching[0].redacted;
|
|
1182
|
+
function exposedAt(text, plaintext, copies) {
|
|
1183
|
+
const tokens = dynamicReferenceSpans(text).map((s) => [s.start, s.end]);
|
|
1184
|
+
const copyRanges = [];
|
|
1185
|
+
for (const copy of copies) for (let at = text.indexOf(copy); at !== -1; at = text.indexOf(copy, at + 1)) copyRanges.push([at, at + copy.length]);
|
|
1186
|
+
const out = [];
|
|
1187
|
+
for (let at = text.indexOf(plaintext); at !== -1;) {
|
|
1188
|
+
const end = at + plaintext.length;
|
|
1189
|
+
if (tokens.some(([from, to]) => at < to && end > from) || copyRanges.some(([from, to]) => at >= from && end <= to)) {
|
|
1190
|
+
at = text.indexOf(plaintext, at + 1);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
out.push(at);
|
|
1194
|
+
at = text.indexOf(plaintext, end);
|
|
1325
1195
|
}
|
|
1326
|
-
|
|
1327
|
-
if (!deepEqualJsonValue(redactForState(answer, {
|
|
1328
|
-
provenance: "value-scan",
|
|
1329
|
-
secrets
|
|
1330
|
-
}), answer)) return void 0;
|
|
1331
|
-
return answer;
|
|
1196
|
+
return out;
|
|
1332
1197
|
}
|
|
1333
1198
|
|
|
1334
|
-
// src/deployment/secret-redaction/
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1199
|
+
// src/deployment/secret-redaction/nested-stack/row-tag-spellings.ts
|
|
1200
|
+
const rowTagSpellings = /* @__PURE__ */ new WeakMap();
|
|
1201
|
+
function recordNestedStackRowTagSpellings(secrets, resourceType, resolvedProperties, sourceProperties) {
|
|
1202
|
+
if (resourceType !== "AWS::CloudFormation::Stack") return;
|
|
1203
|
+
if (!isPlainObject(resolvedProperties) || !isPlainObject(sourceProperties)) return;
|
|
1204
|
+
if (!Object.hasOwn(resolvedProperties, "Tags") || !Object.hasOwn(sourceProperties, "Tags")) return;
|
|
1205
|
+
const resolvedTags = resolvedProperties["Tags"];
|
|
1206
|
+
const sourceTags = sourceProperties["Tags"];
|
|
1207
|
+
if (!Array.isArray(resolvedTags) || !Array.isArray(sourceTags)) return;
|
|
1208
|
+
const sourceByKey = /* @__PURE__ */ new Map();
|
|
1209
|
+
const repeated = /* @__PURE__ */ new Set();
|
|
1210
|
+
for (const item of sourceTags) {
|
|
1211
|
+
if (!isPlainObject(item)) return;
|
|
1212
|
+
const key = item["Key"];
|
|
1213
|
+
if (typeof key !== "string") return;
|
|
1214
|
+
if (sourceByKey.has(key)) repeated.add(key);
|
|
1215
|
+
sourceByKey.set(key, item["Value"]);
|
|
1216
|
+
}
|
|
1217
|
+
const table = /* @__PURE__ */ new Map();
|
|
1218
|
+
for (const item of resolvedTags) {
|
|
1219
|
+
if (!isPlainObject(item)) continue;
|
|
1220
|
+
const key = item["Key"];
|
|
1221
|
+
const value = item["Value"];
|
|
1222
|
+
if (typeof key !== "string" || typeof value !== "string" || !sourceByKey.has(key)) continue;
|
|
1223
|
+
if (repeated.has(key) || table.has(key)) {
|
|
1224
|
+
table.set(key, null);
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
const spelling = certifiedSpelling(secrets, sourceByKey.get(key), value);
|
|
1228
|
+
if (spelling !== void 0) table.set(key, spelling);
|
|
1229
|
+
}
|
|
1230
|
+
if (table.size > 0) rowTagSpellings.set(secrets, table);
|
|
1231
|
+
else rowTagSpellings.delete(secrets);
|
|
1232
|
+
}
|
|
1233
|
+
function certifiedSpelling(secrets, source, value) {
|
|
1234
|
+
if (typeof source === "string") {
|
|
1235
|
+
if (dynamicReferenceSpans(source).length === 0) return source === value ? {
|
|
1236
|
+
value,
|
|
1237
|
+
spelling: source,
|
|
1238
|
+
fromLiteral: true
|
|
1239
|
+
} : void 0;
|
|
1240
|
+
return rendersLiteralTo(source, secrets, value) ? {
|
|
1241
|
+
value,
|
|
1242
|
+
spelling: source,
|
|
1243
|
+
fromLiteral: true
|
|
1244
|
+
} : void 0;
|
|
1245
|
+
}
|
|
1246
|
+
if (!isPlainObject(source)) return void 0;
|
|
1247
|
+
const spelling = substitutedSpellingOf(secrets, source, value);
|
|
1248
|
+
return spelling === void 0 ? void 0 : {
|
|
1249
|
+
value,
|
|
1250
|
+
spelling,
|
|
1251
|
+
fromLiteral: false
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function nestedStackRowTagSpellingOf(secrets, key, value) {
|
|
1255
|
+
const entry = rowTagSpellings.get(secrets)?.get(key);
|
|
1256
|
+
return entry !== void 0 && entry !== null && entry.value === value ? entry : void 0;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// src/deployment/secret-redaction/nested-stack/record-parameter-expressions.ts
|
|
1260
|
+
function recordNestedStackParameterExpressions(secrets, resourceType, resolvedProperties, sourceProperties, provenance = "template-derived") {
|
|
1261
|
+
if (resourceType !== "AWS::CloudFormation::Stack") return;
|
|
1262
|
+
if (provenance === "template-derived") recordNestedStackRowTagSpellings(secrets, resourceType, resolvedProperties, sourceProperties);
|
|
1263
|
+
if (secrets.size === 0) return;
|
|
1264
|
+
if (!isPlainObject(resolvedProperties) || !isPlainObject(sourceProperties)) return;
|
|
1265
|
+
if (!Object.hasOwn(resolvedProperties, "Parameters")) return;
|
|
1266
|
+
if (!Object.hasOwn(sourceProperties, "Parameters")) return;
|
|
1267
|
+
const resolvedParameters = resolvedProperties["Parameters"];
|
|
1268
|
+
const sourceParameters = sourceProperties["Parameters"];
|
|
1269
|
+
if (!isPlainObject(resolvedParameters) || !isPlainObject(sourceParameters)) return;
|
|
1270
|
+
const positioned = withoutLiteralRendering(() => redactAtProvenance({ ...resolvedParameters }, secrets, sourceParameters, provenance, true));
|
|
1271
|
+
let table = nestedStackParameterExpressions.get(secrets);
|
|
1272
|
+
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
1273
|
+
const sourceLeaf = sourceParameters[name];
|
|
1274
|
+
if (typeof resolvedValue !== "string") continue;
|
|
1275
|
+
const spelling = typeof sourceLeaf === "string" ? !isSingleDynamicReferenceToken(sourceLeaf) && positioned[name] === sourceLeaf ? sourceLeaf : void 0 : provenance === "template-derived" ? substitutionSpelling(resolvedValue, sourceLeaf, secrets, name) : void 0;
|
|
1276
|
+
if (holdsSubFloorSecret(resolvedValue, secrets) || holdsConsumedSubFloorSecret(resolvedValue, sourceLeaf, secrets) || isPlainObject(sourceLeaf) && attributionRefusedReadsOf(sourceLeaf, secrets) !== void 0) markAttributionRefusedParameter(secrets, name, "sub-floor");
|
|
1277
|
+
if (spelling === void 0 || !rendersLiteralTo(spelling, secrets, resolvedValue)) continue;
|
|
1278
|
+
let rendered = renderedParameterSpellings.get(secrets);
|
|
1279
|
+
if (rendered === void 0) {
|
|
1280
|
+
rendered = /* @__PURE__ */ new Map();
|
|
1281
|
+
renderedParameterSpellings.set(secrets, rendered);
|
|
1282
|
+
}
|
|
1283
|
+
const previous = rendered.get(name);
|
|
1284
|
+
if (previous === void 0) rendered.set(name, {
|
|
1285
|
+
spelling,
|
|
1286
|
+
value: resolvedValue
|
|
1287
|
+
});
|
|
1288
|
+
else if (previous?.spelling !== spelling || previous.value !== resolvedValue) rendered.set(name, null);
|
|
1289
|
+
}
|
|
1290
|
+
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
1291
|
+
if (typeof resolvedValue !== "string" || !secrets.has(resolvedValue)) continue;
|
|
1292
|
+
const expression = positioned[name];
|
|
1293
|
+
if (typeof expression !== "string") continue;
|
|
1294
|
+
if (!isSingleDynamicReferenceToken(expression)) continue;
|
|
1295
|
+
const sourceLeaf = sourceParameters[name];
|
|
1296
|
+
if (typeof sourceLeaf === "string" && expression !== sourceLeaf) continue;
|
|
1297
|
+
if (expression === resolvedValue) continue;
|
|
1298
|
+
const seenResolvingTo = plaintextIndexOf(secrets).get(expression);
|
|
1299
|
+
if (seenResolvingTo !== void 0 && seenResolvingTo !== resolvedValue) continue;
|
|
1300
|
+
if (typeof sourceLeaf === "string" && resolvedPlaintextOf(secrets, expression) !== resolvedValue) continue;
|
|
1301
|
+
if (table === void 0) {
|
|
1302
|
+
table = /* @__PURE__ */ new Map();
|
|
1303
|
+
nestedStackParameterExpressions.set(secrets, table);
|
|
1304
|
+
}
|
|
1305
|
+
storeAssociation(table, name, expression, resolvedValue);
|
|
1306
|
+
}
|
|
1307
|
+
const framesByValue = /* @__PURE__ */ new Map();
|
|
1308
|
+
const tokensOf = /* @__PURE__ */ new Map();
|
|
1309
|
+
const frameSpellings = /* @__PURE__ */ new Map();
|
|
1310
|
+
const frameSpellingOf = (name) => {
|
|
1311
|
+
if (!frameSpellings.has(name)) frameSpellings.set(name, computeFrameSpelling(name));
|
|
1312
|
+
return frameSpellings.get(name);
|
|
1313
|
+
};
|
|
1314
|
+
const computeFrameSpelling = (name) => {
|
|
1315
|
+
const resolvedValue = resolvedParameters[name];
|
|
1316
|
+
if (typeof resolvedValue !== "string") return void 0;
|
|
1317
|
+
const sourceLeaf = sourceParameters[name];
|
|
1318
|
+
if (typeof sourceLeaf === "string") return sourceLeaf;
|
|
1319
|
+
if (!isPlainObject(sourceLeaf)) return void 0;
|
|
1320
|
+
const written = positioned[name];
|
|
1321
|
+
if (typeof written !== "string") return void 0;
|
|
1322
|
+
const rendered = intrinsicSkeletonSegments(sourceLeaf)?.map((s) => s === UNKNOWN_PART ? "\0" : s).join("");
|
|
1323
|
+
const spans = rendered === void 0 ? [] : dynamicReferenceSpans(rendered);
|
|
1324
|
+
if (rendered !== void 0 && spans.length === 1) {
|
|
1325
|
+
const [span] = spans;
|
|
1326
|
+
const ownToken = rendered.slice(span.start, span.end);
|
|
1327
|
+
if (written !== resolvedValue && SPELLED_SECRET_REFERENCE_PREFIXES.some((prefix) => ownToken.startsWith(prefix))) return written;
|
|
1328
|
+
}
|
|
1329
|
+
const substituted = substitutedSpellingOf(secrets, sourceLeaf, resolvedValue);
|
|
1330
|
+
if (substituted === void 0) return void 0;
|
|
1331
|
+
return written === resolvedValue || written === substituted ? substituted : void 0;
|
|
1332
|
+
};
|
|
1333
|
+
const certifiedSpellingOf = (name) => {
|
|
1334
|
+
const sourceLeaf = sourceParameters[name];
|
|
1335
|
+
if (typeof sourceLeaf === "string") return positioned[name] === sourceLeaf ? sourceLeaf : void 0;
|
|
1336
|
+
return frameSpellingOf(name);
|
|
1337
|
+
};
|
|
1338
|
+
const unwrittenValues = /* @__PURE__ */ new Set();
|
|
1339
|
+
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
1340
|
+
if (typeof resolvedValue !== "string") continue;
|
|
1341
|
+
const spelling = frameSpellingOf(name);
|
|
1342
|
+
const frame = spelling === void 0 ? void 0 : singleSpanFrame(resolvedValue, spelling);
|
|
1343
|
+
const frames = framesByValue.get(resolvedValue) ?? /* @__PURE__ */ new Set();
|
|
1344
|
+
const unframed = frame === void 0 || resolvedPlaintextOf(secrets, frame.token) !== frame.middle;
|
|
1345
|
+
frames.add(unframed ? UNFRAMED_SPELLING : `${frame.prefix.length}:${frame.prefix}${frame.suffix}`);
|
|
1346
|
+
framesByValue.set(resolvedValue, frames);
|
|
1347
|
+
if (!unframed) {
|
|
1348
|
+
const tokens = tokensOf.get(resolvedValue) ?? /* @__PURE__ */ new Set();
|
|
1349
|
+
tokens.add(frame.token);
|
|
1350
|
+
tokensOf.set(resolvedValue, tokens);
|
|
1351
|
+
if (typeof sourceParameters[name] !== "string" && positioned[name] !== spelling) unwrittenValues.add(resolvedValue);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
for (const value of unwrittenValues) if (tokensOf.get(value)?.size !== 1) framesByValue.get(value)?.add(UNFRAMED_SPELLING);
|
|
1355
|
+
const rowWithoutParameters = {};
|
|
1356
|
+
for (const [key, value] of Object.entries(resolvedProperties)) if (key !== "Parameters") rowWithoutParameters[key] = value;
|
|
1357
|
+
const outsideLeaves = wholeStringLeavesOf(rowWithoutParameters);
|
|
1358
|
+
const framed = /* @__PURE__ */ new Map();
|
|
1359
|
+
const framedByName = [];
|
|
1360
|
+
for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
|
|
1361
|
+
if (typeof resolvedValue !== "string") continue;
|
|
1362
|
+
const spelling = certifiedSpellingOf(name);
|
|
1363
|
+
if (spelling === void 0) continue;
|
|
1364
|
+
if (redactForState(resolvedValue, {
|
|
1365
|
+
provenance: "value-scan",
|
|
1366
|
+
secrets
|
|
1367
|
+
}) !== resolvedValue) continue;
|
|
1368
|
+
const frame = singleSpanFrame(resolvedValue, spelling);
|
|
1369
|
+
if (frame === void 0 || resolvedPlaintextOf(secrets, frame.token) !== frame.middle) continue;
|
|
1370
|
+
if (framesByValue.get(resolvedValue)?.size !== 1) continue;
|
|
1371
|
+
const isNeedle = resolvedValue.length >= 4;
|
|
1372
|
+
const rewrites = (leaf) => leaf === resolvedValue || isNeedle && leaf.includes(resolvedValue);
|
|
1373
|
+
let embedded = false;
|
|
1374
|
+
for (const leaf of outsideLeaves) if (rewrites(leaf)) {
|
|
1375
|
+
embedded = true;
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
for (const other of Object.values(resolvedParameters)) {
|
|
1379
|
+
if (embedded) break;
|
|
1380
|
+
if (typeof other === "string") {
|
|
1381
|
+
if (other !== resolvedValue && rewrites(other)) embedded = true;
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
for (const leaf of wholeStringLeavesOf(other)) if (rewrites(leaf)) {
|
|
1385
|
+
embedded = true;
|
|
1386
|
+
break;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (embedded) continue;
|
|
1390
|
+
framedByName.push([
|
|
1391
|
+
name,
|
|
1392
|
+
spelling,
|
|
1393
|
+
resolvedValue
|
|
1394
|
+
]);
|
|
1395
|
+
if (secrets.get(frame.middle) !== frame.token && tokensOf.get(resolvedValue)?.size !== 1) continue;
|
|
1396
|
+
framed.set(resolvedValue, spelling);
|
|
1397
|
+
}
|
|
1398
|
+
for (const [plaintext, expression] of framed) secrets.set(plaintext, expression);
|
|
1399
|
+
for (const [name, expression, plaintext] of framedByName) {
|
|
1400
|
+
if (table === void 0) {
|
|
1401
|
+
table = /* @__PURE__ */ new Map();
|
|
1402
|
+
nestedStackParameterExpressions.set(secrets, table);
|
|
1403
|
+
}
|
|
1404
|
+
storeAssociation(table, name, expression, plaintext);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
function substitutionSpelling(resolvedValue, sourceLeaf, secrets, name) {
|
|
1408
|
+
const placed = positionBySubstitutionSpans(resolvedValue, sourceLeaf, secrets, TEMPLATE_DERIVED_RULES, (text) => redactForState(text, {
|
|
1409
|
+
provenance: "value-scan",
|
|
1410
|
+
secrets
|
|
1411
|
+
}));
|
|
1412
|
+
const spelled = placed === TAINTED_WITHOUT_SPAN ? "***" : placed;
|
|
1413
|
+
if (spelled === "***") {
|
|
1414
|
+
recordDerivedMaskOnlyValue(secrets, resolvedValue);
|
|
1415
|
+
markAttributionRefusedParameter(secrets, name, "masked");
|
|
1416
|
+
}
|
|
1417
|
+
return spelled === void 0 || spelled === "***" || spelled === resolvedValue ? void 0 : spelled;
|
|
1418
|
+
}
|
|
1419
|
+
function holdsConsumedSubFloorSecret(value, sourceLeaf, secrets) {
|
|
1420
|
+
const tokens = typeof sourceLeaf === "string" ? dynamicReferenceTokens(sourceLeaf) : isPlainObject(sourceLeaf) ? [...referencesConsumedBy(secrets, sourceLeaf)] : [];
|
|
1421
|
+
for (const token of tokens) {
|
|
1422
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
1423
|
+
if (plaintext === void 0 || plaintext === "" || plaintext.length >= 4) continue;
|
|
1424
|
+
if (value.includes(plaintext)) return true;
|
|
1425
|
+
}
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
function holdsSubFloorSecret(value, secrets) {
|
|
1429
|
+
for (const [plaintext, expression] of secrets) {
|
|
1430
|
+
if (plaintext === "" || plaintext.length >= 4) continue;
|
|
1431
|
+
if (expression !== "***" && value.includes(plaintext)) return true;
|
|
1432
|
+
}
|
|
1433
|
+
return false;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// src/deployment/secret-redaction/fresh-noecho.ts
|
|
1437
|
+
function embedsFreshNoEchoValue(text, secrets, freshClass) {
|
|
1438
|
+
const fresh = freshNoEchoValuesOf.get(secrets);
|
|
1439
|
+
if (fresh === void 0) return false;
|
|
1440
|
+
for (const value of fresh) {
|
|
1441
|
+
if (freshClass !== void 0 && isNoEchoParameterPlaintext(secrets, value) !== (freshClass === "parameter")) continue;
|
|
1442
|
+
if (isMaskOnlyPlaintext(secrets, value) && text.includes(value)) return true;
|
|
1443
|
+
}
|
|
1444
|
+
return false;
|
|
1445
|
+
}
|
|
1446
|
+
function carriesFreshNoEchoValue(value, secrets, freshClass) {
|
|
1447
|
+
const isFresh = freshNoEchoLeafTest(secrets, freshClass);
|
|
1448
|
+
if (isFresh === void 0) return false;
|
|
1449
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1450
|
+
const walk = (node) => {
|
|
1451
|
+
if (typeof node === "string") return isFresh(node);
|
|
1452
|
+
if (node === null || typeof node !== "object") return false;
|
|
1453
|
+
if (seen.has(node)) return false;
|
|
1454
|
+
seen.add(node);
|
|
1455
|
+
if (Array.isArray(node)) return node.some((item) => walk(item));
|
|
1456
|
+
return Object.values(node).some((child) => walk(child));
|
|
1457
|
+
};
|
|
1458
|
+
return walk(value);
|
|
1459
|
+
}
|
|
1460
|
+
function freshNoEchoLeafPositions(value, secrets, freshClass) {
|
|
1461
|
+
const isFresh = freshNoEchoLeafTest(secrets, freshClass);
|
|
1462
|
+
if (isFresh === void 0) return [];
|
|
1463
|
+
const leaves = [];
|
|
1464
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
1465
|
+
const walk = (node, path) => {
|
|
1466
|
+
if (typeof node === "string") {
|
|
1467
|
+
if (isFresh(node)) leaves.push({
|
|
1468
|
+
path,
|
|
1469
|
+
plaintext: node
|
|
1470
|
+
});
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (node === null || typeof node !== "object") return;
|
|
1474
|
+
if (ancestors.has(node)) return;
|
|
1475
|
+
ancestors.add(node);
|
|
1476
|
+
if (Array.isArray(node)) node.forEach((item, index) => walk(item, [...path, index]));
|
|
1477
|
+
else for (const [key, child] of Object.entries(node)) walk(child, [...path, key]);
|
|
1478
|
+
ancestors.delete(node);
|
|
1479
|
+
};
|
|
1480
|
+
walk(value, []);
|
|
1481
|
+
return leaves;
|
|
1482
|
+
}
|
|
1483
|
+
function freshNoEchoLeafTest(secrets, freshClass) {
|
|
1484
|
+
const all = freshNoEchoValuesOf.get(secrets);
|
|
1485
|
+
if (all === void 0 || all.size === 0) return void 0;
|
|
1486
|
+
const fresh = freshClass === void 0 ? all : new Set([...all].filter((value) => isNoEchoParameterPlaintext(secrets, value) === (freshClass === "parameter")));
|
|
1487
|
+
if (fresh.size === 0) return void 0;
|
|
1488
|
+
const needles = containmentNeedlesOf(secrets).filter((needle) => fresh.has(needle));
|
|
1489
|
+
return (leaf) => fresh.has(leaf) && isMaskOnlyPlaintext(secrets, leaf) || leaf !== "***" && embedsNeedleOutsideReferences(leaf, needles, secrets);
|
|
1490
|
+
}
|
|
1491
|
+
function containmentNeedlesOf(secrets) {
|
|
1492
|
+
const values = containmentValuesOf.get(secrets);
|
|
1493
|
+
if (values === void 0 || values.size === 0) return [];
|
|
1494
|
+
const needles = [];
|
|
1495
|
+
for (const value of values) if (value.length >= 4 && isMaskOnlyPlaintext(secrets, value)) needles.push(value);
|
|
1496
|
+
return needles;
|
|
1497
|
+
}
|
|
1498
|
+
function isStrictlyInsideASpan(spans, start, end) {
|
|
1499
|
+
return spans.some((span) => span.start <= start && end <= span.end && (span.start !== start || span.end !== end));
|
|
1500
|
+
}
|
|
1501
|
+
function embedsNeedleOutsideReferences(leaf, needles, secrets) {
|
|
1502
|
+
return needleOccurrencesOutsideReferences(leaf, needles, secrets, true).length > 0;
|
|
1503
|
+
}
|
|
1504
|
+
function needleOccurrencesOutsideReferences(leaf, needles, secrets, first) {
|
|
1505
|
+
const found = [];
|
|
1506
|
+
let spans;
|
|
1507
|
+
let names;
|
|
1508
|
+
for (const needle of needles) for (let at = leaf.indexOf(needle); at >= 0; at = leaf.indexOf(needle, at + 1)) {
|
|
1509
|
+
spans ??= isDynamicReferenceString(leaf) ? resolvableReferenceSpans(leaf, new Set(secrets.values())) : [];
|
|
1510
|
+
if (isStrictlyInsideASpan(spans, at, at + needle.length)) continue;
|
|
1511
|
+
names ??= physicalNameSpans(physicalNameCopiesOf.get(secrets), leaf);
|
|
1512
|
+
const end = at + needle.length;
|
|
1513
|
+
if (names.some((n) => n.start <= at && end <= n.end)) continue;
|
|
1514
|
+
found.push({
|
|
1515
|
+
start: at,
|
|
1516
|
+
end
|
|
1517
|
+
});
|
|
1518
|
+
if (first) return found;
|
|
1519
|
+
}
|
|
1520
|
+
return found;
|
|
1521
|
+
}
|
|
1522
|
+
function cutsContainmentNeedle(leaf, secrets, redacted) {
|
|
1523
|
+
if (redacted.length === 0) return false;
|
|
1524
|
+
const needles = containmentNeedlesOf(secrets);
|
|
1525
|
+
if (needles.length === 0) return false;
|
|
1526
|
+
return needleOccurrencesOutsideReferences(leaf, needles, secrets, false).some((c) => redacted.some((m) => m.start < c.end && c.start < m.end && !(m.start <= c.start && c.end <= m.end)));
|
|
1527
|
+
}
|
|
1528
|
+
function flattenEmbeddedNoEchoLeaves(value, secrets) {
|
|
1529
|
+
const needles = containmentNeedlesOf(secrets);
|
|
1530
|
+
if (needles.length === 0) return value;
|
|
1531
|
+
const flattens = (leaf) => leaf !== "***" && embedsNeedleOutsideReferences(leaf, needles, secrets);
|
|
1532
|
+
const walk = (node) => {
|
|
1533
|
+
if (typeof node === "string") return flattens(node) ? "***" : node;
|
|
1534
|
+
if (node === null || typeof node !== "object") return node;
|
|
1535
|
+
if (Array.isArray(node)) {
|
|
1536
|
+
let changed = false;
|
|
1537
|
+
const out = node.map((item) => {
|
|
1538
|
+
const next = walk(item);
|
|
1539
|
+
if (next !== item) changed = true;
|
|
1540
|
+
return next;
|
|
1541
|
+
});
|
|
1542
|
+
return changed ? out : node;
|
|
1543
|
+
}
|
|
1544
|
+
if (isOrdinaryDate(node)) {
|
|
1545
|
+
const persisted = node.toJSON();
|
|
1546
|
+
return typeof persisted === "string" && flattens(persisted) ? "***" : node;
|
|
1547
|
+
}
|
|
1548
|
+
let out;
|
|
1549
|
+
for (const [key, child] of Object.entries(node)) {
|
|
1550
|
+
const next = walk(child);
|
|
1551
|
+
if (next === child) continue;
|
|
1552
|
+
out ??= Object.assign(Object.create(null), node);
|
|
1553
|
+
out[key] = next;
|
|
1554
|
+
}
|
|
1555
|
+
return out ?? node;
|
|
1556
|
+
};
|
|
1557
|
+
return walk(value);
|
|
1558
|
+
}
|
|
1559
|
+
function substringNeedlesOf(secrets) {
|
|
1560
|
+
const needles = [];
|
|
1561
|
+
for (const plaintext of secrets.keys()) if (!isMaskOnlyPlaintext(secrets, plaintext)) needles.push(plaintext);
|
|
1562
|
+
return needles;
|
|
1563
|
+
}
|
|
1564
|
+
function recordedExpressionsOf(secrets) {
|
|
1565
|
+
const expressions = /* @__PURE__ */ new Set();
|
|
1566
|
+
for (const [plaintext, expression] of secrets) if (!isMaskOnlyPlaintext(secrets, plaintext)) expressions.add(expression);
|
|
1567
|
+
return expressions;
|
|
1568
|
+
}
|
|
1569
|
+
const recoverableMaskedOutputs = /* @__PURE__ */ new Map();
|
|
1570
|
+
function maskedOutputKey(identity, stackName, region, outputKey) {
|
|
1571
|
+
return `${identity}\u0000${stackName}\u0000${region}\u0000${outputKey}`;
|
|
1572
|
+
}
|
|
1573
|
+
function recordRecoverableMaskedOutput(identity, stackName, region, outputKey, plaintext) {
|
|
1574
|
+
recoverableMaskedOutputs.set(maskedOutputKey(identity, stackName, region, outputKey), plaintext);
|
|
1575
|
+
}
|
|
1576
|
+
function recoverMaskedOutput(identity, stackName, region, outputKey) {
|
|
1577
|
+
return recoverableMaskedOutputs.get(maskedOutputKey(identity, stackName, region, outputKey));
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/deployment/secret-redaction/nested-stack/child-only-plaintext.ts
|
|
1581
|
+
function carriesChildOnlyPlaintext(value, childSecrets, parentSecrets) {
|
|
1582
|
+
const parentNeedles = new Set(substringNeedlesOf(parentSecrets));
|
|
1583
|
+
const childNeedles = new Set(substringNeedlesOf(childSecrets));
|
|
1584
|
+
const childOnly = [...childSecrets.keys()].filter((plaintext) => plaintext !== "" && (!parentSecrets.has(plaintext) || childNeedles.has(plaintext) && !parentNeedles.has(plaintext)));
|
|
1585
|
+
for (const needle of parentNeedles) if (needle.length >= 4 && !childSecrets.has(needle)) childOnly.push(needle);
|
|
1586
|
+
if (childOnly.length === 0) return false;
|
|
1587
|
+
const visit = (node) => {
|
|
1588
|
+
if (typeof node === "string") return childOnly.some((plaintext) => node.includes(plaintext));
|
|
1589
|
+
if (Array.isArray(node)) return node.some(visit);
|
|
1590
|
+
if (node !== null && typeof node === "object") return Object.values(node).some(visit);
|
|
1591
|
+
return false;
|
|
1592
|
+
};
|
|
1593
|
+
return visit(value);
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// src/deployment/secret-redaction/nested-stack/inherited-parameters.ts
|
|
1597
|
+
function inheritNestedStackParameterAssociations(childSecrets, parentSecrets) {
|
|
1598
|
+
for (const [name, kind] of attributionRefusedParameters.get(parentSecrets) ?? []) markAttributionRefusedParameter(childSecrets, name, kind);
|
|
1599
|
+
const table = nestedStackParameterExpressions.get(parentSecrets);
|
|
1600
|
+
if (table === void 0 || table.size === 0) return;
|
|
1601
|
+
let associations = crossStackAssociations.get(childSecrets);
|
|
1602
|
+
for (const [name, association] of table) {
|
|
1603
|
+
const key = crossStackSourceKey({ Ref: name });
|
|
1604
|
+
if (key === void 0) continue;
|
|
1605
|
+
if (associations === void 0) {
|
|
1606
|
+
associations = /* @__PURE__ */ new Map();
|
|
1607
|
+
crossStackAssociations.set(childSecrets, associations);
|
|
1608
|
+
}
|
|
1609
|
+
if (typeof association === "symbol") {
|
|
1610
|
+
associations.set(key, association);
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
storeAssociation(associations, key, association.expression, association.plaintext);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
function inheritedParameterExpression(parentSecrets, parameterName, resolvedValue) {
|
|
1617
|
+
const association = nestedStackParameterExpressions.get(parentSecrets)?.get(parameterName);
|
|
1618
|
+
if (association === void 0) return renderedParameterSpelling(parentSecrets, parameterName, resolvedValue);
|
|
1619
|
+
if (typeof association === "symbol") return void 0;
|
|
1620
|
+
if (Array.isArray(resolvedValue)) return certifiedListForLeaf(parentSecrets, association, resolvedValue);
|
|
1621
|
+
return certifiedExpressionForLeaf(parentSecrets, association, resolvedValue);
|
|
1622
|
+
}
|
|
1623
|
+
function renderedParameterSpelling(parentSecrets, parameterName, resolvedValue) {
|
|
1624
|
+
if (typeof resolvedValue !== "string" || parentSecrets.has(resolvedValue)) return void 0;
|
|
1625
|
+
const rendered = renderedParameterSpellings.get(parentSecrets)?.get(parameterName);
|
|
1626
|
+
if (rendered == null || rendered.value !== resolvedValue) return void 0;
|
|
1627
|
+
if (!rendersLiteralTo(rendered.spelling, parentSecrets, resolvedValue)) return void 0;
|
|
1628
|
+
return rendered.spelling;
|
|
1338
1629
|
}
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
if (
|
|
1342
|
-
|
|
1630
|
+
function inheritedRenderedToken(parentSecrets, parameterName, value, plaintext) {
|
|
1631
|
+
const spelling = inheritedParameterExpression(parentSecrets, parameterName, value);
|
|
1632
|
+
if (typeof spelling !== "string" || isSingleDynamicReferenceToken(spelling)) return void 0;
|
|
1633
|
+
return renderedTokenOf(spelling, parentSecrets, plaintext);
|
|
1634
|
+
}
|
|
1635
|
+
function withdrawRenderedParameterSpelling(parentSecrets, parameterName) {
|
|
1636
|
+
const rendered = renderedParameterSpellings.get(parentSecrets);
|
|
1637
|
+
if (rendered?.has(parameterName)) rendered.set(parameterName, null);
|
|
1638
|
+
}
|
|
1639
|
+
function inheritedRenderedSpan(childSecrets, key, text) {
|
|
1640
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
1641
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
1642
|
+
for (const name of reads.names) {
|
|
1643
|
+
if (crossStackSourceKey({ Ref: name }) !== key) continue;
|
|
1644
|
+
const value = renderedParameterSpellings.get(reads.parent)?.get(name)?.value;
|
|
1645
|
+
if (value === void 0 || text !== void 0 && text !== value) return void 0;
|
|
1646
|
+
if (carriesChildOnlyPlaintext(value, childSecrets, reads.parent)) return void 0;
|
|
1647
|
+
const spelling = inheritedParameterExpression(reads.parent, name, value);
|
|
1648
|
+
if (typeof spelling !== "string") return void 0;
|
|
1649
|
+
if (redactForState(spelling, {
|
|
1650
|
+
provenance: "value-scan",
|
|
1651
|
+
secrets: childSecrets
|
|
1652
|
+
}) !== spelling) return void 0;
|
|
1653
|
+
return {
|
|
1654
|
+
value,
|
|
1655
|
+
spelling
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
const inheritedParameterReads = /* @__PURE__ */ new WeakMap();
|
|
1660
|
+
const POISONED_PARAMETER_READS = Symbol("cdkd.inherited-parameter-reads.poisoned");
|
|
1661
|
+
function parameterReadsFor(childSecrets, parentSecrets) {
|
|
1662
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
1663
|
+
if (reads === void 0) {
|
|
1664
|
+
const created = {
|
|
1665
|
+
parent: parentSecrets,
|
|
1666
|
+
names: /* @__PURE__ */ new Set(),
|
|
1667
|
+
values: /* @__PURE__ */ new Map()
|
|
1668
|
+
};
|
|
1669
|
+
inheritedParameterReads.set(childSecrets, created);
|
|
1670
|
+
return created;
|
|
1671
|
+
}
|
|
1672
|
+
if (typeof reads === "symbol") return void 0;
|
|
1673
|
+
if (reads.parent !== parentSecrets) {
|
|
1674
|
+
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1343
1675
|
return;
|
|
1344
1676
|
}
|
|
1345
|
-
|
|
1346
|
-
out.push(part);
|
|
1677
|
+
return reads;
|
|
1347
1678
|
}
|
|
1348
|
-
function
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
if (
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
if (depth >= MAX_PLACEHOLDER_DEPTH) {
|
|
1356
|
-
budget.exhausted = true;
|
|
1679
|
+
function recordInheritedParameterValue(childSecrets, parentSecrets, parameterName, value, declared) {
|
|
1680
|
+
const reads = parameterReadsFor(childSecrets, parentSecrets);
|
|
1681
|
+
if (reads === void 0) return;
|
|
1682
|
+
if (declared !== void 0) {
|
|
1683
|
+
if (reads.declared === void 0) reads.declared = declared;
|
|
1684
|
+
else if (reads.declared.size !== declared.size || [...declared].some((name) => !reads.declared.has(name))) {
|
|
1685
|
+
inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1357
1686
|
return;
|
|
1358
1687
|
}
|
|
1359
|
-
if (appendParameterPlaceholderParts(value, out, budget, depth + 1)) return;
|
|
1360
|
-
return pushPlaceholderPart(out, keyedPart(value), budget);
|
|
1361
1688
|
}
|
|
1362
|
-
|
|
1689
|
+
if (reads.values.has(parameterName)) {
|
|
1690
|
+
if (!deepEqualJsonValue(reads.values.get(parameterName), value)) inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
reads.values.set(parameterName, value);
|
|
1363
1694
|
}
|
|
1364
|
-
function
|
|
1695
|
+
function recordInheritedParameterRead(childSecrets, parentSecrets, parameterName) {
|
|
1696
|
+
parameterReadsFor(childSecrets, parentSecrets)?.names.add(parameterName);
|
|
1697
|
+
}
|
|
1698
|
+
function redactInheritedParameterValue(parentSecrets, parameterName, value) {
|
|
1699
|
+
return inheritedParameterExpression(parentSecrets, parameterName, value) ?? redactForState(value, {
|
|
1700
|
+
provenance: "value-scan",
|
|
1701
|
+
secrets: parentSecrets
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
function persistedInheritedParameterValue(parentSecrets, parameterName, value) {
|
|
1705
|
+
if (attributionRefusedParameters.get(parentSecrets)?.get(parameterName) !== "sub-floor") return redactInheritedParameterValue(parentSecrets, parameterName, value);
|
|
1706
|
+
const certified = inheritedParameterExpression(parentSecrets, parameterName, value);
|
|
1707
|
+
if (certified !== void 0) return certified;
|
|
1708
|
+
const scanned = redactForState(value, {
|
|
1709
|
+
provenance: "value-scan",
|
|
1710
|
+
secrets: parentSecrets
|
|
1711
|
+
});
|
|
1712
|
+
const masked = (text) => typeof text === "string" && literalTextHoldsSubFloorSecret(text, parentSecrets) ? "***" : text;
|
|
1713
|
+
return Array.isArray(scanned) ? scanned.map(masked) : masked(scanned);
|
|
1714
|
+
}
|
|
1715
|
+
function positionByInheritedParameter(bag, source, secrets) {
|
|
1365
1716
|
const keys = Object.keys(source);
|
|
1366
|
-
if (keys.length !== 1) return
|
|
1367
|
-
const
|
|
1368
|
-
if (
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (key === "Fn::Sub") {
|
|
1380
|
-
const args = source[key];
|
|
1381
|
-
let template;
|
|
1382
|
-
let variables = {};
|
|
1383
|
-
if (typeof args === "string") template = args;
|
|
1384
|
-
else if (Array.isArray(args) && args.length === 2 && isPlainObject(args[1])) {
|
|
1385
|
-
template = args[0];
|
|
1386
|
-
variables = args[1];
|
|
1387
|
-
} else return false;
|
|
1388
|
-
if (typeof template !== "string") return false;
|
|
1389
|
-
let cursor = 0;
|
|
1390
|
-
for (const hit of template.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
1391
|
-
if (budget.exhausted) return true;
|
|
1392
|
-
pushPlaceholderPart(out, template.slice(cursor, hit.index), budget);
|
|
1393
|
-
cursor = hit.index + hit[0].length;
|
|
1394
|
-
const name = hit[2] ?? "";
|
|
1395
|
-
if (hit[1] === "!") pushPlaceholderPart(out, `\${${name}}`, budget);
|
|
1396
|
-
else if (name === "") pushPlaceholderPart(out, hit[0], budget);
|
|
1397
|
-
else if (Object.hasOwn(variables, name)) appendValuePlaceholderParts(variables[name], out, budget, depth);
|
|
1398
|
-
else if (name.includes(".")) pushPlaceholderPart(out, keyedPart({ "Fn::GetAtt": name }), budget);
|
|
1399
|
-
else pushPlaceholderPart(out, keyedPart({ Ref: name }), budget);
|
|
1400
|
-
}
|
|
1401
|
-
pushPlaceholderPart(out, template.slice(cursor), budget);
|
|
1402
|
-
return true;
|
|
1403
|
-
}
|
|
1404
|
-
return false;
|
|
1717
|
+
if (keys.length !== 1 || keys[0] !== "Ref") return void 0;
|
|
1718
|
+
const name = source["Ref"];
|
|
1719
|
+
if (typeof name !== "string") return void 0;
|
|
1720
|
+
const reads = inheritedParameterReads.get(secrets);
|
|
1721
|
+
if (reads === void 0 || typeof reads === "symbol" || !reads.names.has(name)) return;
|
|
1722
|
+
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
1723
|
+
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
1724
|
+
const answer = persistedInheritedParameterValue(reads.parent, name, bag);
|
|
1725
|
+
if (!deepEqualJsonValue(redactForState(answer, {
|
|
1726
|
+
provenance: "value-scan",
|
|
1727
|
+
secrets
|
|
1728
|
+
}), answer)) return void 0;
|
|
1729
|
+
return answer;
|
|
1405
1730
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1731
|
+
|
|
1732
|
+
// src/deployment/secret-redaction/nested-stack/pseudo-parameters.ts
|
|
1733
|
+
const REREAD_PSEUDO_PARAMETERS = /* @__PURE__ */ new Set([
|
|
1734
|
+
"AWS::Region",
|
|
1735
|
+
"AWS::Partition",
|
|
1736
|
+
"AWS::URLSuffix",
|
|
1737
|
+
"AWS::AccountId"
|
|
1738
|
+
]);
|
|
1739
|
+
function templateRereadsAccountId(template) {
|
|
1740
|
+
if (template === void 0) return false;
|
|
1741
|
+
const resources = template.Resources !== null && typeof template.Resources === "object" ? template.Resources : void 0;
|
|
1742
|
+
const cached = resources && accountRereadVerdicts.get(resources);
|
|
1743
|
+
if (cached !== void 0 && cached.outputs === template.Outputs) return cached.verdict;
|
|
1744
|
+
const parts = resources ? Object.values(resources) : [];
|
|
1745
|
+
if (template.Outputs !== void 0) parts.push(template.Outputs);
|
|
1746
|
+
const verdict = parts.some(partRereadsAccountId);
|
|
1747
|
+
if (resources) accountRereadVerdicts.set(resources, {
|
|
1748
|
+
outputs: template.Outputs,
|
|
1749
|
+
verdict
|
|
1750
|
+
});
|
|
1751
|
+
return verdict;
|
|
1414
1752
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
if (part !== UNKNOWN_PART) {
|
|
1437
|
-
const association = associations?.get(part.key);
|
|
1438
|
-
if (association !== void 0 && typeof association !== "symbol") {
|
|
1439
|
-
plaintext = association.plaintext;
|
|
1440
|
-
expression = certifiedExpressionForLeaf(secrets, association, plaintext);
|
|
1441
|
-
}
|
|
1442
|
-
if (expression === void 0) {
|
|
1443
|
-
const inherited = inheritedRenderedSpan(secrets, part.key);
|
|
1444
|
-
if (inherited !== void 0) {
|
|
1445
|
-
plaintext = inherited.value;
|
|
1446
|
-
expression = inherited.spelling;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
const pseudo = expression === void 0 && part !== UNKNOWN_PART ? inheritedPseudoSpan(secrets, part.key) : void 0;
|
|
1451
|
-
if (pseudo !== void 0) {
|
|
1452
|
-
side[0] += pseudo;
|
|
1453
|
-
side[1] += pseudo;
|
|
1454
|
-
continue;
|
|
1455
|
-
}
|
|
1456
|
-
if (expression === void 0) {
|
|
1457
|
-
if (unknown) return void 0;
|
|
1458
|
-
unknown = true;
|
|
1459
|
-
side = after;
|
|
1460
|
-
continue;
|
|
1461
|
-
}
|
|
1462
|
-
rendered = plaintext;
|
|
1463
|
-
persisted = expression;
|
|
1464
|
-
certified += 1;
|
|
1465
|
-
spans.push([
|
|
1466
|
-
side,
|
|
1467
|
-
side[0].length,
|
|
1468
|
-
plaintext.length
|
|
1469
|
-
]);
|
|
1470
|
-
}
|
|
1471
|
-
side[0] += rendered;
|
|
1472
|
-
side[1] += persisted;
|
|
1473
|
-
}
|
|
1474
|
-
if (certified === 0) return void 0;
|
|
1475
|
-
let persisted;
|
|
1476
|
-
if (!unknown) {
|
|
1477
|
-
if (before[0] !== bag) return void 0;
|
|
1478
|
-
persisted = before[1];
|
|
1479
|
-
} else {
|
|
1480
|
-
if (bag.length < before[0].length + after[0].length) return void 0;
|
|
1481
|
-
if (!bag.startsWith(before[0]) || !bag.endsWith(after[0])) return void 0;
|
|
1482
|
-
const middle = bag.slice(before[0].length, bag.length - after[0].length);
|
|
1483
|
-
if (redactForState(middle, {
|
|
1484
|
-
provenance: "value-scan",
|
|
1485
|
-
secrets
|
|
1486
|
-
}) !== middle) return void 0;
|
|
1487
|
-
persisted = before[1] + middle + after[1];
|
|
1753
|
+
const accountRereadVerdicts = /* @__PURE__ */ new WeakMap();
|
|
1754
|
+
function partRereadsAccountId(part) {
|
|
1755
|
+
let trigger = false;
|
|
1756
|
+
let account = false;
|
|
1757
|
+
const pending = [part];
|
|
1758
|
+
while (pending.length > 0 && !(trigger && account)) {
|
|
1759
|
+
const node = pending.pop();
|
|
1760
|
+
if (Array.isArray(node)) {
|
|
1761
|
+
pending.push(...node);
|
|
1762
|
+
continue;
|
|
1763
|
+
}
|
|
1764
|
+
if (node === null || typeof node !== "object") continue;
|
|
1765
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1766
|
+
if (REREAD_TRIGGERS.has(key)) trigger = true;
|
|
1767
|
+
if (key === "Ref" && value === "AWS::AccountId") account = true;
|
|
1768
|
+
if (key === "Fn::Sub") {
|
|
1769
|
+
const text = Array.isArray(value) ? value[0] : value;
|
|
1770
|
+
if (typeof text === "string" && text.includes("${AWS::AccountId}")) account = true;
|
|
1771
|
+
}
|
|
1772
|
+
pending.push(value);
|
|
1773
|
+
}
|
|
1488
1774
|
}
|
|
1489
|
-
|
|
1490
|
-
return acceptedPlaceholderRendering(bag, persisted, spans.map(([side, offset, length]) => [(side === before ? 0 : afterStart) + offset, length]), secrets);
|
|
1775
|
+
return trigger && account;
|
|
1491
1776
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1777
|
+
const inheritedPseudoParameters = /* @__PURE__ */ new WeakMap();
|
|
1778
|
+
const POISONED_PSEUDO_PARAMETERS = Symbol("cdkd.inherited-pseudo-parameters.poisoned");
|
|
1779
|
+
function recordInheritedPseudoParameters(inheritedSecrets, values) {
|
|
1780
|
+
let table = inheritedPseudoParameters.get(inheritedSecrets);
|
|
1781
|
+
if (table === POISONED_PSEUDO_PARAMETERS) return;
|
|
1782
|
+
if (table === void 0) {
|
|
1783
|
+
table = /* @__PURE__ */ new Map();
|
|
1784
|
+
inheritedPseudoParameters.set(inheritedSecrets, table);
|
|
1785
|
+
}
|
|
1786
|
+
for (const [name, value] of values) {
|
|
1787
|
+
if (!REREAD_PSEUDO_PARAMETERS.has(name) || typeof value !== "string") continue;
|
|
1788
|
+
const known = table.get(name);
|
|
1789
|
+
if (known !== void 0 && known !== value) {
|
|
1790
|
+
inheritedPseudoParameters.set(inheritedSecrets, POISONED_PSEUDO_PARAMETERS);
|
|
1791
|
+
return;
|
|
1498
1792
|
}
|
|
1793
|
+
table.set(name, value);
|
|
1499
1794
|
}
|
|
1500
|
-
if (redactForState(persisted, {
|
|
1501
|
-
provenance: "value-scan",
|
|
1502
|
-
secrets
|
|
1503
|
-
}) !== persisted) return void 0;
|
|
1504
|
-
return persisted;
|
|
1505
1795
|
}
|
|
1506
|
-
function
|
|
1507
|
-
const
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1796
|
+
function pseudoBindingOf(parentSecrets) {
|
|
1797
|
+
const table = inheritedPseudoParameters.get(parentSecrets);
|
|
1798
|
+
return (name) => table instanceof Map && table.has(name) ? { value: table.get(name) } : void 0;
|
|
1799
|
+
}
|
|
1800
|
+
function inheritedPseudoValue(parentSecrets, name) {
|
|
1801
|
+
const bound = pseudoBindingOf(parentSecrets)(name)?.value;
|
|
1802
|
+
return typeof bound === "string" ? bound : void 0;
|
|
1803
|
+
}
|
|
1804
|
+
function inheritedPseudoSpan(childSecrets, key) {
|
|
1805
|
+
const reads = inheritedParameterReads.get(childSecrets);
|
|
1806
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
1807
|
+
for (const name of REREAD_PSEUDO_PARAMETERS) if (crossStackSourceKey({ Ref: name }) === key) return inheritedPseudoValue(reads.parent, name);
|
|
1808
|
+
}
|
|
1809
|
+
const REREAD_TRIGGERS = /* @__PURE__ */ new Set([
|
|
1810
|
+
"Fn::Select",
|
|
1811
|
+
"Fn::Split",
|
|
1812
|
+
"Fn::If"
|
|
1813
|
+
]);
|
|
1814
|
+
|
|
1815
|
+
// src/deployment/secret-redaction/nested-stack/reread.ts
|
|
1816
|
+
const MAX_REREAD_DEPTH = 16;
|
|
1817
|
+
const MAX_REREAD_CONDITIONS = 4;
|
|
1818
|
+
const REREAD_NO_VALUE = Symbol("cdkd.reread.no-value");
|
|
1819
|
+
function splitOutsideDynamicReferences(text, delimiter, standsForSecret) {
|
|
1820
|
+
if (delimiter === "") return text.split(delimiter);
|
|
1821
|
+
const spans = dynamicReferenceSpans(text).filter((span) => {
|
|
1822
|
+
const token = text.slice(span.start, span.end);
|
|
1823
|
+
return spanNamesResolvableService(token) && standsForSecret(token);
|
|
1824
|
+
});
|
|
1825
|
+
if (spans.length === 0) return text.split(delimiter);
|
|
1826
|
+
const pieces = [];
|
|
1512
1827
|
let cursor = 0;
|
|
1513
|
-
let
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
certified.push([start, length]);
|
|
1527
|
-
cursor = start + length;
|
|
1828
|
+
let from = 0;
|
|
1829
|
+
for (;;) {
|
|
1830
|
+
const at = text.indexOf(delimiter, from);
|
|
1831
|
+
if (at === -1) break;
|
|
1832
|
+
const end = at + delimiter.length;
|
|
1833
|
+
const token = spans.find((span) => span.start < end && at < span.end);
|
|
1834
|
+
if (token !== void 0) {
|
|
1835
|
+
from = token.end;
|
|
1836
|
+
continue;
|
|
1837
|
+
}
|
|
1838
|
+
pieces.push(text.slice(cursor, at));
|
|
1839
|
+
cursor = end;
|
|
1840
|
+
from = end;
|
|
1528
1841
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
gaps.push(tail);
|
|
1532
|
-
persisted += tail;
|
|
1533
|
-
for (const gap of gaps) if (redactForState(gap, {
|
|
1534
|
-
provenance: "value-scan",
|
|
1535
|
-
secrets
|
|
1536
|
-
}) !== gap) return void 0;
|
|
1537
|
-
return acceptedPlaceholderRendering(bag, persisted, certified, secrets);
|
|
1842
|
+
pieces.push(text.slice(cursor));
|
|
1843
|
+
return pieces;
|
|
1538
1844
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1845
|
+
function standsForInheritedSecret(parentSecrets, token) {
|
|
1846
|
+
return parentSecrets !== void 0 && resolvedPlaintextOf(parentSecrets, token) !== void 0;
|
|
1847
|
+
}
|
|
1848
|
+
const plainSplit = (text, delimiter) => text.split(delimiter);
|
|
1849
|
+
function evaluatePureRead(node, bind, pseudo, split, choose, depth = 0) {
|
|
1850
|
+
if (depth > MAX_REREAD_DEPTH) return void 0;
|
|
1851
|
+
const evaluate = (child) => evaluatePureRead(child, bind, pseudo, split, choose, depth + 1);
|
|
1852
|
+
if (typeof node === "string") return node.includes("{{resolve:") ? void 0 : { value: node };
|
|
1853
|
+
if (Array.isArray(node)) {
|
|
1854
|
+
const out = [];
|
|
1855
|
+
for (const element of node) {
|
|
1856
|
+
const evaluated = evaluate(element);
|
|
1857
|
+
if (evaluated === void 0 || evaluated.value === REREAD_NO_VALUE) return void 0;
|
|
1858
|
+
out.push(evaluated.value);
|
|
1859
|
+
}
|
|
1860
|
+
return { value: out };
|
|
1861
|
+
}
|
|
1862
|
+
if (!isPlainObject(node)) return void 0;
|
|
1863
|
+
const keys = Object.keys(node);
|
|
1864
|
+
if (keys.length !== 1) return void 0;
|
|
1865
|
+
const key = keys[0];
|
|
1866
|
+
const args = node[key];
|
|
1867
|
+
if (key === "Ref") {
|
|
1868
|
+
if (args === "AWS::NoValue") return { value: REREAD_NO_VALUE };
|
|
1869
|
+
return typeof args === "string" ? bindReadName(args, bind, pseudo) : void 0;
|
|
1870
|
+
}
|
|
1871
|
+
if (key === "Fn::If") {
|
|
1872
|
+
if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return void 0;
|
|
1873
|
+
const tookTrue = choose(args[0], node);
|
|
1874
|
+
if (tookTrue === void 0) return void 0;
|
|
1875
|
+
return evaluate(tookTrue ? args[1] : args[2]);
|
|
1876
|
+
}
|
|
1877
|
+
if (key === "Fn::Sub") return evaluatePureSub(args, bind, pseudo, evaluate);
|
|
1878
|
+
if (!Array.isArray(args) || args.length !== 2) return void 0;
|
|
1879
|
+
if (key === "Fn::Select") {
|
|
1880
|
+
const index = args[0];
|
|
1881
|
+
const position = typeof index === "number" ? index : typeof index === "string" && /^(0|[1-9][0-9]*)$/.test(index) ? Number(index) : void 0;
|
|
1882
|
+
if (position === void 0 || !Number.isSafeInteger(position) || position < 0) return void 0;
|
|
1883
|
+
const list = evaluate(args[1]);
|
|
1884
|
+
if (list === void 0 || !Array.isArray(list.value) || position >= list.value.length) return;
|
|
1885
|
+
return { value: list.value[position] };
|
|
1886
|
+
}
|
|
1887
|
+
const delimiter = args[0];
|
|
1888
|
+
if (typeof delimiter !== "string") return void 0;
|
|
1889
|
+
if (key === "Fn::Split") {
|
|
1890
|
+
const value = evaluate(args[1]);
|
|
1891
|
+
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
1892
|
+
return { value: split(value.value, delimiter) };
|
|
1893
|
+
}
|
|
1894
|
+
if (key === "Fn::Join") {
|
|
1895
|
+
const parts = evaluate(args[1]);
|
|
1896
|
+
if (parts === void 0 || !Array.isArray(parts.value)) return void 0;
|
|
1897
|
+
if (!parts.value.every((part) => typeof part === "string")) return void 0;
|
|
1898
|
+
return { value: parts.value.join(delimiter) };
|
|
1551
1899
|
}
|
|
1552
|
-
return true;
|
|
1553
1900
|
}
|
|
1554
|
-
function
|
|
1555
|
-
|
|
1901
|
+
function evaluatePureSub(args, bind, pseudo, evaluate) {
|
|
1902
|
+
const [text, variables] = typeof args === "string" ? [args, {}] : Array.isArray(args) && args.length === 2 ? [args[0], args[1]] : [void 0, void 0];
|
|
1903
|
+
if (typeof text !== "string" || text.includes("{{resolve:") || !isPlainObject(variables)) return;
|
|
1904
|
+
const bound = /* @__PURE__ */ new Map();
|
|
1905
|
+
for (const [name, variable] of Object.entries(variables)) {
|
|
1906
|
+
const evaluated = evaluate(variable);
|
|
1907
|
+
if (evaluated === void 0 || typeof evaluated.value !== "string") return void 0;
|
|
1908
|
+
bound.set(name, evaluated.value);
|
|
1909
|
+
}
|
|
1910
|
+
let out = "";
|
|
1911
|
+
let cursor = 0;
|
|
1912
|
+
for (const match of text.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
1913
|
+
const name = match[2] ?? "";
|
|
1914
|
+
let replacement;
|
|
1915
|
+
if (match[1] === "!") replacement = `\${${name}}`;
|
|
1916
|
+
else if (name === "") replacement = match[0];
|
|
1917
|
+
else if (bound.has(name)) replacement = bound.get(name);
|
|
1918
|
+
else {
|
|
1919
|
+
if (name.includes(".")) return void 0;
|
|
1920
|
+
const value = bindReadName(name, bind, pseudo);
|
|
1921
|
+
if (value === void 0 || typeof value.value !== "string") return void 0;
|
|
1922
|
+
replacement = value.value;
|
|
1923
|
+
}
|
|
1924
|
+
out += text.slice(cursor, match.index) + replacement;
|
|
1925
|
+
cursor = match.index + match[0].length;
|
|
1926
|
+
}
|
|
1927
|
+
return { value: out + text.slice(cursor) };
|
|
1556
1928
|
}
|
|
1557
|
-
function
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
return certifiedListForLeaf(secrets, association, bag);
|
|
1929
|
+
function bindReadName(name, bind, pseudo) {
|
|
1930
|
+
if (!name.startsWith("AWS::")) return bind(name);
|
|
1931
|
+
return bind(name) === void 0 ? pseudo(name) : void 0;
|
|
1561
1932
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
"Fn::
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
if (depth > 16) return "unknown";
|
|
1573
|
-
if (!isPlainObject(element)) return "never";
|
|
1574
|
-
if (Object.hasOwn(element, "Ref")) return element["Ref"] === "AWS::NoValue" ? "always" : "never";
|
|
1575
|
-
const keys = Object.keys(element);
|
|
1576
|
-
if (keys.filter((key) => key.startsWith("Fn::") || key === "Condition").length === 0) return "never";
|
|
1577
|
-
if (keys.length !== 1) return "unknown";
|
|
1578
|
-
if (NEVER_DROPPING_INTRINSICS.has(keys[0])) return "never";
|
|
1579
|
-
if (keys[0] !== "Fn::If") return "unknown";
|
|
1580
|
-
const args = element["Fn::If"];
|
|
1581
|
-
if (!Array.isArray(args) || args.length !== 3) return "unknown";
|
|
1582
|
-
const branches = [arrayElementDrop(args[1], depth + 1), arrayElementDrop(args[2], depth + 1)];
|
|
1583
|
-
if (branches.includes("unknown")) return "unknown";
|
|
1584
|
-
if (branches.every((branch) => branch === "never")) return "never";
|
|
1585
|
-
if (branches.every((branch) => branch === "always")) return "always";
|
|
1586
|
-
return "maybe";
|
|
1933
|
+
function collectRereadConditions(node, names, depth = 0) {
|
|
1934
|
+
if (depth > MAX_REREAD_DEPTH) return false;
|
|
1935
|
+
if (Array.isArray(node)) return node.every((element) => collectRereadConditions(element, names, depth + 1));
|
|
1936
|
+
if (!isPlainObject(node)) return true;
|
|
1937
|
+
if (Object.hasOwn(node, "Fn::If")) {
|
|
1938
|
+
const args = node["Fn::If"];
|
|
1939
|
+
if (!Array.isArray(args) || typeof args[0] !== "string") return false;
|
|
1940
|
+
names.add(args[0]);
|
|
1941
|
+
}
|
|
1942
|
+
return Object.values(node).every((child) => collectRereadConditions(child, names, depth + 1));
|
|
1587
1943
|
}
|
|
1588
|
-
function
|
|
1589
|
-
|
|
1590
|
-
if (
|
|
1591
|
-
|
|
1592
|
-
|
|
1944
|
+
function holdsRereadTrigger(node, depth = 0) {
|
|
1945
|
+
if (depth > MAX_REREAD_DEPTH) return false;
|
|
1946
|
+
if (Array.isArray(node)) return node.some((element) => holdsRereadTrigger(element, depth + 1));
|
|
1947
|
+
if (!isPlainObject(node)) return false;
|
|
1948
|
+
return Object.entries(node).some(([key, child]) => REREAD_TRIGGERS.has(key) || holdsRereadTrigger(child, depth + 1));
|
|
1949
|
+
}
|
|
1950
|
+
function rendersReadTo(spelling, parentSecrets, value) {
|
|
1951
|
+
if (typeof spelling === "string" && typeof value === "string") {
|
|
1952
|
+
if (literalTextHoldsSubFloorSecret(spelling, parentSecrets)) return false;
|
|
1953
|
+
if (spelling === value) return redactForState(spelling, {
|
|
1954
|
+
provenance: "value-scan",
|
|
1955
|
+
secrets: parentSecrets
|
|
1956
|
+
}) === spelling;
|
|
1957
|
+
return rendersLiteralTo(spelling, parentSecrets, value);
|
|
1593
1958
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
const always = drops.filter((drop) => drop === "always").length;
|
|
1597
|
-
const maybe = drops.filter((drop) => drop === "maybe").length;
|
|
1598
|
-
const dropped = source.length - bagLength;
|
|
1599
|
-
let dropMaybe;
|
|
1600
|
-
if (dropped === always) dropMaybe = false;
|
|
1601
|
-
else if (dropped === always + maybe) dropMaybe = true;
|
|
1602
|
-
else return void 0;
|
|
1603
|
-
return source.filter((_, i) => drops[i] === "never" || drops[i] === "maybe" && !dropMaybe);
|
|
1959
|
+
if (Array.isArray(spelling) && Array.isArray(value) && spelling.length === value.length) return spelling.every((element, i) => rendersReadTo(element, parentSecrets, value[i]));
|
|
1960
|
+
return false;
|
|
1604
1961
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1962
|
+
const REREAD_UNBOUND = Symbol("cdkd.reread.unbound");
|
|
1963
|
+
const REREAD_PARAMETER_FREE = Symbol("cdkd.reread.parameter-free");
|
|
1964
|
+
function diffSideReading(bind, parentSecrets) {
|
|
1965
|
+
return {
|
|
1966
|
+
bind: (name) => {
|
|
1967
|
+
const bound = bind(name);
|
|
1968
|
+
return bound && { value: persistedInheritedParameterValue(parentSecrets, name, bound.value) };
|
|
1969
|
+
},
|
|
1970
|
+
split: (text, delimiter) => splitOutsideDynamicReferences(text, delimiter, (token) => standsForInheritedSecret(parentSecrets, token))
|
|
1971
|
+
};
|
|
1607
1972
|
}
|
|
1608
|
-
function
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1973
|
+
function rereadUnder(source, bind, parentSecrets, choose) {
|
|
1974
|
+
const pseudo = pseudoBindingOf(parentSecrets);
|
|
1975
|
+
const resolved = evaluatePureRead(source, bind, pseudo, plainSplit, choose);
|
|
1976
|
+
if (resolved === void 0) return void 0;
|
|
1977
|
+
const diffSide = diffSideReading(bind, parentSecrets);
|
|
1978
|
+
const redacted = evaluatePureRead(source, diffSide.bind, pseudo, diffSide.split, choose);
|
|
1979
|
+
if (redacted === void 0) return void 0;
|
|
1980
|
+
if (resolved.value === REREAD_NO_VALUE || redacted.value === REREAD_NO_VALUE) return resolved.value === redacted.value ? REREAD_NO_VALUE : void 0;
|
|
1981
|
+
if (!rendersReadTo(redacted.value, parentSecrets, resolved.value)) return void 0;
|
|
1982
|
+
return {
|
|
1983
|
+
resolved: resolved.value,
|
|
1984
|
+
redacted: redacted.value
|
|
1985
|
+
};
|
|
1612
1986
|
}
|
|
1613
|
-
function
|
|
1614
|
-
if (depth >
|
|
1615
|
-
if (typeof
|
|
1616
|
-
|
|
1617
|
-
|
|
1987
|
+
function namesParameterOnBranches(node, choose, isParameter, depth = 0) {
|
|
1988
|
+
if (depth > MAX_REREAD_DEPTH) return true;
|
|
1989
|
+
if (typeof node === "string") return node.includes("{{resolve:");
|
|
1990
|
+
if (Array.isArray(node)) return node.some((element) => namesParameterOnBranches(element, choose, isParameter, depth + 1));
|
|
1991
|
+
if (!isPlainObject(node)) return false;
|
|
1992
|
+
if (Object.hasOwn(node, "Fn::If")) {
|
|
1993
|
+
const args = node["Fn::If"];
|
|
1994
|
+
if (Object.keys(node).length !== 1) return true;
|
|
1995
|
+
if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return true;
|
|
1996
|
+
const tookTrue = choose(args[0], node);
|
|
1997
|
+
if (tookTrue === void 0) return true;
|
|
1998
|
+
return namesParameterOnBranches(tookTrue ? args[1] : args[2], choose, isParameter, depth + 1);
|
|
1618
1999
|
}
|
|
1619
|
-
if (
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
if (
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
function corroboratesWhateverResolves(source, depth = 0) {
|
|
1627
|
-
if (depth > 16) return false;
|
|
1628
|
-
if (typeof source === "string") return !source.includes("{{resolve:");
|
|
1629
|
-
if (source === null || typeof source !== "object") return true;
|
|
1630
|
-
if (isIntrinsicNode(source)) return true;
|
|
1631
|
-
if (Array.isArray(source)) return source.every((element) => arrayElementDrop(element) === "never" && corroboratesWhateverResolves(element, depth + 1));
|
|
1632
|
-
if (!isPlainObject(source)) return false;
|
|
1633
|
-
if (Object.keys(source).some((key) => key === "Ref" || key.startsWith("Fn::"))) return false;
|
|
1634
|
-
return Object.values(source).every((value) => arrayElementDrop(value) !== "unknown" && corroboratesWhateverResolves(value, depth + 1));
|
|
2000
|
+
if (typeof node["Ref"] === "string" && isParameter(node["Ref"])) return true;
|
|
2001
|
+
const sub = node["Fn::Sub"];
|
|
2002
|
+
const text = typeof sub === "string" ? sub : Array.isArray(sub) ? sub[0] : void 0;
|
|
2003
|
+
if (typeof text === "string") {
|
|
2004
|
+
for (const match of text.matchAll(/\$\{([^}!][^}]*)\}/g)) if (isParameter(match[1].trim()) || isParameter(match[1])) return true;
|
|
2005
|
+
}
|
|
2006
|
+
return Object.values(node).some((child) => namesParameterOnBranches(child, choose, isParameter, depth + 1));
|
|
1635
2007
|
}
|
|
1636
|
-
function
|
|
1637
|
-
if (!source
|
|
1638
|
-
|
|
2008
|
+
function rereadAssignments(source, bind, parentSecrets, untakenWhenUnbound = () => false, parameterFree) {
|
|
2009
|
+
if (!holdsRereadTrigger(source)) return void 0;
|
|
2010
|
+
const conditions = /* @__PURE__ */ new Set();
|
|
2011
|
+
if (!collectRereadConditions(source, conditions)) return void 0;
|
|
2012
|
+
if (conditions.size > MAX_REREAD_CONDITIONS) return void 0;
|
|
2013
|
+
const names = [...conditions];
|
|
2014
|
+
const out = [];
|
|
2015
|
+
for (let assignment = 0; assignment < 2 ** names.length; assignment++) {
|
|
2016
|
+
const choose = (condition) => Math.floor(assignment / 2 ** names.indexOf(condition)) % 2 === 1;
|
|
2017
|
+
let unbound = false;
|
|
2018
|
+
const tracked = (name) => {
|
|
2019
|
+
const bound = bind(name);
|
|
2020
|
+
if (bound === void 0 && untakenWhenUnbound(name)) unbound = true;
|
|
2021
|
+
return bound;
|
|
2022
|
+
};
|
|
2023
|
+
const reread = rereadUnder(source, tracked, parentSecrets, choose);
|
|
2024
|
+
if (unbound) out.push(REREAD_UNBOUND);
|
|
2025
|
+
else if (reread !== void 0) out.push(reread);
|
|
2026
|
+
else if (parameterFree !== void 0 && !namesParameterOnBranches(source, choose, parameterFree)) out.push(REREAD_PARAMETER_FREE);
|
|
2027
|
+
else out.push(void 0);
|
|
2028
|
+
}
|
|
2029
|
+
return out;
|
|
1639
2030
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
return
|
|
2031
|
+
function rereadParameterExpression(source, bind, parentSecrets) {
|
|
2032
|
+
const assignments = rereadAssignments(source, bind, parentSecrets, void 0, (name) => bind(name) !== void 0);
|
|
2033
|
+
if (assignments === void 0 || assignments.includes(void 0) || assignments.includes(REREAD_UNBOUND)) return;
|
|
2034
|
+
return assignments.find((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE);
|
|
1644
2035
|
}
|
|
1645
|
-
function
|
|
1646
|
-
|
|
1647
|
-
if (Array.isArray(value)) return value.some(subtreeHasDynamicReference);
|
|
1648
|
-
if (isPlainObject(value)) return Object.values(value).some(subtreeHasDynamicReference);
|
|
1649
|
-
return false;
|
|
2036
|
+
function ambiguousRereads(rereads) {
|
|
2037
|
+
return rereads.some((a, i) => rereads.slice(i + 1).some((b) => deepEqualJsonValue(a.resolved, b.resolved) && !deepEqualJsonValue(a.redacted, b.redacted)));
|
|
1650
2038
|
}
|
|
1651
|
-
function
|
|
1652
|
-
const
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
2039
|
+
function positionByParameterReread(bag, source, secrets) {
|
|
2040
|
+
const reads = inheritedParameterReads.get(secrets);
|
|
2041
|
+
if (reads === void 0 || typeof reads === "symbol") return void 0;
|
|
2042
|
+
if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
|
|
2043
|
+
if (!holdsRereadTrigger(source)) return void 0;
|
|
2044
|
+
const bind = (name) => reads.values.has(name) ? { value: reads.values.get(name) } : void 0;
|
|
2045
|
+
let unrecorded = false;
|
|
2046
|
+
const recorded = rereadUnder(source, bind, reads.parent, (_, node) => {
|
|
2047
|
+
const taken = takenIfBranchOf(secrets, node);
|
|
2048
|
+
if (taken === void 0) unrecorded = true;
|
|
2049
|
+
return taken;
|
|
2050
|
+
});
|
|
2051
|
+
let answer;
|
|
2052
|
+
if (!unrecorded) {
|
|
2053
|
+
if (recorded === void 0 || recorded === REREAD_NO_VALUE || !deepEqualJsonValue(recorded.resolved, bag) && !deepEqualJsonValue(recorded.redacted, bag)) return;
|
|
2054
|
+
answer = recorded.redacted;
|
|
2055
|
+
} else {
|
|
2056
|
+
const declared = reads.declared;
|
|
2057
|
+
const assignments = rereadAssignments(source, bind, reads.parent, (name) => declared?.has(name) === true);
|
|
2058
|
+
if (assignments === void 0 || assignments.includes(void 0)) return void 0;
|
|
2059
|
+
const matching = assignments.filter((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE && deepEqualJsonValue(entry.resolved, bag));
|
|
2060
|
+
if (matching.length === 0 || ambiguousRereads(matching)) return void 0;
|
|
2061
|
+
answer = matching[0].redacted;
|
|
1660
2062
|
}
|
|
1661
|
-
return
|
|
2063
|
+
if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
|
|
2064
|
+
if (!deepEqualJsonValue(redactForState(answer, {
|
|
2065
|
+
provenance: "value-scan",
|
|
2066
|
+
secrets
|
|
2067
|
+
}), answer)) return void 0;
|
|
2068
|
+
return answer;
|
|
1662
2069
|
}
|
|
1663
2070
|
|
|
1664
|
-
// src/deployment/secret-redaction/
|
|
1665
|
-
function
|
|
1666
|
-
const
|
|
1667
|
-
return
|
|
2071
|
+
// src/deployment/secret-redaction/placeholder-positions.ts
|
|
2072
|
+
function keyedPart(source) {
|
|
2073
|
+
const key = crossStackSourceKey(source);
|
|
2074
|
+
return key === void 0 ? UNKNOWN_PART : { key };
|
|
1668
2075
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
return false;
|
|
2076
|
+
const MAX_PLACEHOLDER_DEPTH = 8;
|
|
2077
|
+
function pushPlaceholderPart(out, part, budget) {
|
|
2078
|
+
if (budget.remaining <= 0) {
|
|
2079
|
+
budget.exhausted = true;
|
|
2080
|
+
return;
|
|
1675
2081
|
}
|
|
1676
|
-
|
|
2082
|
+
budget.remaining -= 1;
|
|
2083
|
+
out.push(part);
|
|
1677
2084
|
}
|
|
1678
|
-
function
|
|
1679
|
-
if (
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
2085
|
+
function appendValuePlaceholderParts(value, out, budget, depth) {
|
|
2086
|
+
if (budget.exhausted) return;
|
|
2087
|
+
const literal = joinPartLiteralText(value);
|
|
2088
|
+
if (literal !== void 0) return pushPlaceholderPart(out, literal, budget);
|
|
2089
|
+
if (isPlainObject(value) && Object.keys(value).length === 1) {
|
|
2090
|
+
const ref = value["Ref"];
|
|
2091
|
+
if (typeof ref === "string" && ref !== "") return pushPlaceholderPart(out, keyedPart({ Ref: ref }), budget);
|
|
2092
|
+
if (depth >= MAX_PLACEHOLDER_DEPTH) {
|
|
2093
|
+
budget.exhausted = true;
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
if (appendParameterPlaceholderParts(value, out, budget, depth + 1)) return;
|
|
2097
|
+
return pushPlaceholderPart(out, keyedPart(value), budget);
|
|
1683
2098
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
2099
|
+
pushPlaceholderPart(out, UNKNOWN_PART, budget);
|
|
2100
|
+
}
|
|
2101
|
+
function appendParameterPlaceholderParts(source, out, budget, depth) {
|
|
2102
|
+
const keys = Object.keys(source);
|
|
2103
|
+
if (keys.length !== 1) return false;
|
|
2104
|
+
const key = keys[0];
|
|
2105
|
+
if (key === "Fn::Join") {
|
|
2106
|
+
const args = source[key];
|
|
2107
|
+
if (!Array.isArray(args) || args.length !== 2) return false;
|
|
2108
|
+
const [delimiter, parts] = args;
|
|
2109
|
+
if (typeof delimiter !== "string" || !Array.isArray(parts)) return false;
|
|
2110
|
+
for (let index = 0; index < parts.length && !budget.exhausted; index++) {
|
|
2111
|
+
if (index > 0) pushPlaceholderPart(out, delimiter, budget);
|
|
2112
|
+
appendValuePlaceholderParts(parts[index], out, budget, depth);
|
|
2113
|
+
}
|
|
2114
|
+
return true;
|
|
2115
|
+
}
|
|
2116
|
+
if (key === "Fn::Sub") {
|
|
2117
|
+
const args = source[key];
|
|
2118
|
+
let template;
|
|
2119
|
+
let variables = {};
|
|
2120
|
+
if (typeof args === "string") template = args;
|
|
2121
|
+
else if (Array.isArray(args) && args.length === 2 && isPlainObject(args[1])) {
|
|
2122
|
+
template = args[0];
|
|
2123
|
+
variables = args[1];
|
|
2124
|
+
} else return false;
|
|
2125
|
+
if (typeof template !== "string") return false;
|
|
2126
|
+
let cursor = 0;
|
|
2127
|
+
for (const hit of template.matchAll(/\$\{(!)?([^}]*)\}/g)) {
|
|
2128
|
+
if (budget.exhausted) return true;
|
|
2129
|
+
pushPlaceholderPart(out, template.slice(cursor, hit.index), budget);
|
|
2130
|
+
cursor = hit.index + hit[0].length;
|
|
2131
|
+
const name = hit[2] ?? "";
|
|
2132
|
+
if (hit[1] === "!") pushPlaceholderPart(out, `\${${name}}`, budget);
|
|
2133
|
+
else if (name === "") pushPlaceholderPart(out, hit[0], budget);
|
|
2134
|
+
else if (Object.hasOwn(variables, name)) appendValuePlaceholderParts(variables[name], out, budget, depth);
|
|
2135
|
+
else if (name.includes(".")) pushPlaceholderPart(out, keyedPart({ "Fn::GetAtt": name }), budget);
|
|
2136
|
+
else pushPlaceholderPart(out, keyedPart({ Ref: name }), budget);
|
|
2137
|
+
}
|
|
2138
|
+
pushPlaceholderPart(out, template.slice(cursor), budget);
|
|
2139
|
+
return true;
|
|
1690
2140
|
}
|
|
1691
2141
|
return false;
|
|
1692
2142
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
"DefinitionString",
|
|
1698
|
-
"Definition"
|
|
1699
|
-
];
|
|
1700
|
-
const RENDERED_DEFINITION_KEYS = /* @__PURE__ */ new Set(["Definition", "DefinitionString"]);
|
|
1701
|
-
function definitionSourceCarriesSecret(source) {
|
|
1702
|
-
return DEFINITION_SOURCE_KEYS.some((k) => Object.hasOwn(source, k) && (subtreeHasDynamicReference(source[k]) || carriesSecretMask(source[k])));
|
|
1703
|
-
}
|
|
1704
|
-
function nameScalarSecrets(value, secrets) {
|
|
1705
|
-
const byValue = /* @__PURE__ */ new Set();
|
|
1706
|
-
for (const plaintext of secrets.keys()) try {
|
|
1707
|
-
const parsed = JSON.parse(plaintext);
|
|
1708
|
-
if (typeof parsed === "number" && Number.isFinite(parsed) || typeof parsed === "boolean") byValue.add(parsed);
|
|
1709
|
-
} catch {}
|
|
1710
|
-
if (byValue.size === 0) return value;
|
|
1711
|
-
const walk = (node) => {
|
|
1712
|
-
if (typeof node === "number" || typeof node === "boolean") {
|
|
1713
|
-
if (typeof node === "number" && !Number.isFinite(node)) return node;
|
|
1714
|
-
return secrets.has(String(node)) || byValue.has(node) ? "***" : node;
|
|
1715
|
-
}
|
|
1716
|
-
if (Array.isArray(node)) return node.map(walk);
|
|
1717
|
-
if (isPlainObject(node) && hasPlainPrototype(node)) {
|
|
1718
|
-
const out = Object.create(null);
|
|
1719
|
-
for (const [k, v] of Object.entries(node)) out[k] = walk(v);
|
|
1720
|
-
return out;
|
|
1721
|
-
}
|
|
1722
|
-
return node;
|
|
2143
|
+
function parameterPlaceholderParts(source, bag) {
|
|
2144
|
+
const budget = {
|
|
2145
|
+
remaining: bag.length * 2 + 16,
|
|
2146
|
+
exhausted: false
|
|
1723
2147
|
};
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
const SENTINEL_OUT_OF_STRING = "";
|
|
1728
|
-
function substitutionIsSecret(value) {
|
|
1729
|
-
return subtreeHasDynamicReference(value) || value.includes("***");
|
|
2148
|
+
const out = [];
|
|
2149
|
+
if (!appendParameterPlaceholderParts(source, out, budget, 0)) return void 0;
|
|
2150
|
+
return budget.exhausted ? void 0 : out;
|
|
1730
2151
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const
|
|
1733
|
-
const
|
|
1734
|
-
if (
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
let
|
|
1745
|
-
let
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
} else for (const c of value) feed(c);
|
|
1765
|
-
i = end;
|
|
1766
|
-
continue;
|
|
2152
|
+
function positionByParameterPlaceholders(bag, source, secrets) {
|
|
2153
|
+
const associations = crossStackAssociations.get(secrets);
|
|
2154
|
+
const spanned = positionByRecordedParameterSpans(bag, source, secrets, associations);
|
|
2155
|
+
if (spanned !== void 0) return spanned;
|
|
2156
|
+
const parts = parameterPlaceholderParts(source, bag);
|
|
2157
|
+
if (parts === void 0) return void 0;
|
|
2158
|
+
const before = ["", ""];
|
|
2159
|
+
const after = ["", ""];
|
|
2160
|
+
let side = before;
|
|
2161
|
+
let unknown = false;
|
|
2162
|
+
let certified = 0;
|
|
2163
|
+
const spans = [];
|
|
2164
|
+
for (const part of parts) {
|
|
2165
|
+
let rendered;
|
|
2166
|
+
let persisted;
|
|
2167
|
+
if (typeof part === "string") {
|
|
2168
|
+
rendered = part;
|
|
2169
|
+
persisted = part;
|
|
2170
|
+
} else {
|
|
2171
|
+
let expression;
|
|
2172
|
+
let plaintext = "";
|
|
2173
|
+
if (part !== UNKNOWN_PART) {
|
|
2174
|
+
const association = associations?.get(part.key);
|
|
2175
|
+
if (association !== void 0 && typeof association !== "symbol") {
|
|
2176
|
+
plaintext = association.plaintext;
|
|
2177
|
+
expression = certifiedExpressionForLeaf(secrets, association, plaintext);
|
|
2178
|
+
}
|
|
2179
|
+
if (expression === void 0) {
|
|
2180
|
+
const inherited = inheritedRenderedSpan(secrets, part.key);
|
|
2181
|
+
if (inherited !== void 0) {
|
|
2182
|
+
plaintext = inherited.value;
|
|
2183
|
+
expression = inherited.spelling;
|
|
2184
|
+
}
|
|
1767
2185
|
}
|
|
1768
2186
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
} catch {
|
|
1775
|
-
continue;
|
|
1776
|
-
}
|
|
1777
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1778
|
-
const strings = /* @__PURE__ */ new Set();
|
|
1779
|
-
const scalars = /* @__PURE__ */ new Set();
|
|
1780
|
-
const secretLeaves = [];
|
|
1781
|
-
const marked = (t) => t.includes(SENTINEL_IN_STRING) || t.includes(SENTINEL_OUT_OF_STRING);
|
|
1782
|
-
const outOfString = new RegExp(`^${SENTINEL_OUT_OF_STRING}(\\d+)${SENTINEL_OUT_OF_STRING}$`);
|
|
1783
|
-
const inStringMarkers = new RegExp(`${SENTINEL_IN_STRING}(\\d+)${SENTINEL_IN_STRING}`, "g");
|
|
1784
|
-
const written = (t) => t.replace(inStringMarkers, (_m, i) => `\${${names[Number(i)]}}`);
|
|
1785
|
-
const walk = (node, path, shapes) => {
|
|
1786
|
-
if (typeof node === "string") {
|
|
1787
|
-
const m = outOfString.exec(node);
|
|
1788
|
-
if (m !== null) secretLeaves.push({
|
|
1789
|
-
path,
|
|
1790
|
-
shapes,
|
|
1791
|
-
outOfStringName: names[Number(m[1])],
|
|
1792
|
-
asWritten: void 0
|
|
1793
|
-
});
|
|
1794
|
-
else if (marked(node)) secretLeaves.push({
|
|
1795
|
-
path,
|
|
1796
|
-
shapes,
|
|
1797
|
-
outOfStringName: void 0,
|
|
1798
|
-
asWritten: written(node)
|
|
1799
|
-
});
|
|
1800
|
-
else strings.add(node);
|
|
1801
|
-
return;
|
|
1802
|
-
}
|
|
1803
|
-
if (typeof node === "number" || typeof node === "boolean") {
|
|
1804
|
-
scalars.add(node);
|
|
1805
|
-
return;
|
|
1806
|
-
}
|
|
1807
|
-
if (Array.isArray(node)) {
|
|
1808
|
-
node.forEach((item, i) => walk(item, [...path, i], [...shapes, node.length]));
|
|
1809
|
-
return;
|
|
2187
|
+
const pseudo = expression === void 0 && part !== UNKNOWN_PART ? inheritedPseudoSpan(secrets, part.key) : void 0;
|
|
2188
|
+
if (pseudo !== void 0) {
|
|
2189
|
+
side[0] += pseudo;
|
|
2190
|
+
side[1] += pseudo;
|
|
2191
|
+
continue;
|
|
1810
2192
|
}
|
|
1811
|
-
if (
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
}
|
|
2193
|
+
if (expression === void 0) {
|
|
2194
|
+
if (unknown) return void 0;
|
|
2195
|
+
unknown = true;
|
|
2196
|
+
side = after;
|
|
2197
|
+
continue;
|
|
1817
2198
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
2199
|
+
rendered = plaintext;
|
|
2200
|
+
persisted = expression;
|
|
2201
|
+
certified += 1;
|
|
2202
|
+
spans.push([
|
|
2203
|
+
side,
|
|
2204
|
+
side[0].length,
|
|
2205
|
+
plaintext.length
|
|
2206
|
+
]);
|
|
2207
|
+
}
|
|
2208
|
+
side[0] += rendered;
|
|
2209
|
+
side[1] += persisted;
|
|
2210
|
+
}
|
|
2211
|
+
if (certified === 0) return void 0;
|
|
2212
|
+
let persisted;
|
|
2213
|
+
if (!unknown) {
|
|
2214
|
+
if (before[0] !== bag) return void 0;
|
|
2215
|
+
persisted = before[1];
|
|
2216
|
+
} else {
|
|
2217
|
+
if (bag.length < before[0].length + after[0].length) return void 0;
|
|
2218
|
+
if (!bag.startsWith(before[0]) || !bag.endsWith(after[0])) return void 0;
|
|
2219
|
+
const middle = bag.slice(before[0].length, bag.length - after[0].length);
|
|
2220
|
+
if (redactForState(middle, {
|
|
2221
|
+
provenance: "value-scan",
|
|
2222
|
+
secrets
|
|
2223
|
+
}) !== middle) return void 0;
|
|
2224
|
+
persisted = before[1] + middle + after[1];
|
|
1829
2225
|
}
|
|
2226
|
+
const afterStart = bag.length - after[0].length;
|
|
2227
|
+
return acceptedPlaceholderRendering(bag, persisted, spans.map(([side, offset, length]) => [(side === before ? 0 : afterStart) + offset, length]), secrets);
|
|
1830
2228
|
}
|
|
1831
|
-
function
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
if (
|
|
1837
|
-
cursor = cursor[segment];
|
|
1838
|
-
} else {
|
|
1839
|
-
if (!isPlainObject(cursor)) return void 0;
|
|
1840
|
-
const own = Object.keys(cursor);
|
|
1841
|
-
if (own.length !== shape.size || own.some((k) => !shape.has(k))) return void 0;
|
|
1842
|
-
if (!Object.hasOwn(cursor, segment)) return void 0;
|
|
1843
|
-
cursor = cursor[segment];
|
|
2229
|
+
function acceptedPlaceholderRendering(bag, persisted, spans, secrets) {
|
|
2230
|
+
for (const plaintext of secrets.keys()) {
|
|
2231
|
+
if (plaintext.length < 4) continue;
|
|
2232
|
+
for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
|
|
2233
|
+
const end = at + plaintext.length;
|
|
2234
|
+
for (const [start, length] of spans) if (at < start + length && end > start && (at < start || end > start + length)) return void 0;
|
|
1844
2235
|
}
|
|
1845
2236
|
}
|
|
1846
|
-
|
|
2237
|
+
if (redactForState(persisted, {
|
|
2238
|
+
provenance: "value-scan",
|
|
2239
|
+
secrets
|
|
2240
|
+
}) !== persisted) return void 0;
|
|
2241
|
+
return persisted;
|
|
2242
|
+
}
|
|
2243
|
+
function positionByRecordedParameterSpans(bag, source, secrets, associations) {
|
|
2244
|
+
const resolution = intrinsicLeafResolutionOf(secrets, source);
|
|
2245
|
+
if (resolution === void 0 || resolution.output !== bag) return void 0;
|
|
2246
|
+
const recorded = resolution.parameterSpans;
|
|
2247
|
+
if (recorded === void 0) return void 0;
|
|
2248
|
+
let previousEnd = 0;
|
|
2249
|
+
let cursor = 0;
|
|
2250
|
+
let persisted = "";
|
|
2251
|
+
const gaps = [];
|
|
2252
|
+
const certified = [];
|
|
2253
|
+
for (const { start, length, key } of recorded) {
|
|
2254
|
+
if (!(start >= previousEnd && length > 0 && start + length <= bag.length)) return void 0;
|
|
2255
|
+
previousEnd = start + length;
|
|
2256
|
+
const text = bag.slice(start, start + length);
|
|
2257
|
+
const association = associations?.get(key);
|
|
2258
|
+
const expression = (association !== void 0 && typeof association !== "symbol" ? certifiedExpressionForLeaf(secrets, association, text) : void 0) ?? inheritedRenderedSpan(secrets, key, text)?.spelling;
|
|
2259
|
+
if (expression === void 0) continue;
|
|
2260
|
+
const gap = bag.slice(cursor, start);
|
|
2261
|
+
gaps.push(gap);
|
|
2262
|
+
persisted += gap + expression;
|
|
2263
|
+
certified.push([start, length]);
|
|
2264
|
+
cursor = start + length;
|
|
2265
|
+
}
|
|
2266
|
+
if (certified.length === 0) return void 0;
|
|
2267
|
+
const tail = bag.slice(cursor);
|
|
2268
|
+
gaps.push(tail);
|
|
2269
|
+
persisted += tail;
|
|
2270
|
+
for (const gap of gaps) if (redactForState(gap, {
|
|
2271
|
+
provenance: "value-scan",
|
|
2272
|
+
secrets
|
|
2273
|
+
}) !== gap) return void 0;
|
|
2274
|
+
return acceptedPlaceholderRendering(bag, persisted, certified, secrets);
|
|
1847
2275
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2276
|
+
|
|
2277
|
+
// src/deployment/secret-redaction/identity-keys.ts
|
|
2278
|
+
const ARRAY_IDENTITY_KEYS = ["Name", "Key"];
|
|
2279
|
+
function isUniquelyKeyedBy(items, key) {
|
|
2280
|
+
if (items.length === 0) return false;
|
|
2281
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2282
|
+
for (const item of items) {
|
|
2283
|
+
if (!isPlainObject(item) || !Object.hasOwn(item, key)) return false;
|
|
2284
|
+
const id = item[key];
|
|
2285
|
+
if (typeof id !== "string" || id === "") return false;
|
|
2286
|
+
if (seen.has(id)) return false;
|
|
2287
|
+
seen.add(id);
|
|
1853
2288
|
}
|
|
2289
|
+
return true;
|
|
1854
2290
|
}
|
|
1855
|
-
function
|
|
1856
|
-
const
|
|
1857
|
-
collectObjectKeys(properties, keys);
|
|
1858
|
-
for (const key of sentinelDefinitionOf(properties)?.keys ?? []) keys.add(key);
|
|
1859
|
-
return keys;
|
|
1860
|
-
}
|
|
1861
|
-
function someKeyIsUnspelled(value, spelled) {
|
|
1862
|
-
if (Array.isArray(value)) return value.some((item) => someKeyIsUnspelled(item, spelled));
|
|
1863
|
-
if (isPlainObject(value)) return Object.entries(value).some(([k, v]) => !spelled(k) || someKeyIsUnspelled(v, spelled));
|
|
1864
|
-
return false;
|
|
1865
|
-
}
|
|
1866
|
-
function nameDefinitionSecrets(value, source, secrets) {
|
|
1867
|
-
if (value === null || typeof value !== "object") return value;
|
|
1868
|
-
const sentinel = sentinelDefinitionOf(source);
|
|
1869
|
-
if (sentinel === void 0) {
|
|
1870
|
-
const plaintexts = [...secrets.keys()].filter((p) => p !== "");
|
|
1871
|
-
const keyHoldsSecret = (key) => plaintexts.some((p) => key === p || p.length >= 4 && key.includes(p));
|
|
1872
|
-
if (someKeyIsUnspelled(value, (key) => !keyHoldsSecret(key))) return "***";
|
|
1873
|
-
return nameScalarSecrets(value, secrets);
|
|
1874
|
-
}
|
|
1875
|
-
if (someKeyIsUnspelled(value, (key) => sentinel.keys.has(key))) return "***";
|
|
1876
|
-
let out = value;
|
|
1877
|
-
for (const leaf of sentinel.secretLeaves) {
|
|
1878
|
-
if (alignedSecretLeaf(out, leaf) === void 0) return "***";
|
|
1879
|
-
if (leaf.outOfStringName !== void 0) out = replaceAtPath(out, leaf.path, "***");
|
|
1880
|
-
}
|
|
1881
|
-
return out;
|
|
2291
|
+
function identityKeyFor(bag, source) {
|
|
2292
|
+
for (const key of ARRAY_IDENTITY_KEYS) if (isUniquelyKeyedBy(bag, key) && isUniquelyKeyedBy(source, key)) return key;
|
|
1882
2293
|
}
|
|
1883
|
-
function
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
const copy = [...root];
|
|
1888
|
-
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
1889
|
-
return copy;
|
|
1890
|
-
}
|
|
1891
|
-
const copy = Object.create(null);
|
|
1892
|
-
Object.assign(copy, root);
|
|
1893
|
-
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
1894
|
-
return copy;
|
|
2294
|
+
function positionListByCrossStackSource(bag, source, secrets) {
|
|
2295
|
+
const association = associationForSource(source, secrets);
|
|
2296
|
+
if (association === void 0) return void 0;
|
|
2297
|
+
return certifiedListForLeaf(secrets, association, bag);
|
|
1895
2298
|
}
|
|
1896
2299
|
|
|
1897
|
-
// src/deployment/secret-redaction/redact-path/
|
|
1898
|
-
|
|
1899
|
-
|
|
2300
|
+
// src/deployment/secret-redaction/redact-path/array-drop.ts
|
|
2301
|
+
const NEVER_DROPPING_INTRINSICS = /* @__PURE__ */ new Set([
|
|
2302
|
+
"Fn::Join",
|
|
2303
|
+
"Fn::Sub",
|
|
2304
|
+
"Fn::Select",
|
|
2305
|
+
"Fn::Split",
|
|
2306
|
+
"Fn::GetAtt"
|
|
2307
|
+
]);
|
|
2308
|
+
function arrayElementDrop(element, depth = 0) {
|
|
2309
|
+
if (depth > 16) return "unknown";
|
|
2310
|
+
if (!isPlainObject(element)) return "never";
|
|
2311
|
+
if (Object.hasOwn(element, "Ref")) return element["Ref"] === "AWS::NoValue" ? "always" : "never";
|
|
2312
|
+
const keys = Object.keys(element);
|
|
2313
|
+
if (keys.filter((key) => key.startsWith("Fn::") || key === "Condition").length === 0) return "never";
|
|
2314
|
+
if (keys.length !== 1) return "unknown";
|
|
2315
|
+
if (NEVER_DROPPING_INTRINSICS.has(keys[0])) return "never";
|
|
2316
|
+
if (keys[0] !== "Fn::If") return "unknown";
|
|
2317
|
+
const args = element["Fn::If"];
|
|
2318
|
+
if (!Array.isArray(args) || args.length !== 3) return "unknown";
|
|
2319
|
+
const branches = [arrayElementDrop(args[1], depth + 1), arrayElementDrop(args[2], depth + 1)];
|
|
2320
|
+
if (branches.includes("unknown")) return "unknown";
|
|
2321
|
+
if (branches.every((branch) => branch === "never")) return "never";
|
|
2322
|
+
if (branches.every((branch) => branch === "always")) return "always";
|
|
2323
|
+
return "maybe";
|
|
1900
2324
|
}
|
|
1901
|
-
function
|
|
1902
|
-
const
|
|
1903
|
-
|
|
1904
|
-
if (
|
|
1905
|
-
|
|
1906
|
-
pairs.push([expression, plaintext]);
|
|
2325
|
+
function sourceElementsKeptFor(source, bagLength, secrets) {
|
|
2326
|
+
const recorded = secrets && droppedArrayElementsOf(secrets, source);
|
|
2327
|
+
if (recorded !== void 0) {
|
|
2328
|
+
if (source.length - recorded.length !== bagLength) return void 0;
|
|
2329
|
+
return source.filter((_, i) => !recorded.includes(i));
|
|
1907
2330
|
}
|
|
1908
|
-
|
|
2331
|
+
const drops = source.map((element) => arrayElementDrop(element));
|
|
2332
|
+
if (drops.includes("unknown")) return void 0;
|
|
2333
|
+
const always = drops.filter((drop) => drop === "always").length;
|
|
2334
|
+
const maybe = drops.filter((drop) => drop === "maybe").length;
|
|
2335
|
+
const dropped = source.length - bagLength;
|
|
2336
|
+
let dropMaybe;
|
|
2337
|
+
if (dropped === always) dropMaybe = false;
|
|
2338
|
+
else if (dropped === always + maybe) dropMaybe = true;
|
|
2339
|
+
else return void 0;
|
|
2340
|
+
return source.filter((_, i) => drops[i] === "never" || drops[i] === "maybe" && !dropMaybe);
|
|
1909
2341
|
}
|
|
1910
|
-
function
|
|
1911
|
-
|
|
1912
|
-
if (!isDynamicReferenceString(bag) || isDynamicReferenceString(source)) return void 0;
|
|
1913
|
-
if (rules.sourceIsTemplate !== true && secrets.has(source)) return void 0;
|
|
1914
|
-
let rendered = bag;
|
|
1915
|
-
for (const [expression, plaintext] of secretRerenderPairs(secrets)) rendered = rendered.split(expression).join(plaintext);
|
|
1916
|
-
return rendered === source ? source : void 0;
|
|
2342
|
+
function keptLiteralsCorroborate(kept, bag, secrets) {
|
|
2343
|
+
return kept.every((element, i) => keptElementCorroborates(element, bag[i], secrets));
|
|
1917
2344
|
}
|
|
1918
|
-
function
|
|
1919
|
-
if (
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
return rerenderedSourceLiteral(raw, template, secrets, TEMPLATE_SOURCE) ?? redacted;
|
|
1923
|
-
}
|
|
1924
|
-
if (Array.isArray(raw)) {
|
|
1925
|
-
if (!Array.isArray(template) || !Array.isArray(redacted)) return redacted;
|
|
1926
|
-
if (redacted.length !== raw.length || template.length !== raw.length) return redacted;
|
|
1927
|
-
let out;
|
|
1928
|
-
for (let i = 0; i < redacted.length; i++) {
|
|
1929
|
-
const kept = keepTemplateLiteralLeaves(redacted[i], raw[i], template[i], secrets);
|
|
1930
|
-
if (kept !== redacted[i]) (out ??= [...redacted])[i] = kept;
|
|
1931
|
-
}
|
|
1932
|
-
return out ?? redacted;
|
|
1933
|
-
}
|
|
1934
|
-
if (!isPlainRecord(raw) || !isPlainRecord(template) || !isPlainRecord(redacted)) return redacted;
|
|
1935
|
-
let out;
|
|
1936
|
-
for (const key of Object.keys(redacted)) {
|
|
1937
|
-
if (!Object.hasOwn(raw, key) || !Object.hasOwn(template, key)) continue;
|
|
1938
|
-
const kept = keepTemplateLiteralLeaves(redacted[key], raw[key], template[key], secrets);
|
|
1939
|
-
if (kept === redacted[key]) continue;
|
|
1940
|
-
out ??= { ...redacted };
|
|
1941
|
-
out[key] = kept;
|
|
1942
|
-
}
|
|
1943
|
-
return out ?? redacted;
|
|
2345
|
+
function isIntrinsicNode(value) {
|
|
2346
|
+
if (!isPlainObject(value)) return false;
|
|
2347
|
+
const keys = Object.keys(value);
|
|
2348
|
+
return keys.length === 1 && (keys[0] === "Ref" || keys[0].startsWith("Fn::"));
|
|
1944
2349
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
|
|
2350
|
+
function keptElementCorroborates(source, bag, secrets, depth = 0) {
|
|
2351
|
+
if (depth > 16) return false;
|
|
2352
|
+
if (typeof source === "string") {
|
|
2353
|
+
if (!source.includes("{{resolve:")) return source === bag;
|
|
2354
|
+
return isSingleDynamicReferenceToken(source) && resolvedPlaintextOf(secrets, source) === bag;
|
|
2355
|
+
}
|
|
2356
|
+
if (source === null || typeof source !== "object") return source === bag;
|
|
2357
|
+
if (isIntrinsicNode(source)) return true;
|
|
2358
|
+
if (Array.isArray(source)) return Array.isArray(bag) && bag.length === source.length && source.every((element, i) => keptElementCorroborates(element, bag[i], secrets, depth + 1));
|
|
2359
|
+
if (!isPlainObject(source) || !isPlainObject(bag)) return false;
|
|
2360
|
+
if (Object.keys(bag).some((key) => !Object.hasOwn(source, key))) return false;
|
|
2361
|
+
return Object.entries(source).every(([key, value]) => Object.hasOwn(bag, key) ? keptElementCorroborates(value, bag[key], secrets, depth + 1) : arrayElementDrop(value) === "always" || arrayElementDrop(value) === "maybe");
|
|
1953
2362
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2363
|
+
function corroboratesWhateverResolves(source, depth = 0) {
|
|
2364
|
+
if (depth > 16) return false;
|
|
2365
|
+
if (typeof source === "string") return !source.includes("{{resolve:");
|
|
2366
|
+
if (source === null || typeof source !== "object") return true;
|
|
2367
|
+
if (isIntrinsicNode(source)) return true;
|
|
2368
|
+
if (Array.isArray(source)) return source.every((element) => arrayElementDrop(element) === "never" && corroboratesWhateverResolves(element, depth + 1));
|
|
2369
|
+
if (!isPlainObject(source)) return false;
|
|
2370
|
+
if (Object.keys(source).some((key) => key === "Ref" || key.startsWith("Fn::"))) return false;
|
|
2371
|
+
return Object.values(source).every((value) => arrayElementDrop(value) !== "unknown" && corroboratesWhateverResolves(value, depth + 1));
|
|
1959
2372
|
}
|
|
1960
|
-
function
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
for (const match of value.matchAll(DYNAMIC_REFERENCE_TOKEN_SCAN)) spans.push({
|
|
1964
|
-
start: match.index,
|
|
1965
|
-
end: match.index + match[0].length
|
|
1966
|
-
});
|
|
1967
|
-
return spans;
|
|
2373
|
+
function arrayPairsWhateverDrops(source) {
|
|
2374
|
+
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;
|
|
2375
|
+
return source.every((element) => corroboratesWhateverResolves(element));
|
|
1968
2376
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2377
|
+
|
|
2378
|
+
// src/deployment/secret-redaction/redact-path/subtree.ts
|
|
2379
|
+
function isReadbackProjectedFromState(rules) {
|
|
2380
|
+
return rules.trustAnyExpression && !rules.descendArrays && rules.sourceIsSameGeneration;
|
|
1972
2381
|
}
|
|
1973
|
-
function
|
|
1974
|
-
|
|
1975
|
-
if (
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
if (!token.startsWith("{{resolve:ssm:")) return false;
|
|
1979
|
-
const value = provenPublicValue(secrets, token);
|
|
1980
|
-
if (value === void 0) return false;
|
|
1981
|
-
values.set(token, value);
|
|
1982
|
-
}
|
|
1983
|
-
DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = 0;
|
|
1984
|
-
return source.replace(DYNAMIC_REFERENCE_TOKEN_SCAN, (token) => values.get(token)) === readback;
|
|
2382
|
+
function subtreeHasDynamicReference(value) {
|
|
2383
|
+
if (isDynamicReferenceString(value)) return true;
|
|
2384
|
+
if (Array.isArray(value)) return value.some(subtreeHasDynamicReference);
|
|
2385
|
+
if (isPlainObject(value)) return Object.values(value).some(subtreeHasDynamicReference);
|
|
2386
|
+
return false;
|
|
1985
2387
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
return renderLeaf(bag, source, secrets, scan);
|
|
1996
|
-
} finally {
|
|
1997
|
-
walking = void 0;
|
|
2388
|
+
function pathCrossesDottedKey(bag, path) {
|
|
2389
|
+
const segments = path.split(".");
|
|
2390
|
+
let cursor = bag;
|
|
2391
|
+
for (let i = 0; i < segments.length; i++) {
|
|
2392
|
+
if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor)) return false;
|
|
2393
|
+
const rest = segments.slice(i).join(".");
|
|
2394
|
+
for (const key of Object.keys(cursor)) if (key.includes(".") && (rest === key || rest.startsWith(`${key}.`))) return true;
|
|
2395
|
+
if (!Object.hasOwn(cursor, segments[i])) return false;
|
|
2396
|
+
cursor = cursor[segments[i]];
|
|
1998
2397
|
}
|
|
2398
|
+
return false;
|
|
1999
2399
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2400
|
+
|
|
2401
|
+
// src/deployment/secret-redaction/redact-path/definition.ts
|
|
2402
|
+
const DEFINITION_SOURCE_KEYS = [
|
|
2403
|
+
"DefinitionSubstitutions",
|
|
2404
|
+
"DefinitionString",
|
|
2405
|
+
"Definition"
|
|
2406
|
+
];
|
|
2407
|
+
const RENDERED_DEFINITION_KEYS = /* @__PURE__ */ new Set(["Definition", "DefinitionString"]);
|
|
2408
|
+
function definitionSourceCarriesSecret(source) {
|
|
2409
|
+
return DEFINITION_SOURCE_KEYS.some((k) => Object.hasOwn(source, k) && (subtreeHasDynamicReference(source[k]) || carriesSecretMask(source[k])));
|
|
2410
|
+
}
|
|
2411
|
+
function nameScalarSecrets(value, secrets) {
|
|
2412
|
+
const byValue = /* @__PURE__ */ new Set();
|
|
2413
|
+
for (const plaintext of secrets.keys()) try {
|
|
2414
|
+
const parsed = JSON.parse(plaintext);
|
|
2415
|
+
if (typeof parsed === "number" && Number.isFinite(parsed) || typeof parsed === "boolean") byValue.add(parsed);
|
|
2416
|
+
} catch {}
|
|
2417
|
+
if (byValue.size === 0) return value;
|
|
2418
|
+
const walk = (node) => {
|
|
2419
|
+
if (typeof node === "number" || typeof node === "boolean") {
|
|
2420
|
+
if (typeof node === "number" && !Number.isFinite(node)) return node;
|
|
2421
|
+
return secrets.has(String(node)) || byValue.has(node) ? "***" : node;
|
|
2013
2422
|
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
const spelled = placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
|
|
2020
|
-
if (spelled !== void 0) spellings.add(spelled);
|
|
2423
|
+
if (Array.isArray(node)) return node.map(walk);
|
|
2424
|
+
if (isPlainObject(node) && hasPlainPrototype(node)) {
|
|
2425
|
+
const out = Object.create(null);
|
|
2426
|
+
for (const [k, v] of Object.entries(node)) out[k] = walk(v);
|
|
2427
|
+
return out;
|
|
2021
2428
|
}
|
|
2022
|
-
return
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
if (segments === void 0) return void 0;
|
|
2026
|
-
return placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
|
|
2429
|
+
return node;
|
|
2430
|
+
};
|
|
2431
|
+
return walk(value);
|
|
2027
2432
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
let segments;
|
|
2033
|
-
try {
|
|
2034
|
-
segments = renderSegments(node, 0);
|
|
2035
|
-
} finally {
|
|
2036
|
-
walking = outer;
|
|
2037
|
-
visits = outerVisits;
|
|
2038
|
-
}
|
|
2039
|
-
if (segments === void 0) return void 0;
|
|
2040
|
-
let text = "";
|
|
2041
|
-
for (const segment of segments) {
|
|
2042
|
-
if (!("text" in segment)) return void 0;
|
|
2043
|
-
text += segment.text;
|
|
2044
|
-
}
|
|
2045
|
-
return text;
|
|
2433
|
+
const SENTINEL_IN_STRING = "";
|
|
2434
|
+
const SENTINEL_OUT_OF_STRING = "";
|
|
2435
|
+
function substitutionIsSecret(value) {
|
|
2436
|
+
return subtreeHasDynamicReference(value) || value.includes("***");
|
|
2046
2437
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
return run();
|
|
2053
|
-
} finally {
|
|
2054
|
-
suspended--;
|
|
2438
|
+
function sentinelDefinitionOf(source) {
|
|
2439
|
+
const subs = source["DefinitionSubstitutions"];
|
|
2440
|
+
const values = /* @__PURE__ */ new Map();
|
|
2441
|
+
if (isPlainObject(subs)) {
|
|
2442
|
+
for (const [name, value] of Object.entries(subs)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values.set(name, String(value));
|
|
2055
2443
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2444
|
+
for (const key of ["DefinitionString", "Definition"]) {
|
|
2445
|
+
if (!Object.hasOwn(source, key)) continue;
|
|
2446
|
+
const raw = source[key];
|
|
2447
|
+
const body = typeof raw === "string" ? raw : isPlainObject(raw) ? JSON.stringify(raw) : void 0;
|
|
2448
|
+
if (body === void 0) continue;
|
|
2449
|
+
if (body.includes(SENTINEL_IN_STRING) || body.includes(SENTINEL_OUT_OF_STRING) || /\\u[eE]00[01]/.test(body)) continue;
|
|
2450
|
+
const names = [];
|
|
2451
|
+
let text = "";
|
|
2452
|
+
let inString = false;
|
|
2453
|
+
let escaped = false;
|
|
2454
|
+
const feed = (c) => {
|
|
2455
|
+
text += c;
|
|
2456
|
+
if (inString) {
|
|
2457
|
+
if (escaped) escaped = false;
|
|
2458
|
+
else if (c === "\\") escaped = true;
|
|
2459
|
+
else if (c === "\"") inString = false;
|
|
2460
|
+
} else if (c === "\"") inString = true;
|
|
2461
|
+
};
|
|
2462
|
+
for (let i = 0; i < body.length; i++) {
|
|
2463
|
+
if (body.startsWith("${", i)) {
|
|
2464
|
+
const end = body.indexOf("}", i + 2);
|
|
2465
|
+
const name = end === -1 ? void 0 : body.slice(i + 2, end);
|
|
2466
|
+
const value = name === void 0 ? void 0 : values.get(name);
|
|
2467
|
+
if (name !== void 0 && value !== void 0) {
|
|
2468
|
+
if (substitutionIsSecret(value)) {
|
|
2469
|
+
const index = names.push(name) - 1;
|
|
2470
|
+
text += inString ? `${SENTINEL_IN_STRING}${index}${SENTINEL_IN_STRING}` : `"${SENTINEL_OUT_OF_STRING}${index}${SENTINEL_OUT_OF_STRING}"`;
|
|
2471
|
+
} else for (const c of value) feed(c);
|
|
2472
|
+
i = end;
|
|
2473
|
+
continue;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
feed(body[i]);
|
|
2477
|
+
}
|
|
2478
|
+
let parsed;
|
|
2479
|
+
try {
|
|
2480
|
+
parsed = JSON.parse(text);
|
|
2481
|
+
} catch {
|
|
2069
2482
|
continue;
|
|
2070
2483
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2484
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2485
|
+
const strings = /* @__PURE__ */ new Set();
|
|
2486
|
+
const scalars = /* @__PURE__ */ new Set();
|
|
2487
|
+
const secretLeaves = [];
|
|
2488
|
+
const marked = (t) => t.includes(SENTINEL_IN_STRING) || t.includes(SENTINEL_OUT_OF_STRING);
|
|
2489
|
+
const outOfString = new RegExp(`^${SENTINEL_OUT_OF_STRING}(\\d+)${SENTINEL_OUT_OF_STRING}$`);
|
|
2490
|
+
const inStringMarkers = new RegExp(`${SENTINEL_IN_STRING}(\\d+)${SENTINEL_IN_STRING}`, "g");
|
|
2491
|
+
const written = (t) => t.replace(inStringMarkers, (_m, i) => `\${${names[Number(i)]}}`);
|
|
2492
|
+
const walk = (node, path, shapes) => {
|
|
2493
|
+
if (typeof node === "string") {
|
|
2494
|
+
const m = outOfString.exec(node);
|
|
2495
|
+
if (m !== null) secretLeaves.push({
|
|
2496
|
+
path,
|
|
2497
|
+
shapes,
|
|
2498
|
+
outOfStringName: names[Number(m[1])],
|
|
2499
|
+
asWritten: void 0
|
|
2500
|
+
});
|
|
2501
|
+
else if (marked(node)) secretLeaves.push({
|
|
2502
|
+
path,
|
|
2503
|
+
shapes,
|
|
2504
|
+
outOfStringName: void 0,
|
|
2505
|
+
asWritten: written(node)
|
|
2506
|
+
});
|
|
2507
|
+
else strings.add(node);
|
|
2508
|
+
return;
|
|
2509
|
+
}
|
|
2510
|
+
if (typeof node === "number" || typeof node === "boolean") {
|
|
2511
|
+
scalars.add(node);
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
if (Array.isArray(node)) {
|
|
2515
|
+
node.forEach((item, i) => walk(item, [...path, i], [...shapes, node.length]));
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
if (isPlainObject(node)) {
|
|
2519
|
+
const own = new Set(Object.keys(node).map(written));
|
|
2520
|
+
for (const [k, v] of Object.entries(node)) {
|
|
2521
|
+
if (!marked(k)) keys.add(k);
|
|
2522
|
+
walk(v, [...path, written(k)], [...shapes, own]);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2075
2525
|
};
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
}
|
|
2086
|
-
if (current !== void 0) anchors.push(current);
|
|
2087
|
-
if (!leadingGap && !trailingGap && anchors.length <= 1) {
|
|
2088
|
-
const only = anchors[0] ?? {
|
|
2089
|
-
rendered: "",
|
|
2090
|
-
persisted: ""
|
|
2526
|
+
walk(parsed, [], []);
|
|
2527
|
+
try {
|
|
2528
|
+
collectObjectKeys(JSON.parse(body), keys);
|
|
2529
|
+
} catch {}
|
|
2530
|
+
return {
|
|
2531
|
+
keys,
|
|
2532
|
+
strings,
|
|
2533
|
+
scalars,
|
|
2534
|
+
secretLeaves
|
|
2091
2535
|
};
|
|
2092
|
-
return only.rendered === bag ? only.persisted : void 0;
|
|
2093
|
-
}
|
|
2094
|
-
if (!anchors.some((a) => a.rendered.length > 0)) return void 0;
|
|
2095
|
-
const leftmost = placements(anchors, bag, leadingGap, trailingGap, "left");
|
|
2096
|
-
const rightmost = placements(anchors, bag, leadingGap, trailingGap, "right");
|
|
2097
|
-
if (leftmost === void 0 || rightmost === void 0) return void 0;
|
|
2098
|
-
if (leftmost.some((at, i) => at !== rightmost[i])) return void 0;
|
|
2099
|
-
const gaps = [];
|
|
2100
|
-
const gapRanges = [];
|
|
2101
|
-
let persisted = "";
|
|
2102
|
-
let cursor = 0;
|
|
2103
|
-
for (let i = 0; i < anchors.length; i++) {
|
|
2104
|
-
const at = leftmost[i];
|
|
2105
|
-
if (i > 0 || leadingGap) {
|
|
2106
|
-
const gap = bag.slice(cursor, at);
|
|
2107
|
-
gaps.push(gap);
|
|
2108
|
-
gapRanges.push([cursor, at]);
|
|
2109
|
-
persisted += gap;
|
|
2110
|
-
} else if (at !== 0) return;
|
|
2111
|
-
persisted += anchors[i].persisted;
|
|
2112
|
-
cursor = at + anchors[i].rendered.length;
|
|
2113
|
-
}
|
|
2114
|
-
if (trailingGap) {
|
|
2115
|
-
const gap = bag.slice(cursor);
|
|
2116
|
-
gaps.push(gap);
|
|
2117
|
-
gapRanges.push([cursor, bag.length]);
|
|
2118
|
-
persisted += gap;
|
|
2119
|
-
} else if (cursor !== bag.length) return;
|
|
2120
|
-
if (gaps.some((gap) => scan(gap) !== gap)) return void 0;
|
|
2121
|
-
const copyRanges = [];
|
|
2122
|
-
for (const copy of physicalNameCopies) {
|
|
2123
|
-
if (copy === "") continue;
|
|
2124
|
-
for (let at = bag.indexOf(copy); at !== -1; at = bag.indexOf(copy, at + 1)) copyRanges.push([at, at + copy.length]);
|
|
2125
|
-
}
|
|
2126
|
-
for (const plaintext of plaintexts) {
|
|
2127
|
-
if (plaintext === "") continue;
|
|
2128
|
-
for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
|
|
2129
|
-
const end = at + plaintext.length;
|
|
2130
|
-
if (!gapRanges.some(([from, to]) => at < to && end > from)) continue;
|
|
2131
|
-
if (!copyRanges.some(([from, to]) => at >= from && end <= to && gapRanges.some(([g0, g1]) => from >= g0 && to <= g1))) return void 0;
|
|
2132
|
-
}
|
|
2133
2536
|
}
|
|
2134
|
-
return persisted;
|
|
2135
2537
|
}
|
|
2136
|
-
function
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
if (pinnedEnd && at + text.length !== bag.length) return void 0;
|
|
2150
|
-
out[i] = at;
|
|
2151
|
-
cursor = at + text.length;
|
|
2538
|
+
function alignedSecretLeaf(root, leaf) {
|
|
2539
|
+
let cursor = root;
|
|
2540
|
+
for (const [depth, segment] of leaf.path.entries()) {
|
|
2541
|
+
const shape = leaf.shapes[depth];
|
|
2542
|
+
if (typeof shape === "number") {
|
|
2543
|
+
if (!Array.isArray(cursor) || cursor.length !== shape) return void 0;
|
|
2544
|
+
cursor = cursor[segment];
|
|
2545
|
+
} else {
|
|
2546
|
+
if (!isPlainObject(cursor)) return void 0;
|
|
2547
|
+
const own = Object.keys(cursor);
|
|
2548
|
+
if (own.length !== shape.size || own.some((k) => !shape.has(k))) return void 0;
|
|
2549
|
+
if (!Object.hasOwn(cursor, segment)) return void 0;
|
|
2550
|
+
cursor = cursor[segment];
|
|
2152
2551
|
}
|
|
2153
|
-
return out;
|
|
2154
|
-
}
|
|
2155
|
-
let limit = bag.length;
|
|
2156
|
-
for (let i = anchors.length - 1; i >= 0; i--) {
|
|
2157
|
-
const text = anchors[i].rendered;
|
|
2158
|
-
const pinnedStart = i === 0 && !leadingGap;
|
|
2159
|
-
const pinnedEnd = i === anchors.length - 1 && !trailingGap;
|
|
2160
|
-
let at;
|
|
2161
|
-
if (pinnedEnd) at = bag.length - text.length;
|
|
2162
|
-
else if (pinnedStart) at = 0;
|
|
2163
|
-
else at = limit - text.length < 0 ? -1 : bag.lastIndexOf(text, limit - text.length);
|
|
2164
|
-
if (at < 0 || at + text.length > limit || bag.slice(at, at + text.length) !== text) return;
|
|
2165
|
-
if (pinnedStart && at !== 0) return void 0;
|
|
2166
|
-
out[i] = at;
|
|
2167
|
-
limit = at;
|
|
2168
2552
|
}
|
|
2169
|
-
return
|
|
2170
|
-
}
|
|
2171
|
-
function isNoValue(node) {
|
|
2172
|
-
return isPlainObject(node) && Object.keys(node).length === 1 && node["Ref"] === "AWS::NoValue";
|
|
2553
|
+
return { value: cursor };
|
|
2173
2554
|
}
|
|
2174
|
-
|
|
2175
|
-
const
|
|
2176
|
-
const
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
function renderSegments(node, depth) {
|
|
2180
|
-
if (depth === 0) visits = 0;
|
|
2181
|
-
if (++visits > MAX_VISITS) return void 0;
|
|
2182
|
-
if (depth > MAX_DEPTH) return void 0;
|
|
2183
|
-
if (typeof node === "string") return stringSegments(node);
|
|
2184
|
-
if (typeof node === "number" || typeof node === "boolean") return [{ text: String(node) }];
|
|
2185
|
-
if (!isPlainObject(node) || Object.keys(node).length !== 1) return GAP;
|
|
2186
|
-
const [key] = Object.keys(node);
|
|
2187
|
-
const args = node[key];
|
|
2188
|
-
if (key === "Fn::Join") {
|
|
2189
|
-
if (!Array.isArray(args) || args.length !== 2) return GAP;
|
|
2190
|
-
const [delimiter, list] = args;
|
|
2191
|
-
if (typeof delimiter !== "string" || !Array.isArray(list)) return GAP;
|
|
2192
|
-
const glue = stringSegments(delimiter);
|
|
2193
|
-
if (glue === void 0) return void 0;
|
|
2194
|
-
const out = [];
|
|
2195
|
-
const parts = list;
|
|
2196
|
-
for (let i = 0; i < parts.length; i++) {
|
|
2197
|
-
if (i > 0) out.push(...glue);
|
|
2198
|
-
const part = renderSegments(parts[i], depth + 1);
|
|
2199
|
-
if (part === void 0) return void 0;
|
|
2200
|
-
out.push(...part);
|
|
2201
|
-
if (out.length > MAX_SEGMENTS) return void 0;
|
|
2202
|
-
}
|
|
2203
|
-
return out;
|
|
2204
|
-
}
|
|
2205
|
-
if (key === "Fn::Sub") {
|
|
2206
|
-
if (typeof args === "string") return subSegments(args, {}, depth);
|
|
2207
|
-
if (Array.isArray(args) && args.length === 2 && typeof args[0] === "string") {
|
|
2208
|
-
const variables = args[1];
|
|
2209
|
-
if (!isPlainObject(variables)) return GAP;
|
|
2210
|
-
return subSegments(args[0], variables, depth);
|
|
2211
|
-
}
|
|
2212
|
-
return GAP;
|
|
2213
|
-
}
|
|
2214
|
-
if (key === "Fn::If") {
|
|
2215
|
-
const taken = walking === void 0 ? void 0 : takenIfBranchOf(walking, node);
|
|
2216
|
-
if (taken === void 0 || !Array.isArray(args) || args.length !== 3) return GAP;
|
|
2217
|
-
const branch = taken ? args[1] : args[2];
|
|
2218
|
-
return isNoValue(branch) ? GAP : renderSegments(branch, depth + 1);
|
|
2219
|
-
}
|
|
2220
|
-
if (key === "Fn::Select") {
|
|
2221
|
-
if (!Array.isArray(args) || args.length !== 2) return GAP;
|
|
2222
|
-
const index = typeof args[0] === "number" ? args[0] : typeof args[0] === "string" && /^\d+$/.test(args[0]) ? Number(args[0]) : void 0;
|
|
2223
|
-
const list = staticList(args[1]);
|
|
2224
|
-
if (index === void 0 || list === void 0 || index >= list.length) return GAP;
|
|
2225
|
-
return renderSegments(list[index], depth + 1);
|
|
2555
|
+
function collectObjectKeys(value, into) {
|
|
2556
|
+
if (Array.isArray(value)) for (const item of value) collectObjectKeys(item, into);
|
|
2557
|
+
else if (isPlainObject(value)) for (const [k, v] of Object.entries(value)) {
|
|
2558
|
+
into.add(k);
|
|
2559
|
+
collectObjectKeys(v, into);
|
|
2226
2560
|
}
|
|
2227
|
-
return GAP;
|
|
2228
2561
|
}
|
|
2229
|
-
function
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
const
|
|
2233
|
-
|
|
2234
|
-
const [delimiter, text] = split;
|
|
2235
|
-
if (typeof delimiter !== "string" || delimiter === "" || typeof text !== "string") return void 0;
|
|
2236
|
-
if (text.includes("{{resolve:")) return void 0;
|
|
2237
|
-
return text.split(delimiter);
|
|
2562
|
+
function spelledKeysOf(properties) {
|
|
2563
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2564
|
+
collectObjectKeys(properties, keys);
|
|
2565
|
+
for (const key of sentinelDefinitionOf(properties)?.keys ?? []) keys.add(key);
|
|
2566
|
+
return keys;
|
|
2238
2567
|
}
|
|
2239
|
-
function
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
const literal = stringSegments(text.slice(at, match.index));
|
|
2244
|
-
if (literal === void 0) return void 0;
|
|
2245
|
-
out.push(...literal);
|
|
2246
|
-
const name = match[1];
|
|
2247
|
-
if (name.startsWith("!")) out.push({ text: `\${${name.slice(1)}}` });
|
|
2248
|
-
else if (Object.hasOwn(variables, name)) {
|
|
2249
|
-
const part = renderSegments(variables[name], depth + 1);
|
|
2250
|
-
if (part === void 0) return void 0;
|
|
2251
|
-
out.push(...part);
|
|
2252
|
-
if (out.length > MAX_SEGMENTS) return void 0;
|
|
2253
|
-
} else out.push({ gap: true });
|
|
2254
|
-
at = match.index + match[0].length;
|
|
2255
|
-
}
|
|
2256
|
-
const rest = stringSegments(text.slice(at));
|
|
2257
|
-
if (rest === void 0) return void 0;
|
|
2258
|
-
out.push(...rest);
|
|
2259
|
-
return out;
|
|
2568
|
+
function someKeyIsUnspelled(value, spelled) {
|
|
2569
|
+
if (Array.isArray(value)) return value.some((item) => someKeyIsUnspelled(item, spelled));
|
|
2570
|
+
if (isPlainObject(value)) return Object.entries(value).some(([k, v]) => !spelled(k) || someKeyIsUnspelled(v, spelled));
|
|
2571
|
+
return false;
|
|
2260
2572
|
}
|
|
2261
|
-
function
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
const
|
|
2266
|
-
|
|
2267
|
-
if (
|
|
2268
|
-
|
|
2269
|
-
|
|
2573
|
+
function nameDefinitionSecrets(value, source, secrets) {
|
|
2574
|
+
if (value === null || typeof value !== "object") return value;
|
|
2575
|
+
const sentinel = sentinelDefinitionOf(source);
|
|
2576
|
+
if (sentinel === void 0) {
|
|
2577
|
+
const plaintexts = [...secrets.keys()].filter((p) => p !== "");
|
|
2578
|
+
const keyHoldsSecret = (key) => plaintexts.some((p) => key === p || p.length >= 4 && key.includes(p));
|
|
2579
|
+
if (someKeyIsUnspelled(value, (key) => !keyHoldsSecret(key))) return "***";
|
|
2580
|
+
return nameScalarSecrets(value, secrets);
|
|
2581
|
+
}
|
|
2582
|
+
if (someKeyIsUnspelled(value, (key) => sentinel.keys.has(key))) return "***";
|
|
2583
|
+
let out = value;
|
|
2584
|
+
for (const leaf of sentinel.secretLeaves) {
|
|
2585
|
+
if (alignedSecretLeaf(out, leaf) === void 0) return "***";
|
|
2586
|
+
if (leaf.outOfStringName !== void 0) out = replaceAtPath(out, leaf.path, "***");
|
|
2270
2587
|
}
|
|
2271
|
-
const rest = value.slice(at);
|
|
2272
|
-
if (rest.includes("{{resolve:")) return void 0;
|
|
2273
|
-
if (rest !== "") out.push({ text: rest });
|
|
2274
2588
|
return out;
|
|
2275
2589
|
}
|
|
2276
|
-
function
|
|
2277
|
-
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2280
|
-
const
|
|
2281
|
-
|
|
2282
|
-
|
|
2590
|
+
function replaceAtPath(root, path, leaf) {
|
|
2591
|
+
if (path.length === 0) return leaf;
|
|
2592
|
+
const [head, ...rest] = path;
|
|
2593
|
+
if (Array.isArray(root)) {
|
|
2594
|
+
const copy = [...root];
|
|
2595
|
+
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
2596
|
+
return copy;
|
|
2283
2597
|
}
|
|
2284
|
-
|
|
2285
|
-
|
|
2598
|
+
const copy = Object.create(null);
|
|
2599
|
+
Object.assign(copy, root);
|
|
2600
|
+
copy[head] = replaceAtPath(root[head], rest, leaf);
|
|
2601
|
+
return copy;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
// src/deployment/secret-redaction/redact-path/unplaced-list-elements.ts
|
|
2605
|
+
function consumedPlaintextsUnder(source, secrets) {
|
|
2606
|
+
const out = /* @__PURE__ */ new Set();
|
|
2607
|
+
const visit = (node) => {
|
|
2608
|
+
if (Array.isArray(node)) {
|
|
2609
|
+
node.forEach(visit);
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
if (!isPlainObject(node)) return;
|
|
2613
|
+
for (const token of referencesConsumedBy(secrets, node)) {
|
|
2614
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
2615
|
+
if (plaintext !== void 0 && plaintext !== "") out.add(plaintext);
|
|
2616
|
+
}
|
|
2617
|
+
Object.values(node).forEach(visit);
|
|
2618
|
+
};
|
|
2619
|
+
visit(source);
|
|
2620
|
+
return [...out];
|
|
2621
|
+
}
|
|
2622
|
+
function placeUnpairedListElements(source, secrets, rules, scan) {
|
|
2623
|
+
const plaintexts = consumedPlaintextsUnder(source, secrets);
|
|
2624
|
+
if (plaintexts.length === 0) return void 0;
|
|
2625
|
+
const copies = [...physicalNameCopiesOf.get(secrets) ?? []].filter((c) => c !== "");
|
|
2626
|
+
const exposes = (text) => plaintexts.some((plaintext) => exposedAt(text, plaintext, copies).length > 0);
|
|
2627
|
+
const placeString = (item) => {
|
|
2628
|
+
let answer;
|
|
2629
|
+
for (const candidate of source) {
|
|
2630
|
+
let placed;
|
|
2631
|
+
try {
|
|
2632
|
+
placed = positionBySubstitutionSpans(item, candidate, secrets, rules, scan);
|
|
2633
|
+
} catch {
|
|
2634
|
+
return "***";
|
|
2635
|
+
}
|
|
2636
|
+
if (placed === void 0) continue;
|
|
2637
|
+
if (placed === TAINTED_WITHOUT_SPAN) continue;
|
|
2638
|
+
if (answer !== void 0 && answer !== placed) return "***";
|
|
2639
|
+
answer = placed;
|
|
2640
|
+
}
|
|
2641
|
+
return answer ?? "***";
|
|
2642
|
+
};
|
|
2643
|
+
const maskExposed = (value) => {
|
|
2644
|
+
if (typeof value === "string") return exposes(value) ? "***" : value;
|
|
2645
|
+
if (Array.isArray(value)) return value.map(maskExposed);
|
|
2646
|
+
if (isPlainObject(value) && hasPlainPrototype(value)) {
|
|
2647
|
+
const out = Object.create(null);
|
|
2648
|
+
for (const [k, v] of Object.entries(value)) out[k] = maskExposed(v);
|
|
2649
|
+
return out;
|
|
2650
|
+
}
|
|
2651
|
+
return value;
|
|
2652
|
+
};
|
|
2653
|
+
return (item) => typeof item === "string" && exposes(item) ? placeString(item) : maskExposed(scan(item));
|
|
2286
2654
|
}
|
|
2287
2655
|
|
|
2288
2656
|
// src/deployment/secret-redaction/redact-path/baseline-mask.ts
|
|
@@ -2319,25 +2687,43 @@ function redactByPath(bag, source, secrets, rules, secretExpressions, bagIsSameG
|
|
|
2319
2687
|
const rerendered = rerenderedSourceLiteral(bag, source, secrets, rules);
|
|
2320
2688
|
if (rerendered !== void 0) return rerendered;
|
|
2321
2689
|
if ((typeof bag === "string" || Array.isArray(bag)) && isPlainObject(source)) {
|
|
2690
|
+
if (attributionRefusedReadsOf(source, secrets) === "masked") return "***";
|
|
2322
2691
|
const inherited = positionByInheritedParameter(bag, source, secrets);
|
|
2323
2692
|
if (inherited !== void 0) return inherited;
|
|
2324
2693
|
const reread = positionByParameterReread(bag, source, secrets);
|
|
2325
2694
|
if (reread !== void 0) return reread;
|
|
2326
2695
|
}
|
|
2327
2696
|
if (typeof bag === "string" && isPlainObject(source)) {
|
|
2328
|
-
const
|
|
2697
|
+
const valueScan = (text) => redactForState(text, {
|
|
2329
2698
|
provenance: "value-scan",
|
|
2330
2699
|
secrets
|
|
2331
|
-
})
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2700
|
+
});
|
|
2701
|
+
let substituted;
|
|
2702
|
+
try {
|
|
2703
|
+
substituted = positionBySubstitutionSpans(bag, source, secrets, rules, valueScan);
|
|
2704
|
+
} catch {
|
|
2705
|
+
return "***";
|
|
2706
|
+
}
|
|
2707
|
+
const tainted = substituted === TAINTED_WITHOUT_SPAN;
|
|
2708
|
+
if (!tainted && substituted !== void 0) return substituted;
|
|
2709
|
+
try {
|
|
2710
|
+
const answered = positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, tainted ? void 0 : () => positionByLiteralRendering(bag, source, secrets, rules, valueScan));
|
|
2711
|
+
if (answered !== void 0) return answered;
|
|
2712
|
+
} catch (error) {
|
|
2713
|
+
if (tainted) return "***";
|
|
2714
|
+
throw error;
|
|
2715
|
+
}
|
|
2716
|
+
if (tainted) return "***";
|
|
2717
|
+
if (attributionRefusedReadsOf(source, secrets) !== void 0) return "***";
|
|
2718
|
+
}
|
|
2719
|
+
if (Array.isArray(bag) && isPlainObject(source) && listHoldsConsumedSecret(bag, source, secrets)) try {
|
|
2720
|
+
return positionListByCrossStackSource(bag, source, secrets) ?? "***";
|
|
2721
|
+
} catch {
|
|
2722
|
+
return "***";
|
|
2723
|
+
}
|
|
2724
|
+
if (Array.isArray(bag) && isPlainObject(source) && attributionRefusedReadsOf(source, secrets)) {
|
|
2725
|
+
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
2726
|
+
return positionedList !== void 0 ? positionedList : "***";
|
|
2341
2727
|
}
|
|
2342
2728
|
if (Array.isArray(bag) && isPlainObject(source)) {
|
|
2343
2729
|
const positionedList = positionListByCrossStackSource(bag, source, secrets);
|
|
@@ -2358,11 +2744,12 @@ function redactByPath(bag, source, secrets, rules, secretExpressions, bagIsSameG
|
|
|
2358
2744
|
return j;
|
|
2359
2745
|
});
|
|
2360
2746
|
const positionalIsExact = rules.descendArrays && bag.length === source.length && orderPreserved;
|
|
2747
|
+
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
2361
2748
|
return bag.map((item, i) => {
|
|
2362
2749
|
const j = partnerIndex[i];
|
|
2363
2750
|
if (j >= 0) return redactByPath(item, source[j], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
2364
2751
|
if (positionalIsExact) return redactByPath(item, source[i], secrets, rules, secretExpressions, bagIsSameGeneration);
|
|
2365
|
-
return redactForState(item, {
|
|
2752
|
+
return unpaired !== void 0 ? unpaired(item) : redactForState(item, {
|
|
2366
2753
|
provenance: "value-scan",
|
|
2367
2754
|
secrets
|
|
2368
2755
|
});
|
|
@@ -2373,6 +2760,8 @@ function redactByPath(bag, source, secrets, rules, secretExpressions, bagIsSameG
|
|
|
2373
2760
|
const kept = sourceElementsKeptFor(source, bag.length, secrets);
|
|
2374
2761
|
if (kept !== void 0 && keptLiteralsCorroborate(kept, bag, secrets)) return bag.map((item, i) => redactByPath(item, kept[i], secrets, rules, secretExpressions, bagIsSameGeneration));
|
|
2375
2762
|
}
|
|
2763
|
+
const unpaired = placeUnpairedListElements(source, secrets, rules, listValueScan(secrets));
|
|
2764
|
+
if (unpaired !== void 0) return bag.map(unpaired);
|
|
2376
2765
|
}
|
|
2377
2766
|
if (isPlainObject(bag) && hasPlainPrototype(bag) && isPlainObject(source)) {
|
|
2378
2767
|
const out = Object.create(null);
|
|
@@ -2390,6 +2779,33 @@ function redactByPath(bag, source, secrets, rules, secretExpressions, bagIsSameG
|
|
|
2390
2779
|
secrets
|
|
2391
2780
|
});
|
|
2392
2781
|
}
|
|
2782
|
+
function positionByCertifiedArms(bag, source, secrets, secretExpressions, bagIsSameGeneration, render) {
|
|
2783
|
+
const rendered = render?.();
|
|
2784
|
+
if (rendered !== void 0) return rendered;
|
|
2785
|
+
const certified = positionByCrossStackSource(bag, source, secrets);
|
|
2786
|
+
if (certified !== void 0) return certified;
|
|
2787
|
+
const placeheld = positionByParameterPlaceholders(bag, source, secrets);
|
|
2788
|
+
if (placeheld !== void 0) return placeheld;
|
|
2789
|
+
const positioned = positionByIntrinsicSkeleton(bag, source, secrets, secretExpressions);
|
|
2790
|
+
if (positioned !== void 0) return positioned;
|
|
2791
|
+
return positionByIntrinsicFrame(bag, source, secrets, secretExpressions, bagIsSameGeneration);
|
|
2792
|
+
}
|
|
2793
|
+
function listHoldsConsumedSecret(bag, source, secrets) {
|
|
2794
|
+
const plaintexts = [];
|
|
2795
|
+
for (const token of referencesConsumedBy(secrets, source)) {
|
|
2796
|
+
const plaintext = resolvedPlaintextOf(secrets, token);
|
|
2797
|
+
if (plaintext !== void 0 && plaintext !== "") plaintexts.push(plaintext);
|
|
2798
|
+
}
|
|
2799
|
+
if (plaintexts.length === 0) return false;
|
|
2800
|
+
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);
|
|
2801
|
+
return holds(bag);
|
|
2802
|
+
}
|
|
2803
|
+
function listValueScan(secrets) {
|
|
2804
|
+
return (value) => redactForState(value, {
|
|
2805
|
+
provenance: "value-scan",
|
|
2806
|
+
secrets
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2393
2809
|
|
|
2394
2810
|
// src/deployment/secret-redaction/readback-certification.ts
|
|
2395
2811
|
function renderedDefinitionLiterals(source) {
|
|
@@ -3847,8 +4263,24 @@ function renderSpans(source, spans, textOf) {
|
|
|
3847
4263
|
return out + source.slice(cursor);
|
|
3848
4264
|
}
|
|
3849
4265
|
function rendersLiteralTo(spelling, secrets, value) {
|
|
4266
|
+
if (literalTextHoldsSubFloorSecret(spelling, secrets)) return false;
|
|
3850
4267
|
return renderedLiteralSpans(spelling, secrets, value) !== void 0;
|
|
3851
4268
|
}
|
|
4269
|
+
function literalTextHoldsSubFloorSecret(spelling, secrets) {
|
|
4270
|
+
const pieces = [];
|
|
4271
|
+
let cursor = 0;
|
|
4272
|
+
for (const span of dynamicReferenceSpans(spelling)) {
|
|
4273
|
+
pieces.push(spelling.slice(cursor, span.start));
|
|
4274
|
+
cursor = span.end;
|
|
4275
|
+
}
|
|
4276
|
+
pieces.push(spelling.slice(cursor));
|
|
4277
|
+
for (const [plaintext, expression] of secrets) {
|
|
4278
|
+
if (plaintext === "" || plaintext.length >= 4) continue;
|
|
4279
|
+
if (expression === "***") continue;
|
|
4280
|
+
if (pieces.some((piece) => piece.includes(plaintext))) return true;
|
|
4281
|
+
}
|
|
4282
|
+
return false;
|
|
4283
|
+
}
|
|
3852
4284
|
function renderedLiteralSpans(spelling, secrets, value) {
|
|
3853
4285
|
const spans = pairedSpans(spelling, secrets);
|
|
3854
4286
|
if (spans === void 0) return void 0;
|
|
@@ -4381,6 +4813,20 @@ function readAt(bag, coordinate) {
|
|
|
4381
4813
|
function valueAtCoordinate(bag, coordinate) {
|
|
4382
4814
|
return readAt(bag, coordinate).value;
|
|
4383
4815
|
}
|
|
4816
|
+
function isWhollyMask(value) {
|
|
4817
|
+
if (value === "***") return true;
|
|
4818
|
+
if (Array.isArray(value)) return value.length > 0 && value.every(isWhollyMask);
|
|
4819
|
+
if (value !== null && typeof value === "object") {
|
|
4820
|
+
const children = Object.values(value);
|
|
4821
|
+
return children.length > 0 && children.every(isWhollyMask);
|
|
4822
|
+
}
|
|
4823
|
+
return false;
|
|
4824
|
+
}
|
|
4825
|
+
function isStaleNoEchoLeaf(recorded, today, coordinate) {
|
|
4826
|
+
if (!isWhollyMask(valueAtCoordinate(recorded, coordinate))) return false;
|
|
4827
|
+
const value = valueAtCoordinate(today, coordinate);
|
|
4828
|
+
return value !== void 0 && !carriesSecretMask(value);
|
|
4829
|
+
}
|
|
4384
4830
|
function cloneContainer(node) {
|
|
4385
4831
|
if (Array.isArray(node)) return [...node];
|
|
4386
4832
|
if (isPlainObject(node)) return { ...node };
|
|
@@ -4686,6 +5132,59 @@ function passedNoEchoParametersOf(bag) {
|
|
|
4686
5132
|
return bag === void 0 ? void 0 : passedNoEchoParameters.get(bag);
|
|
4687
5133
|
}
|
|
4688
5134
|
|
|
5135
|
+
// src/analyzer/replacement-rules/batch-compute-environment.ts
|
|
5136
|
+
const INFRASTRUCTURE_UPDATE_MEMBERS = [
|
|
5137
|
+
"AllocationStrategy",
|
|
5138
|
+
"BidPercentage",
|
|
5139
|
+
"Ec2Configuration",
|
|
5140
|
+
"Ec2KeyPair",
|
|
5141
|
+
"ImageId",
|
|
5142
|
+
"InstanceRole",
|
|
5143
|
+
"InstanceTypes",
|
|
5144
|
+
"LaunchTemplate",
|
|
5145
|
+
"PlacementGroup",
|
|
5146
|
+
"Tags",
|
|
5147
|
+
"Type",
|
|
5148
|
+
"UpdateToLatestImageVersion"
|
|
5149
|
+
];
|
|
5150
|
+
const CREATE_ONLY_PATHS = [
|
|
5151
|
+
["SpotIamFleetRole"],
|
|
5152
|
+
[
|
|
5153
|
+
"ManagedInstancesProvider",
|
|
5154
|
+
"InstanceLaunchTemplate",
|
|
5155
|
+
"CapacityOptionType"
|
|
5156
|
+
],
|
|
5157
|
+
[
|
|
5158
|
+
"ManagedInstancesProvider",
|
|
5159
|
+
"InstanceLaunchTemplate",
|
|
5160
|
+
"FipsEnabled"
|
|
5161
|
+
]
|
|
5162
|
+
];
|
|
5163
|
+
function at(value, path) {
|
|
5164
|
+
let cursor = value;
|
|
5165
|
+
for (const segment of path) {
|
|
5166
|
+
if (typeof cursor !== "object" || cursor === null || Array.isArray(cursor)) return void 0;
|
|
5167
|
+
cursor = cursor[segment];
|
|
5168
|
+
}
|
|
5169
|
+
return cursor;
|
|
5170
|
+
}
|
|
5171
|
+
function noInfrastructureUpdate(current) {
|
|
5172
|
+
const type = at(current, ["Type"]);
|
|
5173
|
+
if (type === "FARGATE" || type === "FARGATE_SPOT") return "fargate";
|
|
5174
|
+
const strategy = at(current, ["AllocationStrategy"]);
|
|
5175
|
+
return strategy === void 0 || strategy === "BEST_FIT" ? "best-fit" : void 0;
|
|
5176
|
+
}
|
|
5177
|
+
function isExplicitFalse(value) {
|
|
5178
|
+
return value === false || value === "false";
|
|
5179
|
+
}
|
|
5180
|
+
function batchComputeResourcesChangeReplaces(oldValue, newValue, siblings) {
|
|
5181
|
+
if (CREATE_ONLY_PATHS.some((p) => !isDeepStrictEqual(at(oldValue, p), at(newValue, p)))) return true;
|
|
5182
|
+
const changed = (member) => !isDeepStrictEqual(at(oldValue, [member]), at(newValue, [member]));
|
|
5183
|
+
const bestFit = noInfrastructureUpdate(oldValue) === "best-fit" || noInfrastructureUpdate(newValue) === "best-fit";
|
|
5184
|
+
if (!(INFRASTRUCTURE_UPDATE_MEMBERS.some(changed) || bestFit && (changed("Subnets") || changed("SecurityGroupIds"))) || siblings === void 0) return false;
|
|
5185
|
+
return !isExplicitFalse(siblings.newProperties["ReplaceComputeEnvironment"]);
|
|
5186
|
+
}
|
|
5187
|
+
|
|
4689
5188
|
// src/utils/lambda-function-name.ts
|
|
4690
5189
|
function parseLambdaFunctionAddress(value) {
|
|
4691
5190
|
const full = /^arn:([^:]+):lambda:([^:]+):(\d{12}):function:([^:]+)$/.exec(value);
|
|
@@ -5179,6 +5678,10 @@ function initializeRules() {
|
|
|
5179
5678
|
"DestinationConfig"
|
|
5180
5679
|
])
|
|
5181
5680
|
});
|
|
5681
|
+
this.rules.set("AWS::Batch::ComputeEnvironment", {
|
|
5682
|
+
replacementProperties: /* @__PURE__ */ new Set(),
|
|
5683
|
+
conditionalReplacements: /* @__PURE__ */ new Map([["ComputeResources", batchComputeResourcesChangeReplaces]])
|
|
5684
|
+
});
|
|
5182
5685
|
this.rules.set("AWS::DynamoDB::GlobalTable", {
|
|
5183
5686
|
replacementProperties: /* @__PURE__ */ new Set(),
|
|
5184
5687
|
conditionalReplacements: /* @__PURE__ */ new Map([["LocalSecondaryIndexes", globalTableLocalSecondaryIndexesRemoved]])
|
|
@@ -5604,5 +6107,5 @@ var ReplacementRulesRegistry = class {
|
|
|
5604
6107
|
}
|
|
5605
6108
|
};
|
|
5606
6109
|
|
|
5607
|
-
export {
|
|
5608
|
-
//# sourceMappingURL=replacement-rules-
|
|
6110
|
+
export { foldRecording as $, WHOLE_DYNAMIC_REFERENCE_PATTERN as $n, inheritedParameterExpression as $t, passedNoEchoParametersOf as A, splitGetAttStringForm as An, overlapRuleAnswered as At, intrinsicLeafResolutionOf as B, markNoEchoParameterClass as Bn, spanNamesResolvableService as Bt, maskedLeafCoordinatesOf as C, dynamicReferenceTokens as Cn, errorCauseChain as Ct, noEchoOutputsComparison as D, withoutConsumptionStamps as Dn, differingStringLeaves as Dt, noEchoLeavesOf as E, withConsumptionScope as En, maskSecretsInText as Et, replaceAtCoordinates as F, isMaskOnlyPlaintext as Fn, repairPhysicalNameCopyLeaves as Ft, recordIntrinsicLeafResolution as G, recordFreshNoEchoValuesIn as Gn, identityKeyFor as Gt, markLeafCertifiedBag as H, pinScopedSecretVerdict as Hn, spelledKeysOf as Ht, valueAtCoordinate as I, isNoEchoParameterPlaintext as In, replaceEmbeddedPhysicalNameRewrites as It, resolvedPlaintextOf as J, recordNoEchoAttributeValues as Jn, standsForInheritedSecret as Jt, recordIntrinsicLeafResolutionAs as K, recordMaskOnlyValue as Kn, rereadParameterExpression as Kt, witnessNormalize as L, isRecordedSecretExpression as Ln, scrubResourceRecord as Lt, readsNoEchoSource as M, carryFreshNoEchoMark as Mn, withLegacyOverlapScan as Mt, recordPassedNoEchoParameters as N, contradictProvenPublicExpression as Nn, embeddedPhysicalNameRewrites as Nt, noEchoParameterNodesAt as O, crossStackSourceKey as On, legacyLeavesWithoutMask as Ot, recordedNoEchoValuesOf as P, freshNoEchoValuesOf as Pn, repairEmbeddedPhysicalNamesTowards as Pt, redactForState as Q, withoutNoEchoParameterEntries as Qn, inheritNestedStackParameterAssociations as Qt, liveMatchesUnresolvedTokenFrame as R, isScopedSecretVerdict as Rn, withPhysicalNameCopies as Rt, maskWholeValue as S, dynamicReferenceSpans as Sn, createSecretMasker as St, noEchoCoordinatesOf as T, noteReferenceConsumed as Tn, maskSecretsInError as Tt, markSameGenerationBag as U, provenPublicValue as Un, pathCrossesDottedKey as Ut, isSameGenerationBag as V, noEchoParameterPlaintextsOf as Vn, isUncertifiedBaselineMaskPosition as Vt, mergeResolvedPairs as W, recordDerivedMaskOnlyValue as Wn, arrayPairsWhateverDrops as Wt, mixedLiteralAnswered as X, recordProvenPublicExpression as Xn, recordInheritedPseudoParameters as Xt, literalTextHoldsSubFloorSecret as Y, recordNoEchoParameterFreshValue as Yn, inheritedPseudoValue as Yt, withLegacyMixedScan as Z, wholeStringLeavesOf as Zn, templateRereadsAccountId as Zt, canonicalJson as _, physicalNameCopiesOf as _n, recordLogOnlyParameterValue as _t, liveHoldsFreshLeaves as a, carriesFreshNoEchoValue as an, recordReferenceProvenanceEntry as at, maskAtCoordinates as b, attributionRefusedParameters as bn, shareLogOnlyValues as bt, blockDeviceMappingsDifferOnlyInDeleteOnTermination as c, recordRecoverableMaskedOutput as cn, carryLogOnlyValues as ct, emrClusterInstancesReplaced as d, nestedStackRowTagSpellingOf as dn, hasLogOnlyValues as dt, inheritedRenderedToken as en, isDynamicReferenceString as er, openRecordingScope as et, canonicalLambdaFunctionName as f, staticTemplateText as fn, hasMaskableValues as ft, canonicalCoordinates as g, secretRerenderPairs as gn, printingCorpusOf as gt, sameLambdaFunctionAddress as h, keepTemplateLiteralLeaves as hn, logOnlyValuesOf as ht, keyOrderFreeJson as i, withdrawRenderedParameterSpelling as in, passReadVersionsFor as it, readbackPathFor as j, carriesSecretMask as jn, replaceWholeLeaves as jt, noEchoParametersReadBy as k, recordCrossStackExpression as kn, legacyReferenceLeavesOnly as kt, dbInstanceEngineChangeIsInPlace as l, recoverMaskedOutput as ln, carryLogOnlyValuesCarriedBy as lt, parseLambdaFunctionAddress as m, recordTakenIfBranch as mn, logOnlyValueCount as mt, grantSentence as n, recordInheritedParameterValue as nn, maskMatchSpans as nr, hasPassProvenance as nt, outputMapsEqual as o, embedsFreshNoEchoValue as on, recordReferenceResolution as ot, lambdaFunctionNameForMask as p, recordDroppedArrayElements as pn, literalSplitDelimitersOf as pt, redactionClaimOf as q, recordMaskOnlyValuesIn as qn, splitOutsideDynamicReferences as qt, isReplacementCeiling as r, redactInheritedParameterValue as rn, passProvenanceFor as rt, readDenialOf as s, freshNoEchoLeafPositions as sn, snapshotPassProvenance as st, ReplacementRulesRegistry as t, recordInheritedParameterRead as tn, isSingleDynamicReferenceToken as tr, recordSecretResolution as tt, ecsServiceLaunchTypeSetOrChanged as u, recordNestedStackParameterExpressions as un, createUnionSecretMasker as ut, isMarkedCoordinate as v, recordAttributeIdCopy as vn, recordLogOnlySplitFragments as vt, noEchoComparison as w, consumptionScopeOpenFor as wn, maskRecordedSecretsInText as wt, maskReadbackAtCoordinates as x, DYNAMIC_REFERENCE_TOKEN_SCAN as xn, unionOfSecretBags as xt, isStaleNoEchoLeaf as y, recordPhysicalNameCopy as yn, recordLogOnlyValue as yt, carryRedactionMarks as z, isSecretExpressionByVerdictOrSpelling as zn, withoutPhysicalNameCopies as zt };
|
|
6111
|
+
//# sourceMappingURL=replacement-rules-BoZMVFdK.js.map
|