cdk-real-drift 0.10.0 → 0.10.1

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
@@ -631,6 +631,14 @@ builds printed one pretty-printed `{...}` per stack back-to-back, which was neit
631
631
  valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.) All
632
632
  `note` / `warning` / progress lines go to **stderr**, so stdout stays pure JSON.
633
633
 
634
+ **Secret redaction.** Values on known secret-bearing properties — Lambda
635
+ `Environment.Variables`, CodeBuild `Environment.EnvironmentVariables[].Value`,
636
+ Elastic Beanstalk env-namespace `OptionSettings`, EC2 LaunchTemplate `UserData` —
637
+ are masked as `<redacted:NN chars>` in both text and `--json` output, so a rotated
638
+ secret surfacing as drift does not leak its plaintext into CI logs. The finding
639
+ still surfaces (detection is preserved) and the property/key name stays visible —
640
+ only the value is hidden (#798).
641
+
634
642
  A **stack that errored or was skipped** before it could be checked still appears as an
635
643
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
636
644
  `"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
package/dist/cli.js CHANGED
@@ -15837,6 +15837,87 @@ function annotateHints(findings) {
15837
15837
  });
15838
15838
  }
15839
15839
 
15840
+ //#endregion
15841
+ //#region src/report/redact.ts
15842
+ function maskPlaceholder(value) {
15843
+ if (typeof value === "string") return `<redacted:${value.length} chars>`;
15844
+ return "<redacted>";
15845
+ }
15846
+ const maskWhole = (value) => maskPlaceholder(value);
15847
+ const maskEntryValueField = (value) => {
15848
+ if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
15849
+ ...value,
15850
+ Value: maskPlaceholder(value.Value)
15851
+ };
15852
+ return maskPlaceholder(value);
15853
+ };
15854
+ const maskMapValues = (value) => {
15855
+ if (value && typeof value === "object" && !Array.isArray(value)) {
15856
+ const out = {};
15857
+ for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
15858
+ return out;
15859
+ }
15860
+ return maskPlaceholder(value);
15861
+ };
15862
+ const REDACTED_VALUE_PATHS = {
15863
+ "AWS::Lambda::Function": [{
15864
+ pathRe: /(^|\.)Environment\.Variables\./,
15865
+ redact: maskWhole
15866
+ }, {
15867
+ pathRe: /(^|\.)Environment\.Variables$/,
15868
+ redact: maskMapValues
15869
+ }],
15870
+ "AWS::CodeBuild::Project": [{
15871
+ pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
15872
+ redact: maskWhole
15873
+ }],
15874
+ "AWS::EC2::LaunchTemplate": [{
15875
+ pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
15876
+ redact: maskWhole
15877
+ }],
15878
+ "AWS::ElasticBeanstalk::Environment": [{
15879
+ pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
15880
+ redact: maskEntryValueField
15881
+ }]
15882
+ };
15883
+ function redactValue(resourceType, path, value) {
15884
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
15885
+ if (!matchers) return value;
15886
+ for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
15887
+ return value;
15888
+ }
15889
+ function isRedactedPath(resourceType, path) {
15890
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
15891
+ return !!matchers && matchers.some((m) => m.pathRe.test(path));
15892
+ }
15893
+ function redactFinding(f) {
15894
+ if (!isRedactedPath(f.resourceType, f.path)) return f;
15895
+ const out = { ...f };
15896
+ if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
15897
+ if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
15898
+ if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
15899
+ return out;
15900
+ }
15901
+ function redactArrayDelta(resourceType, path, d) {
15902
+ const mv = (v) => redactValue(resourceType, path, v);
15903
+ return {
15904
+ identityField: d.identityField,
15905
+ added: d.added.map((a) => ({
15906
+ id: a.id,
15907
+ value: mv(a.value)
15908
+ })),
15909
+ removed: d.removed.map((r) => ({
15910
+ id: r.id,
15911
+ value: mv(r.value)
15912
+ })),
15913
+ changed: d.changed.map((c) => ({
15914
+ id: c.id,
15915
+ recorded: mv(c.recorded),
15916
+ actual: mv(c.actual)
15917
+ }))
15918
+ };
15919
+ }
15920
+
15840
15921
  //#endregion
15841
15922
  //#region src/report/report.ts
15842
15923
  function stackNameFromHeader(header) {
@@ -15889,42 +15970,45 @@ function formatFinding(f, stackName = "") {
15889
15970
  const pathDisplay = f.attributeKey ? `${f.path}[${sanitizeForTerminal(f.attributeKey)}]` : f.path;
15890
15971
  let s = `${pathDisplay ? `${id}.${pathDisplay}` : id} (${f.resourceType})`;
15891
15972
  if (f.note) s += ` — ${sanitizeForTerminal(f.note)}`;
15892
- if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false);
15973
+ const rt = f.resourceType;
15974
+ const rd = (v) => redactValue(rt, f.path, v);
15975
+ if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false, rt, f.path);
15893
15976
  else {
15894
- const { a: d, b: act } = jPair(f.desired, f.actual);
15977
+ const { a: d, b: act } = jPair(rd(f.desired), rd(f.actual));
15895
15978
  s += `\n desired=${style.desired(d)}\n actual =${style.actual(act)}`;
15896
15979
  }
15897
- else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
15980
+ else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
15898
15981
  else {
15899
- const { a: base, b: act } = jPair(f.desired, f.actual);
15982
+ const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
15900
15983
  s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15901
15984
  }
15902
- else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(f.actual))}`;
15903
- else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta);
15904
- else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
15985
+ else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(rd(f.actual)))}`;
15986
+ else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta, rt, f.path);
15987
+ else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
15905
15988
  else {
15906
- const { a: base, b: act } = jPair(f.desired, f.actual);
15989
+ const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
15907
15990
  s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15908
15991
  }
15909
- else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(f.actual))}`;
15992
+ else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(rd(f.actual)))}`;
15910
15993
  if (f.hint) s += `\n ${style.note(`↳ ${sanitizeForTerminal(f.hint)}`)}`;
15911
15994
  return s;
15912
15995
  }
15913
15996
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
15914
- function formatMapDelta(desired, actual, baselineLabels) {
15997
+ function formatMapDelta(desired, actual, baselineLabels, resourceType, basePath) {
15915
15998
  const lhs = baselineLabels ? "baseline" : "desired";
15916
15999
  const rhs = baselineLabels ? "actual " : "actual ";
15917
16000
  const keys = [...new Set([...Object.keys(desired), ...Object.keys(actual)])].sort();
16001
+ const rd = (k, v) => resourceType !== void 0 && basePath !== void 0 ? redactValue(resourceType, `${basePath}.${k}`, v) : v;
15918
16002
  let s = "";
15919
16003
  for (const k of keys) {
15920
16004
  const inD = Object.hasOwn(desired, k);
15921
16005
  if (inD && Object.hasOwn(actual, k)) {
15922
16006
  if (deepEqual(desired[k], actual[k])) continue;
15923
- const { a, b } = jPair(desired[k], actual[k]);
16007
+ const { a, b } = jPair(rd(k, desired[k]), rd(k, actual[k]));
15924
16008
  const sk = sanitizeForTerminal(k);
15925
16009
  s += `\n ~ ${sk}\n ${lhs}=${style.desired(a)}\n ${rhs}=${style.actual(b)}`;
15926
- } else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(desired[k]))}`;
15927
- else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(actual[k]))}`;
16010
+ } else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(rd(k, desired[k])))}`;
16011
+ else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(rd(k, actual[k])))}`;
15928
16012
  }
15929
16013
  if (s === "") {
15930
16014
  const { a, b } = jPair(desired, actual);
@@ -15932,13 +16016,14 @@ function formatMapDelta(desired, actual, baselineLabels) {
15932
16016
  }
15933
16017
  return s;
15934
16018
  }
15935
- function formatArrayDelta(d) {
15936
- const baseline = (v) => `\n baseline=${style.desired(j(v))}`;
15937
- const actual = (v) => `\n actual =${style.actual(j(v))}`;
16019
+ function formatArrayDelta(d, resourceType, path) {
16020
+ const rd = (v) => resourceType !== void 0 && path !== void 0 ? redactValue(resourceType, path, v) : v;
16021
+ const baseline = (v) => `\n baseline=${style.desired(j(rd(v)))}`;
16022
+ const actual = (v) => `\n actual =${style.actual(j(rd(v)))}`;
15938
16023
  let s = ` — ${sanitizeForTerminal(d.identityField)}-keyed element(s) changed vs .cdkrd baseline:`;
15939
16024
  for (const a of d.added) s += `\n + [${sanitizeForTerminal(a.id)}]${actual(a.value)}`;
15940
16025
  for (const c of d.changed) {
15941
- const { a: base, b: act } = jPair(c.recorded, c.actual);
16026
+ const { a: base, b: act } = jPair(rd(c.recorded), rd(c.actual));
15942
16027
  s += `\n ~ [${sanitizeForTerminal(c.id)}]\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15943
16028
  }
15944
16029
  for (const r of d.removed) s += `\n - [${sanitizeForTerminal(r.id)}]${baseline(r.value)}`;
@@ -15983,7 +16068,7 @@ function buildStackJson(rawFindings, header, hasBaseline) {
15983
16068
  json: {
15984
16069
  stack: header,
15985
16070
  drifted,
15986
- findings,
16071
+ findings: findings.map((f) => redactFinding(f)),
15987
16072
  baseline: hasBaseline === true
15988
16073
  },
15989
16074
  code: drifted === 0 ? 0 : 1