cdk-real-drift 0.12.8 → 0.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -637,7 +637,11 @@ Elastic Beanstalk env-namespace `OptionSettings`, EC2 LaunchTemplate `UserData`
637
637
  are masked as `<redacted:NN chars>` in both text and `--json` output, so a rotated
638
638
  secret surfacing as drift does not leak its plaintext into CI logs. The finding
639
639
  still surfaces (detection is preserved) and the property/key name stays visible —
640
- only the value is hidden (#798).
640
+ only the value is hidden. The same protection covers persistence: `record` writes a
641
+ **hash** of these values into the git-committed baseline instead of the plaintext, so
642
+ the secret never lands in a committed file while a later change still re-surfaces as
643
+ drift (an unchanged one stays recorded). Older baselines holding a plaintext value keep
644
+ comparing correctly and migrate to the hashed form on the next `record` (#798).
641
645
 
642
646
  A **stack that errored or was skipped** before it could be checked still appears as an
643
647
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
package/dist/cli.js CHANGED
@@ -11780,6 +11780,113 @@ function stackCountAnnouncement(stackNames) {
11780
11780
  return `note: checking ${stackNames.length} stack(s): ${stackNames.join(", ")}`;
11781
11781
  }
11782
11782
 
11783
+ //#endregion
11784
+ //#region src/report/redact.ts
11785
+ function maskPlaceholder(value) {
11786
+ if (typeof value === "string") return `<redacted:${value.length} chars>`;
11787
+ return "<redacted>";
11788
+ }
11789
+ const maskWhole = (value) => maskPlaceholder(value);
11790
+ const maskEntryValueField = (value) => {
11791
+ if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
11792
+ ...value,
11793
+ Value: maskPlaceholder(value.Value)
11794
+ };
11795
+ return maskPlaceholder(value);
11796
+ };
11797
+ const maskMapValues = (value) => {
11798
+ if (value && typeof value === "object" && !Array.isArray(value)) {
11799
+ const out = {};
11800
+ for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
11801
+ return out;
11802
+ }
11803
+ return maskPlaceholder(value);
11804
+ };
11805
+ const REDACTED_VALUE_PATHS = {
11806
+ "AWS::Lambda::Function": [{
11807
+ pathRe: /(^|\.)Environment\.Variables\./,
11808
+ redact: maskWhole
11809
+ }, {
11810
+ pathRe: /(^|\.)Environment\.Variables$/,
11811
+ redact: maskMapValues
11812
+ }],
11813
+ "AWS::CodeBuild::Project": [{
11814
+ pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
11815
+ redact: maskWhole
11816
+ }],
11817
+ "AWS::EC2::LaunchTemplate": [{
11818
+ pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
11819
+ redact: maskWhole
11820
+ }],
11821
+ "AWS::ElasticBeanstalk::Environment": [{
11822
+ pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
11823
+ redact: maskEntryValueField
11824
+ }]
11825
+ };
11826
+ function redactValue(resourceType, path, value) {
11827
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
11828
+ if (!matchers) return value;
11829
+ if (isRedactedHashSentinel(value)) return "<redacted>";
11830
+ for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
11831
+ return value;
11832
+ }
11833
+ function isRedactedPath(resourceType, path) {
11834
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
11835
+ return !!matchers && matchers.some((m) => m.pathRe.test(path));
11836
+ }
11837
+ function redactFinding(f) {
11838
+ if (!isRedactedPath(f.resourceType, f.path)) return f;
11839
+ const out = { ...f };
11840
+ if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
11841
+ if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
11842
+ if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
11843
+ return out;
11844
+ }
11845
+ function redactArrayDelta(resourceType, path, d) {
11846
+ const mv = (v) => redactValue(resourceType, path, v);
11847
+ return {
11848
+ identityField: d.identityField,
11849
+ added: d.added.map((a) => ({
11850
+ id: a.id,
11851
+ value: mv(a.value)
11852
+ })),
11853
+ removed: d.removed.map((r) => ({
11854
+ id: r.id,
11855
+ value: mv(r.value)
11856
+ })),
11857
+ changed: d.changed.map((c) => ({
11858
+ id: c.id,
11859
+ recorded: mv(c.recorded),
11860
+ actual: mv(c.actual)
11861
+ }))
11862
+ };
11863
+ }
11864
+ const REDACTION_HASH_KEY = "__cdkrdRedactedSha256__";
11865
+ function stableStringify(v) {
11866
+ const sortDeep = (x) => {
11867
+ if (Array.isArray(x)) return x.map(sortDeep);
11868
+ if (x && typeof x === "object") {
11869
+ const out = {};
11870
+ for (const k of Object.keys(x).sort()) out[k] = sortDeep(x[k]);
11871
+ return out;
11872
+ }
11873
+ return x;
11874
+ };
11875
+ return JSON.stringify(sortDeep(v)) ?? "null";
11876
+ }
11877
+ function hashOfCanonical(canonicalValue) {
11878
+ return "sha256:" + createHash("sha256").update(stableStringify(canonicalValue)).digest("hex");
11879
+ }
11880
+ function redactedHashSentinel(canonicalValue) {
11881
+ return { [REDACTION_HASH_KEY]: hashOfCanonical(canonicalValue) };
11882
+ }
11883
+ function isRedactedHashSentinel(v) {
11884
+ return !!v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 1 && typeof v[REDACTION_HASH_KEY] === "string";
11885
+ }
11886
+ function redactedHashOf(sentinelOrCanonical) {
11887
+ return isRedactedHashSentinel(sentinelOrCanonical) ? sentinelOrCanonical[REDACTION_HASH_KEY] ?? hashOfCanonical(sentinelOrCanonical) : hashOfCanonical(sentinelOrCanonical);
11888
+ }
11889
+
11783
11890
  //#endregion
11784
11891
  //#region src/baseline/baseline-file.ts
11785
11892
  const KNOWN_BASELINE_KEYS = new Set([
@@ -12081,7 +12188,7 @@ function buildRecorded(findings) {
12081
12188
  logicalId: f.logicalId,
12082
12189
  resourceType: f.resourceType,
12083
12190
  path: f.path,
12084
- value: f.actual
12191
+ value: isRedactedPath(f.resourceType, f.path) ? redactedHashSentinel(canonicalizeBaselineForCompare(f.actual, f.resourceType)) : f.actual
12085
12192
  }));
12086
12193
  }
