@cdkd/cli 0.371.1 → 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.
Files changed (69) hide show
  1. package/dist/{ambient-client-defaults-Cq58skpK.js → ambient-client-defaults-1yRnA0Re.js} +3 -3
  2. package/dist/{ambient-client-defaults-Cq58skpK.js.map → ambient-client-defaults-1yRnA0Re.js.map} +1 -1
  3. package/dist/{asg-provider-B3ngG-X4.js → asg-provider-3uPCjYQK.js} +8 -8
  4. package/dist/{asg-provider-B3ngG-X4.js.map → asg-provider-3uPCjYQK.js.map} +1 -1
  5. package/dist/cli.js +3 -3
  6. package/dist/{created-resource-sink-Bzk9hJNq.js → created-resource-sink-CBOr1ShX.js} +4 -4
  7. package/dist/{created-resource-sink-Bzk9hJNq.js.map → created-resource-sink-CBOr1ShX.js.map} +1 -1
  8. package/dist/{custom-resource-runtime-CLHhYoEe.js → custom-resource-runtime-DURpNFOa.js} +6 -6
  9. package/dist/{custom-resource-runtime-CLHhYoEe.js.map → custom-resource-runtime-DURpNFOa.js.map} +1 -1
  10. package/dist/{db-associated-roles-CYA2C3yZ.js → db-associated-roles-BbvtfXqW.js} +2 -2
  11. package/dist/{db-associated-roles-CYA2C3yZ.js.map → db-associated-roles-BbvtfXqW.js.map} +1 -1
  12. package/dist/{delete-started-D9FEXTba.js → delete-started-yz9plykR.js} +4 -4
  13. package/dist/{delete-started-D9FEXTba.js.map → delete-started-yz9plykR.js.map} +1 -1
  14. package/dist/{deploy-engine-DvPDae31.js → deploy-engine-C12Ygjb-.js} +4553 -777
  15. package/dist/deploy-engine-C12Ygjb-.js.map +1 -0
  16. package/dist/{ec2-termination-protection-C19A5IH9.js → ec2-termination-protection-UZAZ2Hzv.js} +3 -3
  17. package/dist/{ec2-termination-protection-C19A5IH9.js.map → ec2-termination-protection-UZAZ2Hzv.js.map} +1 -1
  18. package/dist/{ecr-uri-BW6V_9R5.js → ecr-uri-C74u9FtL.js} +2 -2
  19. package/dist/{ecr-uri-BW6V_9R5.js.map → ecr-uri-C74u9FtL.js.map} +1 -1
  20. package/dist/{emr-cluster-provider-DVljF3YH.js → emr-cluster-provider-2ezuxbz3.js} +10 -10
  21. package/dist/{emr-cluster-provider-DVljF3YH.js.map → emr-cluster-provider-2ezuxbz3.js.map} +1 -1
  22. package/dist/{expected-bucket-owner-DMq5H0Zm.js → expected-bucket-owner-0yx_Q4Hl.js} +2 -2
  23. package/dist/{expected-bucket-owner-DMq5H0Zm.js.map → expected-bucket-owner-0yx_Q4Hl.js.map} +1 -1
  24. package/dist/{iam-role-provider-B8c2g5fS.js → iam-role-provider-CZtZQJRp.js} +12 -12
  25. package/dist/{iam-role-provider-B8c2g5fS.js.map → iam-role-provider-CZtZQJRp.js.map} +1 -1
  26. package/dist/{identity-read-denied-Cl8km1o3.js → identity-read-denied-DBsqwW85.js} +5 -5
  27. package/dist/{identity-read-denied-Cl8km1o3.js.map → identity-read-denied-DBsqwW85.js.map} +1 -1
  28. package/dist/{image-plan-Cg5bLNvP.js → image-plan-DW_fg6mx.js} +20 -12
  29. package/dist/image-plan-DW_fg6mx.js.map +1 -0
  30. package/dist/index.d.ts +29 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +5 -5
  33. package/dist/{logger-BUi1Imxa.js → logger-JtU7m4ph.js} +2 -2
  34. package/dist/{logger-BUi1Imxa.js.map → logger-JtU7m4ph.js.map} +1 -1
  35. package/dist/{neptune-provider-Ddse7yYJ.js → neptune-provider-ClT-eveS.js} +9 -9
  36. package/dist/{neptune-provider-Ddse7yYJ.js.map → neptune-provider-ClT-eveS.js.map} +1 -1
  37. package/dist/{program-bUaiwzJ2.js → program-BPrn1MhZ.js} +508 -790
  38. package/dist/program-BPrn1MhZ.js.map +1 -0
  39. package/dist/{provider-classes-AI1PLFRf.js → provider-classes-Bi3D5zDS.js} +22 -22
  40. package/dist/{provider-classes-AI1PLFRf.js.map → provider-classes-Bi3D5zDS.js.map} +1 -1
  41. package/dist/{rds-provider-6Cj8pik8.js → rds-provider-D610vnfB.js} +13 -13
  42. package/dist/{rds-provider-6Cj8pik8.js.map → rds-provider-D610vnfB.js.map} +1 -1
  43. package/dist/{read-replica-DWbYq3Fh.js → read-replica-Br2tFu0d.js} +3 -3
  44. package/dist/{read-replica-DWbYq3Fh.js.map → read-replica-Br2tFu0d.js.map} +1 -1
  45. package/dist/{redacted-delete-address-C1M-bYXm.js → redacted-delete-address-DVgNoeo4.js} +4 -4
  46. package/dist/{redacted-delete-address-C1M-bYXm.js.map → redacted-delete-address-DVgNoeo4.js.map} +1 -1
  47. package/dist/{replacement-rules-BimJi0H1.js → replacement-rules-BoZMVFdK.js} +2166 -1663
  48. package/dist/replacement-rules-BoZMVFdK.js.map +1 -0
  49. package/dist/{resource-deadline-Cj-4PzvY.js → resource-deadline-BkQ9mJAk.js} +2 -2
  50. package/dist/{resource-deadline-Cj-4PzvY.js.map → resource-deadline-BkQ9mJAk.js.map} +1 -1
  51. package/dist/{restore-source-guard-CP2cxnnh.js → restore-source-guard-BkS5tGr5.js} +4 -4
  52. package/dist/{restore-source-guard-CP2cxnnh.js.map → restore-source-guard-BkS5tGr5.js.map} +1 -1
  53. package/dist/{run-cli-C0ZXPvze.js → run-cli-Ds9QnqnH.js} +2 -2
  54. package/dist/{run-cli-C0ZXPvze.js.map → run-cli-Ds9QnqnH.js.map} +1 -1
  55. package/dist/{secret-reference-immutable-BLsAuIkM.js → secret-reference-immutable-BC4abPuQ.js} +20 -11
  56. package/dist/secret-reference-immutable-BC4abPuQ.js.map +1 -0
  57. package/dist/{settle-own-write-members-BJ1rf1Yt.js → settle-own-write-members-D6wzEt7f.js} +13 -771
  58. package/dist/settle-own-write-members-D6wzEt7f.js.map +1 -0
  59. package/dist/{tag-list-CSQWFQbX.js → tag-list-UEcqQLzY.js} +4 -4
  60. package/dist/{tag-list-CSQWFQbX.js.map → tag-list-UEcqQLzY.js.map} +1 -1
  61. package/dist/{version-CQenoJzP.js → version-Dn0kzidt.js} +2 -2
  62. package/dist/{version-CQenoJzP.js.map → version-Dn0kzidt.js.map} +1 -1
  63. package/package.json +1 -1
  64. package/dist/deploy-engine-DvPDae31.js.map +0 -1
  65. package/dist/image-plan-Cg5bLNvP.js.map +0 -1
  66. package/dist/program-bUaiwzJ2.js.map +0 -1
  67. package/dist/replacement-rules-BimJi0H1.js.map +0 -1
  68. package/dist/secret-reference-immutable-BLsAuIkM.js.map +0 -1
  69. package/dist/settle-own-write-members-BJ1rf1Yt.js.map +0 -1