12087
12194
  /** Stable key uniquely identifying an undeclared finding / recorded entry, for
@@ -12191,6 +12298,10 @@ function carryForwardIgnored(recorded, existing, findings) {
12191
12298
  * order-significant declared array, so an order-insensitive sort is safe here.
12192
12299
  */
12193
12300
  function baselineValueMatches(baselineValue, currentCanonicalValue, resourceType) {
12301
+ if (isRedactedHashSentinel(baselineValue) || isRedactedHashSentinel(currentCanonicalValue)) {
12302
+ const asHash = (v) => redactedHashOf(isRedactedHashSentinel(v) ? v : canonicalizeBaselineForCompare(v, resourceType));
12303
+ return asHash(baselineValue) === asHash(currentCanonicalValue);
12304
+ }
12194
12305
  return deepEqual(canonicalizeBaselineForCompare(baselineValue, resourceType), canonicalizeBaselineForCompare(currentCanonicalValue, resourceType));
12195
12306
  }
12196
12307
  const DELTA_IDENTITY_FIELDS = [
@@ -16455,87 +16566,6 @@ function annotateHints(findings) {
16455
16566
  });
16456
16567
  }
16457
16568
 
16458
- //#endregion
16459
- //#region src/report/redact.ts
16460
- function maskPlaceholder(value) {
16461
- if (typeof value === "string") return `<redacted:${value.length} chars>`;
16462
- return "<redacted>";
16463
- }
16464
- const maskWhole = (value) => maskPlaceholder(value);
16465
- const maskEntryValueField = (value) => {
16466
- if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
16467
- ...value,
16468
- Value: maskPlaceholder(value.Value)
16469
- };
16470
- return maskPlaceholder(value);
16471
- };
16472
- const maskMapValues = (value) => {
16473
- if (value && typeof value === "object" && !Array.isArray(value)) {
16474
- const out = {};
16475
- for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
16476
- return out;
16477
- }
16478
- return maskPlaceholder(value);
16479
- };
16480
- const REDACTED_VALUE_PATHS = {
16481
- "AWS::Lambda::Function": [{
16482
- pathRe: /(^|\.)Environment\.Variables\./,
16483
- redact: maskWhole
16484
- }, {
16485
- pathRe: /(^|\.)Environment\.Variables$/,
16486
- redact: maskMapValues
16487
- }],
16488
- "AWS::CodeBuild::Project": [{
16489
- pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
16490
- redact: maskWhole
16491
- }],
16492
- "AWS::EC2::LaunchTemplate": [{
16493
- pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
16494
- redact: maskWhole
16495
- }],
16496
- "AWS::ElasticBeanstalk::Environment": [{
16497
- pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
16498
- redact: maskEntryValueField
16499
- }]
16500
- };
16501
- function redactValue(resourceType, path, value) {
16502
- const matchers = REDACTED_VALUE_PATHS[resourceType];
16503
- if (!matchers) return value;
16504
- for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
16505
- return value;
16506
- }
16507
- function isRedactedPath(resourceType, path) {
16508
- const matchers = REDACTED_VALUE_PATHS[resourceType];
16509
- return !!matchers && matchers.some((m) => m.pathRe.test(path));
16510
- }
16511
- function redactFinding(f) {
16512
- if (!isRedactedPath(f.resourceType, f.path)) return f;
16513
- const out = { ...f };
16514
- if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
16515
- if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
16516
- if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
16517
- return out;
16518
- }
16519
- function redactArrayDelta(resourceType, path, d) {
16520
- const mv = (v) => redactValue(resourceType, path, v);
16521
- return {
16522
- identityField: d.identityField,
16523
- added: d.added.map((a) => ({
16524
- id: a.id,
16525
- value: mv(a.value)
16526
- })),
16527
- removed: d.removed.map((r) => ({
16528
- id: r.id,
16529
- value: mv(r.value)
16530
- })),
16531
- changed: d.changed.map((c) => ({
16532
- id: c.id,
16533
- recorded: mv(c.recorded),
16534
- actual: mv(c.actual)
16535
- }))
16536
- };
16537
- }
16538
-
16539
16569
  //#endregion
16540
16570
  //#region src/report/report.ts
16541
16571
  function stackNameFromHeader(header) {