@@ -1,5 +1,6 @@
1
- import { P as safeMsg, x as SAFE_MSG_ALTERED_CHAR } from "./version-CQenoJzP.js";
2
- import { n as getLogger } from "./logger-BUi1Imxa.js";
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
- // src/deployment/secret-redaction/nested-stack/row-tag-spellings.ts
451
- const rowTagSpellings = /* @__PURE__ */ new WeakMap();
452
- function recordNestedStackRowTagSpellings(secrets, resourceType, resolvedProperties, sourceProperties) {
453
- if (resourceType !== "AWS::CloudFormation::Stack") return;
454
- if (!isPlainObject(resolvedProperties) || !isPlainObject(sourceProperties)) return;
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 (!isPlainObject(source)) return void 0;
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/record-parameter-expressions.ts
511
- function recordNestedStackParameterExpressions(secrets, resourceType, resolvedProperties, sourceProperties, provenance = "template-derived") {
512
- if (resourceType !== "AWS::CloudFormation::Stack") return;
513
- if (provenance === "template-derived") recordNestedStackRowTagSpellings(secrets, resourceType, resolvedProperties, sourceProperties);
514
- if (secrets.size === 0) return;
515
- if (!isPlainObject(resolvedProperties) || !isPlainObject(sourceProperties)) return;
516
- if (!Object.hasOwn(resolvedProperties, "Parameters")) return;
517
- if (!Object.hasOwn(sourceProperties, "Parameters")) return;
518
- const resolvedParameters = resolvedProperties["Parameters"];
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 unwrittenValues = /* @__PURE__ */ new Set();
589
- for (const [name, resolvedValue] of Object.entries(resolvedParameters)) {
590
- if (typeof resolvedValue !== "string") continue;
591
- const spelling = frameSpellingOf(name);
592
- const frame = spelling === void 0 ? void 0 : singleSpanFrame(resolvedValue, spelling);
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
- for (const other of Object.values(resolvedParameters)) {
629
- if (embedded) break;
630
- if (typeof other === "string") {
631
- if (other !== resolvedValue && rewrites(other)) embedded = true;
632
- continue;
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
- if (embedded) continue;
640
- framedByName.push([
641
- name,
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/fresh-noecho.ts
680
- function embedsFreshNoEchoValue(text, secrets, freshClass) {
681
- const fresh = freshNoEchoValuesOf.get(secrets);
682
- if (fresh === void 0) return false;
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 carriesFreshNoEchoValue(value, secrets, freshClass) {
690
- const isFresh = freshNoEchoLeafTest(secrets, freshClass);
691
- if (isFresh === void 0) return false;
692
- const seen = /* @__PURE__ */ new Set();
693
- const walk = (node) => {
694
- if (typeof node === "string") return isFresh(node);
695
- if (node === null || typeof node !== "object") return false;
696
- if (seen.has(node)) return false;
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 isStrictlyInsideASpan(spans, start, end) {
742
- return spans.some((span) => span.start <= start && end <= span.end && (span.start !== start || span.end !== end));
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
- function embedsNeedleOutsideReferences(leaf, needles, secrets) {
745
- return needleOccurrencesOutsideReferences(leaf, needles, secrets, true).length > 0;
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 needleOccurrencesOutsideReferences(leaf, needles, secrets, first) {
748
- const found = [];
749
- let spans;
750
- let names;
751
- for (const needle of needles) for (let at = leaf.indexOf(needle); at >= 0; at = leaf.indexOf(needle, at + 1)) {
752
- spans ??= isDynamicReferenceString(leaf) ? resolvableReferenceSpans(leaf, new Set(secrets.values())) : [];
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 found;
620
+ return pairs;
764
621
  }
765
- function cutsContainmentNeedle(leaf, secrets, redacted) {
766
- if (redacted.length === 0) return false;
767
- const needles = containmentNeedlesOf(secrets);
768
- if (needles.length === 0) return false;
769
- 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)));
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 flattenEmbeddedNoEchoLeaves(value, secrets) {
772
- const needles = containmentNeedlesOf(secrets);
773
- if (needles.length === 0) return value;
774
- const flattens = (leaf) => leaf !== "***" && embedsNeedleOutsideReferences(leaf, needles, secrets);
775
- const walk = (node) => {
776
- if (typeof node === "string") return flattens(node) ? "***" : node;
777
- if (node === null || typeof node !== "object") return node;
778
- if (Array.isArray(node)) {
779
- let changed = false;
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 (const [key, child] of Object.entries(node)) {
793
- const next = walk(child);
794
- if (next === child) continue;
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 ?? node;
799
- };
800
- return walk(value);
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
- function substringNeedlesOf(secrets) {
803
- const needles = [];
804
- for (const plaintext of secrets.keys()) if (!isMaskOnlyPlaintext(secrets, plaintext)) needles.push(plaintext);
805
- return needles;
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
- function recordedExpressionsOf(secrets) {
808
- const expressions = /* @__PURE__ */ new Set();
809
- for (const [plaintext, expression] of secrets) if (!isMaskOnlyPlaintext(secrets, plaintext)) expressions.add(expression);
810
- return expressions;
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
- const recoverableMaskedOutputs = /* @__PURE__ */ new Map();
813
- function maskedOutputKey(identity, stackName, region, outputKey) {
814
- return `${identity}\u0000${stackName}\u0000${region}\u0000${outputKey}`;
680
+ function takenIfBranchOf(secrets, source) {
681
+ const taken = takenBranches.get(secrets)?.get(source);
682
+ return taken === CONFLICTING ? void 0 : taken;
815
683
  }
816
- function recordRecoverableMaskedOutput(identity, stackName, region, outputKey, plaintext) {
817
- recoverableMaskedOutputs.set(maskedOutputKey(identity, stackName, region, outputKey), plaintext);
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 recoverMaskedOutput(identity, stackName, region, outputKey) {
820
- return recoverableMaskedOutputs.get(maskedOutputKey(identity, stackName, region, outputKey));
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/nested-stack/child-only-plaintext.ts
824
- function carriesChildOnlyPlaintext(value, childSecrets, parentSecrets) {
825
- const parentNeedles = new Set(substringNeedlesOf(parentSecrets));
826
- const childNeedles = new Set(substringNeedlesOf(childSecrets));
827
- const childOnly = [...childSecrets.keys()].filter((plaintext) => plaintext !== "" && (!parentSecrets.has(plaintext) || childNeedles.has(plaintext) && !parentNeedles.has(plaintext)));
828
- for (const needle of parentNeedles) if (needle.length >= 4 && !childSecrets.has(needle)) childOnly.push(needle);
829
- if (childOnly.length === 0) return false;
830
- const visit = (node) => {
831
- if (typeof node === "string") return childOnly.some((plaintext) => node.includes(plaintext));
832
- if (Array.isArray(node)) return node.some(visit);
833
- if (node !== null && typeof node === "object") return Object.values(node).some(visit);
834
- return false;
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
- // src/deployment/secret-redaction/nested-stack/inherited-parameters.ts
840
- function inheritNestedStackParameterAssociations(childSecrets, parentSecrets) {
841
- const table = nestedStackParameterExpressions.get(parentSecrets);
842
- if (table === void 0 || table.size === 0) return;
843
- let associations = crossStackAssociations.get(childSecrets);
844
- for (const [name, association] of table) {
845
- const key = crossStackSourceKey({ Ref: name });
846
- if (key === void 0) continue;
847
- if (associations === void 0) {
848
- associations = /* @__PURE__ */ new Map();
849
- crossStackAssociations.set(childSecrets, associations);
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
- if (typeof association === "symbol") {
852
- associations.set(key, association);
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
- storeAssociation(associations, key, association.expression, association.plaintext);
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 inheritedParameterExpression(parentSecrets, parameterName, resolvedValue) {
859
- const association = nestedStackParameterExpressions.get(parentSecrets)?.get(parameterName);
860
- if (association === void 0) return renderedParameterSpelling(parentSecrets, parameterName, resolvedValue);
861
- if (typeof association === "symbol") return void 0;
862
- if (Array.isArray(resolvedValue)) return certifiedListForLeaf(parentSecrets, association, resolvedValue);
863
- return certifiedExpressionForLeaf(parentSecrets, association, resolvedValue);
864
- }
865
- function renderedParameterSpelling(parentSecrets, parameterName, resolvedValue) {
866
- if (typeof resolvedValue !== "string" || parentSecrets.has(resolvedValue)) return void 0;
867
- const rendered = renderedParameterSpellings.get(parentSecrets)?.get(parameterName);
868
- if (rendered == null || rendered.value !== resolvedValue) return void 0;
869
- if (!rendersLiteralTo(rendered.spelling, parentSecrets, resolvedValue)) return void 0;
870
- return rendered.spelling;
871
- }
872
- function inheritedRenderedToken(parentSecrets, parameterName, value, plaintext) {
873
- const spelling = inheritedParameterExpression(parentSecrets, parameterName, value);
874
- if (typeof spelling !== "string" || isSingleDynamicReferenceToken(spelling)) return void 0;
875
- return renderedTokenOf(spelling, parentSecrets, plaintext);
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
- function withdrawRenderedParameterSpelling(parentSecrets, parameterName) {
878
- const rendered = renderedParameterSpellings.get(parentSecrets);
879
- if (rendered?.has(parameterName)) rendered.set(parameterName, null);
760
+ let walking;
761
+ let suspended = 0;
762
+ function literalRenderingSuspended() {
763
+ return suspended > 0;
880
764
  }
881
- function inheritedRenderedSpan(childSecrets, key, text) {
882
- const reads = inheritedParameterReads.get(childSecrets);
883
- if (reads === void 0 || typeof reads === "symbol") return void 0;
884
- for (const name of reads.names) {
885
- if (crossStackSourceKey({ Ref: name }) !== key) continue;
886
- const value = renderedParameterSpellings.get(reads.parent)?.get(name)?.value;
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
- const inheritedParameterReads = /* @__PURE__ */ new WeakMap();
902
- const POISONED_PARAMETER_READS = Symbol("cdkd.inherited-parameter-reads.poisoned");
903
- function parameterReadsFor(childSecrets, parentSecrets) {
904
- const reads = inheritedParameterReads.get(childSecrets);
905
- if (reads === void 0) {
906
- const created = {
907
- parent: parentSecrets,
908
- names: /* @__PURE__ */ new Set(),
909
- values: /* @__PURE__ */ new Map()
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 recordInheritedParameterValue(childSecrets, parentSecrets, parameterName, value, declared) {
922
- const reads = parameterReadsFor(childSecrets, parentSecrets);
923
- if (reads === void 0) return;
924
- if (declared !== void 0) {
925
- if (reads.declared === void 0) reads.declared = declared;
926
- else if (reads.declared.size !== declared.size || [...declared].some((name) => !reads.declared.has(name))) {
927
- inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
928
- return;
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 (reads.values.has(parameterName)) {
932
- if (!deepEqualJsonValue(reads.values.get(parameterName), value)) inheritedParameterReads.set(childSecrets, POISONED_PARAMETER_READS);
933
- return;
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
- reads.values.set(parameterName, value);
936
- }
937
- function recordInheritedParameterRead(childSecrets, parentSecrets, parameterName) {
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 verdict;
852
+ else if (cursor !== region.length) return void 0;
853
+ return out;
983
854
  }
984
- const accountRereadVerdicts = /* @__PURE__ */ new WeakMap();
985
- function partRereadsAccountId(part) {
986
- let trigger = false;
987
- let account = false;
988
- const pending = [part];
989
- while (pending.length > 0 && !(trigger && account)) {
990
- const node = pending.pop();
991
- if (Array.isArray(node)) {
992
- pending.push(...node);
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
- if (node === null || typeof node !== "object") continue;
996
- for (const [key, value] of Object.entries(node)) {
997
- if (REREAD_TRIGGERS.has(key)) trigger = true;
998
- if (key === "Ref" && value === "AWS::AccountId") account = true;
999
- if (key === "Fn::Sub") {
1000
- const text = Array.isArray(value) ? value[0] : value;
1001
- if (typeof text === "string" && text.includes("${AWS::AccountId}")) account = true;
1002
- }
1003
- pending.push(value);
1004
- }
1005
- }
1006
- return trigger && account;
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
- function pseudoBindingOf(parentSecrets) {
1028
- const table = inheritedPseudoParameters.get(parentSecrets);
1029
- return (name) => table instanceof Map && table.has(name) ? { value: table.get(name) } : void 0;
1030
- }
1031
- function inheritedPseudoValue(parentSecrets, name) {
1032
- const bound = pseudoBindingOf(parentSecrets)(name)?.value;
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
- const previous = taken.get(source);
1056
- if (previous === void 0) taken.set(source, tookTrueBranch);
1057
- else if (previous !== tookTrueBranch) taken.set(source, CONFLICTING);
1058
- }
1059
- function takenIfBranchOf(secrets, source) {
1060
- const taken = takenBranches.get(secrets)?.get(source);
1061
- return taken === CONFLICTING ? void 0 : taken;
1062
- }
1063
- const droppedElements = /* @__PURE__ */ new WeakMap();
1064
- function recordDroppedArrayElements(secrets, source, dropped) {
1065
- let arrays = droppedElements.get(secrets);
1066
- if (arrays === void 0) {
1067
- arrays = /* @__PURE__ */ new WeakMap();
1068
- droppedElements.set(secrets, arrays);
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
- const previous = arrays.get(source);
1071
- if (previous === void 0) arrays.set(source, [...dropped]);
1072
- else if (previous !== CONFLICTING && (previous.length !== dropped.length || previous.some((index, i) => index !== dropped[i]))) arrays.set(source, CONFLICTING);
1073
- }
1074
- function droppedArrayElementsOf(secrets, source) {
1075
- const dropped = droppedElements.get(secrets)?.get(source);
1076
- return dropped === CONFLICTING ? void 0 : dropped;
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
- // src/deployment/secret-redaction/nested-stack/reread.ts
1080
- const MAX_REREAD_DEPTH = 16;
1081
- const MAX_REREAD_CONDITIONS = 4;
1082
- const REREAD_NO_VALUE = Symbol("cdkd.reread.no-value");
1083
- function splitOutsideDynamicReferences(text, delimiter, standsForSecret) {
1084
- if (delimiter === "") return text.split(delimiter);
1085
- const spans = dynamicReferenceSpans(text).filter((span) => {
1086
- const token = text.slice(span.start, span.end);
1087
- return spanNamesResolvableService(token) && standsForSecret(token);
1088
- });
1089
- if (spans.length === 0) return text.split(delimiter);
1090
- const pieces = [];
1091
- let cursor = 0;
1092
- let from = 0;
1093
- for (;;) {
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
- pieces.push(text.slice(cursor, at));
1103
- cursor = end;
1104
- from = end;
951
+ return out;
1105
952
  }
1106
- pieces.push(text.slice(cursor));
1107
- return pieces;
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 standsForInheritedSecret(parentSecrets, token) {
1110
- return parentSecrets !== void 0 && resolvedPlaintextOf(parentSecrets, token) !== void 0;
969
+ function isNoValue(node) {
970
+ return isPlainObject(node) && Object.keys(node).length === 1 && node["Ref"] === "AWS::NoValue";
1111
971
  }
1112
- const plainSplit = (text, delimiter) => text.split(delimiter);
1113
- function evaluatePureRead(node, bind, pseudo, split, choose, depth = 0) {
1114
- if (depth > MAX_REREAD_DEPTH) return void 0;
1115
- const evaluate = (child) => evaluatePureRead(child, bind, pseudo, split, choose, depth + 1);
1116
- if (typeof node === "string") return node.includes("{{resolve:") ? void 0 : { value: node };
1117
- if (Array.isArray(node)) {
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
- for (const element of node) {
1120
- const evaluated = evaluate(element);
1121
- if (evaluated === void 0 || evaluated.value === REREAD_NO_VALUE) return void 0;
1122
- out.push(evaluated.value);
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 { value: out };
1001
+ return out;
1125
1002
  }
1126
- if (!isPlainObject(node)) return void 0;
1127
- const keys = Object.keys(node);
1128
- if (keys.length !== 1) return void 0;
1129
- const key = keys[0];
1130
- const args = node[key];
1131
- if (key === "Ref") {
1132
- if (args === "AWS::NoValue") return { value: REREAD_NO_VALUE };
1133
- return typeof args === "string" ? bindReadName(args, bind, pseudo) : void 0;
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
- if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return void 0;
1137
- const tookTrue = choose(args[0], node);
1138
- if (tookTrue === void 0) return void 0;
1139
- return evaluate(tookTrue ? args[1] : args[2]);
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
- const index = args[0];
1145
- const position = typeof index === "number" ? index : typeof index === "string" && /^(0|[1-9][0-9]*)$/.test(index) ? Number(index) : void 0;
1146
- if (position === void 0 || !Number.isSafeInteger(position) || position < 0) return void 0;
1147
- const list = evaluate(args[1]);
1148
- if (list === void 0 || !Array.isArray(list.value) || position >= list.value.length) return;
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 { value: out + text.slice(cursor) };
1025
+ return GAP;
1192
1026
  }
1193
- function bindReadName(name, bind, pseudo) {
1194
- if (!name.startsWith("AWS::")) return bind(name);
1195
- return bind(name) === void 0 ? pseudo(name) : void 0;
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 collectRereadConditions(node, names, depth = 0) {
1198
- if (depth > MAX_REREAD_DEPTH) return false;
1199
- if (Array.isArray(node)) return node.every((element) => collectRereadConditions(element, names, depth + 1));
1200
- if (!isPlainObject(node)) return true;
1201
- if (Object.hasOwn(node, "Fn::If")) {
1202
- const args = node["Fn::If"];
1203
- if (!Array.isArray(args) || typeof args[0] !== "string") return false;
1204
- names.add(args[0]);
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
- return Object.values(node).every((child) => collectRereadConditions(child, names, depth + 1));
1207
- }
1208
- function holdsRereadTrigger(node, depth = 0) {
1209
- if (depth > MAX_REREAD_DEPTH) return false;
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 rendersReadTo(spelling, parentSecrets, value) {
1215
- if (typeof spelling === "string" && typeof value === "string") {
1216
- if (spelling === value) return redactForState(spelling, {
1217
- provenance: "value-scan",
1218
- secrets: parentSecrets
1219
- }) === spelling;
1220
- return rendersLiteralTo(spelling, parentSecrets, value);
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
- if (Array.isArray(spelling) && Array.isArray(value) && spelling.length === value.length) return spelling.every((element, i) => rendersReadTo(element, parentSecrets, value[i]));
1223
- return false;
1224
- }
1225
- const REREAD_UNBOUND = Symbol("cdkd.reread.unbound");
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 rereadUnder(source, bind, parentSecrets, choose) {
1237
- const pseudo = pseudoBindingOf(parentSecrets);
1238
- const resolved = evaluatePureRead(source, bind, pseudo, plainSplit, choose);
1239
- if (resolved === void 0) return void 0;
1240
- const diffSide = diffSideReading(bind, parentSecrets);
1241
- const redacted = evaluatePureRead(source, diffSide.bind, pseudo, diffSide.split, choose);
1242
- if (redacted === void 0) return void 0;
1243
- if (resolved.value === REREAD_NO_VALUE || redacted.value === REREAD_NO_VALUE) return resolved.value === redacted.value ? REREAD_NO_VALUE : void 0;
1244
- if (!rendersReadTo(redacted.value, parentSecrets, resolved.value)) return void 0;
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
- function namesParameterOnBranches(node, choose, isParameter, depth = 0) {
1251
- if (depth > MAX_REREAD_DEPTH) return true;
1252
- if (typeof node === "string") return node.includes("{{resolve:");
1253
- if (Array.isArray(node)) return node.some((element) => namesParameterOnBranches(element, choose, isParameter, depth + 1));
1254
- if (!isPlainObject(node)) return false;
1255
- if (Object.hasOwn(node, "Fn::If")) {
1256
- const args = node["Fn::If"];
1257
- if (Object.keys(node).length !== 1) return true;
1258
- if (!Array.isArray(args) || args.length !== 3 || typeof args[0] !== "string") return true;
1259
- const tookTrue = choose(args[0], node);
1260
- if (tookTrue === void 0) return true;
1261
- return namesParameterOnBranches(tookTrue ? args[1] : args[2], choose, isParameter, depth + 1);
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
- if (typeof node["Ref"] === "string" && isParameter(node["Ref"])) return true;
1264
- const sub = node["Fn::Sub"];
1265
- const text = typeof sub === "string" ? sub : Array.isArray(sub) ? sub[0] : void 0;
1266
- if (typeof text === "string") {
1267
- for (const match of text.matchAll(/\$\{([^}!][^}]*)\}/g)) if (isParameter(match[1].trim()) || isParameter(match[1])) return true;
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
- return Object.values(node).some((child) => namesParameterOnBranches(child, choose, isParameter, depth + 1));
1115
+ rendered += resolution.input.slice(cursor);
1116
+ return rendered === bag ? spans : void 0;
1270
1117
  }
1271
- function rereadAssignments(source, bind, parentSecrets, untakenWhenUnbound = () => false, parameterFree) {
1272
- if (!holdsRereadTrigger(source)) return void 0;
1273
- const conditions = /* @__PURE__ */ new Set();
1274
- if (!collectRereadConditions(source, conditions)) return void 0;
1275
- if (conditions.size > MAX_REREAD_CONDITIONS) return void 0;
1276
- const names = [...conditions];
1277
- const out = [];
1278
- for (let assignment = 0; assignment < 2 ** names.length; assignment++) {
1279
- const choose = (condition) => Math.floor(assignment / 2 ** names.indexOf(condition)) % 2 === 1;
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
- return out;
1293
- }
1294
- function rereadParameterExpression(source, bind, parentSecrets) {
1295
- const assignments = rereadAssignments(source, bind, parentSecrets, void 0, (name) => bind(name) !== void 0);
1296
- if (assignments === void 0 || assignments.includes(void 0) || assignments.includes(REREAD_UNBOUND)) return;
1297
- return assignments.find((entry) => entry !== void 0 && entry !== REREAD_NO_VALUE && entry !== REREAD_UNBOUND && entry !== REREAD_PARAMETER_FREE);
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 ambiguousRereads(rereads) {
1300
- return rereads.some((a, i) => rereads.slice(i + 1).some((b) => deepEqualJsonValue(a.resolved, b.resolved) && !deepEqualJsonValue(a.redacted, b.redacted)));
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 positionByParameterReread(bag, source, secrets) {
1303
- const reads = inheritedParameterReads.get(secrets);
1304
- if (reads === void 0 || typeof reads === "symbol") return void 0;
1305
- if (typeof bag !== "string" && !Array.isArray(bag)) return void 0;
1306
- if (!holdsRereadTrigger(source)) return void 0;
1307
- const bind = (name) => reads.values.has(name) ? { value: reads.values.get(name) } : void 0;
1308
- let unrecorded = false;
1309
- const recorded = rereadUnder(source, bind, reads.parent, (_, node) => {
1310
- const taken = takenIfBranchOf(secrets, node);
1311
- if (taken === void 0) unrecorded = true;
1312
- return taken;
1313
- });
1314
- let answer;
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
- if (carriesChildOnlyPlaintext(bag, secrets, reads.parent)) return void 0;
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/placeholder-positions.ts
1335
- function keyedPart(source) {
1336
- const key = crossStackSourceKey(source);
1337
- return key === void 0 ? UNKNOWN_PART : { key };
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
- const MAX_PLACEHOLDER_DEPTH = 8;
1340
- function pushPlaceholderPart(out, part, budget) {
1341
- if (budget.remaining <= 0) {
1342
- budget.exhausted = true;
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
- budget.remaining -= 1;
1346
- out.push(part);
1677
+ return reads;
1347
1678
  }
1348
- function appendValuePlaceholderParts(value, out, budget, depth) {
1349
- if (budget.exhausted) return;
1350
- const literal = joinPartLiteralText(value);
1351
- if (literal !== void 0) return pushPlaceholderPart(out, literal, budget);
1352
- if (isPlainObject(value) && Object.keys(value).length === 1) {
1353
- const ref = value["Ref"];
1354
- if (typeof ref === "string" && ref !== "") return pushPlaceholderPart(out, keyedPart({ Ref: ref }), budget);
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
- pushPlaceholderPart(out, UNKNOWN_PART, budget);
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 appendParameterPlaceholderParts(source, out, budget, depth) {
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 false;
1367
- const key = keys[0];
1368
- if (key === "Fn::Join") {
1369
- const args = source[key];
1370
- if (!Array.isArray(args) || args.length !== 2) return false;
1371
- const [delimiter, parts] = args;
1372
- if (typeof delimiter !== "string" || !Array.isArray(parts)) return false;
1373
- for (let index = 0; index < parts.length && !budget.exhausted; index++) {
1374
- if (index > 0) pushPlaceholderPart(out, delimiter, budget);
1375
- appendValuePlaceholderParts(parts[index], out, budget, depth);
1376
- }
1377
- return true;
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
- function parameterPlaceholderParts(source, bag) {
1407
- const budget = {
1408
- remaining: bag.length * 2 + 16,
1409
- exhausted: false
1410
- };
1411
- const out = [];
1412
- if (!appendParameterPlaceholderParts(source, out, budget, 0)) return void 0;
1413
- return budget.exhausted ? void 0 : out;
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
- function positionByParameterPlaceholders(bag, source, secrets) {
1416
- const associations = crossStackAssociations.get(secrets);
1417
- const spanned = positionByRecordedParameterSpans(bag, source, secrets, associations);
1418
- if (spanned !== void 0) return spanned;
1419
- const parts = parameterPlaceholderParts(source, bag);
1420
- if (parts === void 0) return void 0;
1421
- const before = ["", ""];
1422
- const after = ["", ""];
1423
- let side = before;
1424
- let unknown = false;
1425
- let certified = 0;
1426
- const spans = [];
1427
- for (const part of parts) {
1428
- let rendered;
1429
- let persisted;
1430
- if (typeof part === "string") {
1431
- rendered = part;
1432
- persisted = part;
1433
- } else {
1434
- let expression;
1435
- let plaintext = "";
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
- const afterStart = bag.length - after[0].length;
1490
- return acceptedPlaceholderRendering(bag, persisted, spans.map(([side, offset, length]) => [(side === before ? 0 : afterStart) + offset, length]), secrets);
1775
+ return trigger && account;
1491
1776
  }
1492
- function acceptedPlaceholderRendering(bag, persisted, spans, secrets) {
1493
- for (const plaintext of secrets.keys()) {
1494
- if (plaintext.length < 4) continue;
1495
- for (let at = bag.indexOf(plaintext); at !== -1; at = bag.indexOf(plaintext, at + 1)) {
1496
- const end = at + plaintext.length;
1497
- for (const [start, length] of spans) if (at < start + length && end > start && (at < start || end > start + length)) return void 0;
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 positionByRecordedParameterSpans(bag, source, secrets, associations) {
1507
- const resolution = intrinsicLeafResolutionOf(secrets, source);
1508
- if (resolution === void 0 || resolution.output !== bag) return void 0;
1509
- const recorded = resolution.parameterSpans;
1510
- if (recorded === void 0) return void 0;
1511
- let previousEnd = 0;
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 persisted = "";
1514
- const gaps = [];
1515
- const certified = [];
1516
- for (const { start, length, key } of recorded) {
1517
- if (!(start >= previousEnd && length > 0 && start + length <= bag.length)) return void 0;
1518
- previousEnd = start + length;
1519
- const text = bag.slice(start, start + length);
1520
- const association = associations?.get(key);
1521
- const expression = (association !== void 0 && typeof association !== "symbol" ? certifiedExpressionForLeaf(secrets, association, text) : void 0) ?? inheritedRenderedSpan(secrets, key, text)?.spelling;
1522
- if (expression === void 0) continue;
1523
- const gap = bag.slice(cursor, start);
1524
- gaps.push(gap);
1525
- persisted += gap + expression;
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
- if (certified.length === 0) return void 0;
1530
- const tail = bag.slice(cursor);
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
- // src/deployment/secret-redaction/identity-keys.ts
1541
- const ARRAY_IDENTITY_KEYS = ["Name", "Key"];
1542
- function isUniquelyKeyedBy(items, key) {
1543
- if (items.length === 0) return false;
1544
- const seen = /* @__PURE__ */ new Set();
1545
- for (const item of items) {
1546
- if (!isPlainObject(item) || !Object.hasOwn(item, key)) return false;
1547
- const id = item[key];
1548
- if (typeof id !== "string" || id === "") return false;
1549
- if (seen.has(id)) return false;
1550
- seen.add(id);
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 identityKeyFor(bag, source) {
1555
- for (const key of ARRAY_IDENTITY_KEYS) if (isUniquelyKeyedBy(bag, key) && isUniquelyKeyedBy(source, key)) return key;
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 positionListByCrossStackSource(bag, source, secrets) {
1558
- const association = associationForSource(source, secrets);
1559
- if (association === void 0) return void 0;
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
- // src/deployment/secret-redaction/redact-path/array-drop.ts
1564
- const NEVER_DROPPING_INTRINSICS = /* @__PURE__ */ new Set([
1565
- "Fn::Join",
1566
- "Fn::Sub",
1567
- "Fn::Select",
1568
- "Fn::Split",
1569
- "Fn::GetAtt"
1570
- ]);
1571
- function arrayElementDrop(element, depth = 0) {
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 sourceElementsKeptFor(source, bagLength, secrets) {
1589
- const recorded = secrets && droppedArrayElementsOf(secrets, source);
1590
- if (recorded !== void 0) {
1591
- if (source.length - recorded.length !== bagLength) return void 0;
1592
- return source.filter((_, i) => !recorded.includes(i));
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
- const drops = source.map((element) => arrayElementDrop(element));
1595
- if (drops.includes("unknown")) return void 0;
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
- function keptLiteralsCorroborate(kept, bag, secrets) {
1606
- return kept.every((element, i) => keptElementCorroborates(element, bag[i], secrets));
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 isIntrinsicNode(value) {
1609
- if (!isPlainObject(value)) return false;
1610
- const keys = Object.keys(value);
1611
- return keys.length === 1 && (keys[0] === "Ref" || keys[0].startsWith("Fn::"));
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 keptElementCorroborates(source, bag, secrets, depth = 0) {
1614
- if (depth > 16) return false;
1615
- if (typeof source === "string") {
1616
- if (!source.includes("{{resolve:")) return source === bag;
1617
- return isSingleDynamicReferenceToken(source) && resolvedPlaintextOf(secrets, source) === bag;
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 (source === null || typeof source !== "object") return source === bag;
1620
- if (isIntrinsicNode(source)) return true;
1621
- if (Array.isArray(source)) return Array.isArray(bag) && bag.length === source.length && source.every((element, i) => keptElementCorroborates(element, bag[i], secrets, depth + 1));
1622
- if (!isPlainObject(source) || !isPlainObject(bag)) return false;
1623
- if (Object.keys(bag).some((key) => !Object.hasOwn(source, key))) return false;
1624
- return Object.entries(source).every(([key, value]) => Object.hasOwn(bag, key) ? keptElementCorroborates(value, bag[key], secrets, depth + 1) : arrayElementDrop(value) === "always" || arrayElementDrop(value) === "maybe");
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 arrayPairsWhateverDrops(source) {
1637
- 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;
1638
- return source.every((element) => corroboratesWhateverResolves(element));
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
- // src/deployment/secret-redaction/redact-path/subtree.ts
1642
- function isReadbackProjectedFromState(rules) {
1643
- return rules.trustAnyExpression && !rules.descendArrays && rules.sourceIsSameGeneration;
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 subtreeHasDynamicReference(value) {
1646
- if (isDynamicReferenceString(value)) return true;
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 pathCrossesDottedKey(bag, path) {
1652
- const segments = path.split(".");
1653
- let cursor = bag;
1654
- for (let i = 0; i < segments.length; i++) {
1655
- if (cursor === null || typeof cursor !== "object" || Array.isArray(cursor)) return false;
1656
- const rest = segments.slice(i).join(".");
1657
- for (const key of Object.keys(cursor)) if (key.includes(".") && (rest === key || rest.startsWith(`${key}.`))) return true;
1658
- if (!Object.hasOwn(cursor, segments[i])) return false;
1659
- cursor = cursor[segments[i]];
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 false;
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/redact-path/json-equality.ts
1665
- function hasPlainPrototype(value) {
1666
- const proto = Object.getPrototypeOf(value);
1667
- return proto === Object.prototype || proto === null;
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
- function isOrdinaryDate(value) {
1670
- if (Object.getPrototypeOf(value) !== Date.prototype) return false;
1671
- try {
1672
- Date.prototype.getTime.call(value);
1673
- } catch {
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
- return Reflect.ownKeys(value).length === 0;
2082
+ budget.remaining -= 1;
2083
+ out.push(part);
1677
2084
  }
1678
- function deepEqualJsonValue(a, b) {
1679
- if (a === b) return true;
1680
- if (Array.isArray(a)) {
1681
- if (!Array.isArray(b) || a.length !== b.length) return false;
1682
- return a.every((item, i) => deepEqualJsonValue(item, b[i]));
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
- if (isPlainObject(a)) {
1685
- if (!isPlainObject(b)) return false;
1686
- if (!hasPlainPrototype(a) || !hasPlainPrototype(b)) return false;
1687
- const keys = Object.keys(a);
1688
- if (keys.length !== Object.keys(b).length) return false;
1689
- return keys.every((k) => Object.hasOwn(b, k) && deepEqualJsonValue(a[k], b[k]));
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
- // src/deployment/secret-redaction/redact-path/definition.ts
1695
- const DEFINITION_SOURCE_KEYS = [
1696
- "DefinitionSubstitutions",
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
- return walk(value);
1725
- }
1726
- const SENTINEL_IN_STRING = "";
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 sentinelDefinitionOf(source) {
1732
- const subs = source["DefinitionSubstitutions"];
1733
- const values = /* @__PURE__ */ new Map();
1734
- if (isPlainObject(subs)) {
1735
- for (const [name, value] of Object.entries(subs)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values.set(name, String(value));
1736
- }
1737
- for (const key of ["DefinitionString", "Definition"]) {
1738
- if (!Object.hasOwn(source, key)) continue;
1739
- const raw = source[key];
1740
- const body = typeof raw === "string" ? raw : isPlainObject(raw) ? JSON.stringify(raw) : void 0;
1741
- if (body === void 0) continue;
1742
- if (body.includes(SENTINEL_IN_STRING) || body.includes(SENTINEL_OUT_OF_STRING) || /\\u[eE]00[01]/.test(body)) continue;
1743
- const names = [];
1744
- let text = "";
1745
- let inString = false;
1746
- let escaped = false;
1747
- const feed = (c) => {
1748
- text += c;
1749
- if (inString) {
1750
- if (escaped) escaped = false;
1751
- else if (c === "\\") escaped = true;
1752
- else if (c === "\"") inString = false;
1753
- } else if (c === "\"") inString = true;
1754
- };
1755
- for (let i = 0; i < body.length; i++) {
1756
- if (body.startsWith("${", i)) {
1757
- const end = body.indexOf("}", i + 2);
1758
- const name = end === -1 ? void 0 : body.slice(i + 2, end);
1759
- const value = name === void 0 ? void 0 : values.get(name);
1760
- if (name !== void 0 && value !== void 0) {
1761
- if (substitutionIsSecret(value)) {
1762
- const index = names.push(name) - 1;
1763
- text += inString ? `${SENTINEL_IN_STRING}${index}${SENTINEL_IN_STRING}` : `"${SENTINEL_OUT_OF_STRING}${index}${SENTINEL_OUT_OF_STRING}"`;
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
- feed(body[i]);
1770
- }
1771
- let parsed;
1772
- try {
1773
- parsed = JSON.parse(text);
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 (isPlainObject(node)) {
1812
- const own = new Set(Object.keys(node).map(written));
1813
- for (const [k, v] of Object.entries(node)) {
1814
- if (!marked(k)) keys.add(k);
1815
- walk(v, [...path, written(k)], [...shapes, own]);
1816
- }
2193
+ if (expression === void 0) {
2194
+ if (unknown) return void 0;
2195
+ unknown = true;
2196
+ side = after;
2197
+ continue;
1817
2198
  }
1818
- };
1819
- walk(parsed, [], []);
1820
- try {
1821
- collectObjectKeys(JSON.parse(body), keys);
1822
- } catch {}
1823
- return {
1824
- keys,
1825
- strings,
1826
- scalars,
1827
- secretLeaves
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 alignedSecretLeaf(root, leaf) {
1832
- let cursor = root;
1833
- for (const [depth, segment] of leaf.path.entries()) {
1834
- const shape = leaf.shapes[depth];
1835
- if (typeof shape === "number") {
1836
- if (!Array.isArray(cursor) || cursor.length !== shape) return void 0;
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
- return { value: cursor };
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
- function collectObjectKeys(value, into) {
1849
- if (Array.isArray(value)) for (const item of value) collectObjectKeys(item, into);
1850
- else if (isPlainObject(value)) for (const [k, v] of Object.entries(value)) {
1851
- into.add(k);
1852
- collectObjectKeys(v, into);
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 spelledKeysOf(properties) {
1856
- const keys = /* @__PURE__ */ new Set();
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 replaceAtPath(root, path, leaf) {
1884
- if (path.length === 0) return leaf;
1885
- const [head, ...rest] = path;
1886
- if (Array.isArray(root)) {
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/template-literal.ts
1898
- function isSourcePlainLiteral(bag, source, rules) {
1899
- return rules.sourceIsTemplate === true && typeof bag === "string" && bag === source && !isDynamicReferenceString(source);
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 secretRerenderPairs(secrets) {
1902
- const pairs = [];
1903
- for (const [plaintext, expression] of secrets) {
1904
- if (plaintext === "" || expression === "***") continue;
1905
- if (!isSingleDynamicReferenceToken(expression)) continue;
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
- return pairs;
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 rerenderedSourceLiteral(bag, source, secrets, rules) {
1911
- if (typeof bag !== "string" || typeof source !== "string") return void 0;
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 keepTemplateLiteralLeaves(redacted, raw, template, secrets) {
1919
- if (typeof raw === "string") {
1920
- if (redacted === "***") return redacted;
1921
- if (raw === template && !isDynamicReferenceString(raw)) return raw;
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
- const TEMPLATE_SOURCE = {
1946
- descendArrays: false,
1947
- trustAnyExpression: false,
1948
- sourceIsSameGeneration: false,
1949
- sourceIsTemplate: true
1950
- };
1951
- function isPlainRecord(value) {
1952
- return isPlainObject(value) && hasPlainPrototype(value);
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
- // src/deployment/secret-redaction/redact-path/reference-tokens.ts
1956
- const DYNAMIC_REFERENCE_TOKEN_SCAN = new RegExp(`\\{\\{resolve:${DYNAMIC_REFERENCE_INNER}\\}\\}`, "g");
1957
- function dynamicReferenceTokens(value) {
1958
- return value.match(DYNAMIC_REFERENCE_TOKEN_SCAN) ?? [];
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 dynamicReferenceSpans(value) {
1961
- DYNAMIC_REFERENCE_TOKEN_SCAN.lastIndex = 0;
1962
- const spans = [];
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
- function mixedLeafMayCarryPublicReference(source, secrets, readback) {
1970
- if (secrets.size === 0) return mixedLeafProvenPublic(source, secrets, readback);
1971
- return dynamicReferenceTokens(source).some((token) => token.startsWith("{{resolve:ssm:") && !isRecordedSecretExpression(token));
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 mixedLeafProvenPublic(source, secrets, readback) {
1974
- const tokens = dynamicReferenceTokens(source);
1975
- if (tokens.length === 0) return false;
1976
- const values = /* @__PURE__ */ new Map();
1977
- for (const token of tokens) {
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
- // src/deployment/secret-redaction/redact-path/literal-rendering.ts
1988
- function positionByLiteralRendering(bag, source, secrets, rules, scan) {
1989
- if (rules.sourceIsTemplate !== true || typeof bag !== "string") return void 0;
1990
- if (suspended > 0) return void 0;
1991
- if (!isPlainObject(source)) return void 0;
1992
- visits = 0;
1993
- walking = secrets;
1994
- try {
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
- function renderLeaf(bag, source, secrets, scan) {
2001
- const plaintextOf = tokenPlaintexts(secrets);
2002
- const recorded = [...secrets.keys()];
2003
- const copies = [...physicalNameCopiesOf.get(secrets) ?? []];
2004
- const ifArgs = source["Fn::If"];
2005
- if (Object.keys(source).length === 1 && Array.isArray(ifArgs)) {
2006
- if (ifArgs.length !== 3) return void 0;
2007
- const taken = takenIfBranchOf(secrets, source);
2008
- if (taken !== void 0) {
2009
- const branch = taken ? ifArgs[1] : ifArgs[2];
2010
- if (isNoValue(branch)) return void 0;
2011
- const segments = renderSegments(branch, 1);
2012
- return segments === void 0 ? void 0 : placeAnchors(segments, plaintextOf, bag, scan, recorded, copies);
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
- const spellings = /* @__PURE__ */ new Set();
2015
- for (const branch of [ifArgs[1], ifArgs[2]]) {
2016
- if (isNoValue(branch)) continue;
2017
- const segments = renderSegments(branch, 1);
2018
- if (segments === void 0 || segments.some((s) => "gap" in s)) return void 0;
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 spellings.size === 1 ? [...spellings][0] : void 0;
2023
- }
2024
- const segments = renderSegments(source, 0);
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
- function staticTemplateText(node) {
2029
- const outer = walking;
2030
- const outerVisits = visits;
2031
- walking = void 0;
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
- let walking;
2048
- let suspended = 0;
2049
- function withoutLiteralRendering(run) {
2050
- suspended++;
2051
- try {
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
- function placeAnchors(segments, plaintextOf, bag, scan, plaintexts, physicalNameCopies) {
2058
- const anchors = [];
2059
- let leadingGap = false;
2060
- let trailingGap = false;
2061
- let current;
2062
- for (const segment of segments) {
2063
- if ("gap" in segment) {
2064
- if (current !== void 0) {
2065
- anchors.push(current);
2066
- current = void 0;
2067
- } else if (anchors.length === 0) leadingGap = true;
2068
- trailingGap = true;
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
- trailingGap = false;
2072
- current ??= {
2073
- rendered: "",
2074
- persisted: ""
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
- if ("text" in segment) {
2077
- current.rendered += segment.text;
2078
- current.persisted += segment.text;
2079
- } else {
2080
- const plaintext = plaintextOf.get(segment.token);
2081
- if (plaintext === void 0) return void 0;
2082
- current.rendered += plaintext;
2083
- current.persisted += segment.token;
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 placements(anchors, bag, leadingGap, trailingGap, side) {
2137
- const out = new Array(anchors.length);
2138
- if (side === "left") {
2139
- let cursor = 0;
2140
- for (let i = 0; i < anchors.length; i++) {
2141
- const text = anchors[i].rendered;
2142
- const pinnedStart = i === 0 && !leadingGap;
2143
- const pinnedEnd = i === anchors.length - 1 && !trailingGap;
2144
- let at;
2145
- if (pinnedStart) at = 0;
2146
- else if (pinnedEnd) at = bag.length - text.length;
2147
- else at = bag.indexOf(text, cursor);
2148
- if (at < cursor || bag.slice(at, at + text.length) !== text) return void 0;
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 out;
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
- const MAX_DEPTH = 16;
2175
- const GAP = [{ gap: true }];
2176
- const MAX_SEGMENTS = 512;
2177
- const MAX_VISITS = 4096;
2178
- let visits = 0;
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 staticList(node) {
2230
- if (Array.isArray(node)) return node;
2231
- if (!isPlainObject(node) || Object.keys(node).length !== 1) return void 0;
2232
- const split = node["Fn::Split"];
2233
- if (!Array.isArray(split) || split.length !== 2) return void 0;
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 subSegments(text, variables, depth) {
2240
- const out = [];
2241
- let at = 0;
2242
- for (const match of text.matchAll(/\$\{([^}]*)\}/g)) {
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 stringSegments(value) {
2262
- const out = [];
2263
- let at = 0;
2264
- for (const span of dynamicReferenceSpans(value)) {
2265
- const text = value.slice(at, span.start);
2266
- if (text.includes("{{resolve:")) return void 0;
2267
- if (text !== "") out.push({ text });
2268
- out.push({ token: value.slice(span.start, span.end) });
2269
- at = span.end;
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 tokenPlaintexts(secrets) {
2277
- const out = /* @__PURE__ */ new Map();
2278
- const ambiguous = /* @__PURE__ */ new Set();
2279
- for (const [token, plaintext] of secretRerenderPairs(secrets)) {
2280
- const known = out.get(token);
2281
- if (known !== void 0 && known !== plaintext) ambiguous.add(token);
2282
- else out.set(token, plaintext);
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
- for (const token of ambiguous) out.delete(token);
2285
- return out;
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 rendered = positionByLiteralRendering(bag, source, secrets, rules, (text) => redactForState(text, {
2697
+ const valueScan = (text) => redactForState(text, {
2329
2698
  provenance: "value-scan",
2330
2699
  secrets
2331
- }));
2332
- if (rendered !== void 0) return rendered;
2333
- const certified = positionByCrossStackSource(bag, source, secrets);
2334
- if (certified !== void 0) return certified;
2335
- const placeheld = positionByParameterPlaceholders(bag, source, secrets);
2336
- if (placeheld !== void 0) return placeheld;
2337
- const positioned = positionByIntrinsicSkeleton(bag, source, secrets, secretExpressions);
2338
- if (positioned !== void 0) return positioned;
2339
- const framed = positionByIntrinsicFrame(bag, source, secrets, secretExpressions, bagIsSameGeneration);
2340
- if (framed !== void 0) return framed;
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 { recordSecretResolution as $, recordDroppedArrayElements as $t, readbackPathFor as A, isScopedSecretVerdict as An, withLegacyOverlapScan as At, isSameGenerationBag as B, recordNoEchoAttributeValues as Bn, staticTemplateText as Bt, noEchoComparison as C, splitGetAttStringForm as Cn, maskSecretsInError as Ct, noEchoParameterNodesAt as D, freshNoEchoValuesOf as Dn, legacyReferenceLeavesOnly as Dt, noEchoOutputsComparison as E, contradictProvenPublicExpression as En, legacyLeavesWithoutMask as Et, valueAtCoordinate as F, provenPublicValue as Fn, scrubResourceRecord as Ft, recordIntrinsicLeafResolutionAs as G, WHOLE_DYNAMIC_REFERENCE_PATTERN as Gn, secretRerenderPairs as Gt, markSameGenerationBag as H, recordProvenPublicExpression as Hn, dynamicReferenceSpans as Ht, witnessNormalize as I, recordDerivedMaskOnlyValue as In, withPhysicalNameCopies as It, mixedLiteralAnswered as J, maskMatchSpans as Jn, arrayPairsWhateverDrops as Jt, redactionClaimOf as K, isDynamicReferenceString as Kn, spelledKeysOf as Kt, liveMatchesUnresolvedTokenFrame as L, recordFreshNoEchoValuesIn as Ln, withoutPhysicalNameCopies as Lt, recordPassedNoEchoParameters as M, markNoEchoParameterClass as Mn, repairEmbeddedPhysicalNamesTowards as Mt, recordedNoEchoValuesOf as N, noEchoParameterPlaintextsOf as Nn, repairPhysicalNameCopyLeaves as Nt, noEchoParametersReadBy as O, isMaskOnlyPlaintext as On, overlapRuleAnswered as Ot, replaceAtCoordinates as P, pinScopedSecretVerdict as Pn, replaceEmbeddedPhysicalNameRewrites as Pt, openRecordingScope as Q, standsForInheritedSecret as Qt, carryRedactionMarks as R, recordMaskOnlyValue as Rn, spanNamesResolvableService as Rt, maskedLeafCoordinatesOf as S, recordCrossStackExpression as Sn, maskRecordedSecretsInText as St, noEchoLeavesOf as T, carryFreshNoEchoMark as Tn, differingStringLeaves as Tt, mergeResolvedPairs as U, wholeStringLeavesOf as Un, dynamicReferenceTokens as Ut, markLeafCertifiedBag as V, recordNoEchoParameterFreshValue as Vn, DYNAMIC_REFERENCE_TOKEN_SCAN as Vt, recordIntrinsicLeafResolution as W, withoutNoEchoParameterEntries as Wn, keepTemplateLiteralLeaves as Wt, redactForState as X, rereadParameterExpression as Xt, withLegacyMixedScan as Y, identityKeyFor as Yt, foldRecording as Z, splitOutsideDynamicReferences as Zt, canonicalJson as _, recordAttributeIdCopy as _n, recordLogOnlyValue as _t, liveHoldsFreshLeaves as a, inheritedParameterExpression as an, snapshotPassProvenance as at, maskReadbackAtCoordinates as b, nestedStackRowTagSpellingOf as bn, createSecretMasker as bt, blockDeviceMappingsDifferOnlyInDeleteOnTermination as c, recordInheritedParameterValue as cn, createUnionSecretMasker as ct, emrClusterInstancesReplaced as d, carriesFreshNoEchoValue as dn, literalSplitDelimitersOf as dt, recordTakenIfBranch as en, hasPassProvenance as et, canonicalLambdaFunctionName as f, embedsFreshNoEchoValue as fn, logOnlyValueCount as ft, canonicalCoordinates as g, physicalNameCopiesOf as gn, recordLogOnlySplitFragments as gt, sameLambdaFunctionAddress as h, recoverMaskedOutput as hn, recordLogOnlyParameterValue as ht, keyOrderFreeJson as i, inheritNestedStackParameterAssociations as in, recordReferenceResolution as it, readsNoEchoSource as j, isSecretExpressionByVerdictOrSpelling as jn, embeddedPhysicalNameRewrites as jt, passedNoEchoParametersOf as k, isNoEchoParameterPlaintext as kn, replaceWholeLeaves as kt, dbInstanceEngineChangeIsInPlace as l, redactInheritedParameterValue as ln, hasLogOnlyValues as lt, parseLambdaFunctionAddress as m, recordRecoverableMaskedOutput as mn, printingCorpusOf as mt, grantSentence as n, recordInheritedPseudoParameters as nn, passReadVersionsFor as nt, outputMapsEqual as o, inheritedRenderedToken as on, carryLogOnlyValues as ot, lambdaFunctionNameForMask as p, freshNoEchoLeafPositions as pn, logOnlyValuesOf as pt, resolvedPlaintextOf as q, isSingleDynamicReferenceToken as qn, pathCrossesDottedKey as qt, isReplacementCeiling as r, templateRereadsAccountId as rn, recordReferenceProvenanceEntry as rt, readDenialOf as s, recordInheritedParameterRead as sn, carryLogOnlyValuesCarriedBy as st, ReplacementRulesRegistry as t, inheritedPseudoValue as tn, passProvenanceFor as tt, ecsServiceLaunchTypeSetOrChanged as u, withdrawRenderedParameterSpelling as un, hasMaskableValues as ut, isMarkedCoordinate as v, recordPhysicalNameCopy as vn, shareLogOnlyValues as vt, noEchoCoordinatesOf as w, carriesSecretMask as wn, maskSecretsInText as wt, maskWholeValue as x, crossStackSourceKey as xn, errorCauseChain as xt, maskAtCoordinates as y, recordNestedStackParameterExpressions as yn, unionOfSecretBags as yt, intrinsicLeafResolutionOf as z, recordMaskOnlyValuesIn as zn, isUncertifiedBaselineMaskPosition as zt };
5608
- //# sourceMappingURL=replacement-rules-BimJi0H1.js.map
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