cdk-real-drift 0.12.17 → 0.12.19

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
@@ -634,9 +634,19 @@ valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.
634
634
  **Secret redaction.** Values on known secret-bearing properties — Lambda
635
635
  `Environment.Variables`, CodeBuild `Environment.EnvironmentVariables[].Value`,
636
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 —
637
+ are masked as `<redacted:NN chars:HHHHHHHH>` in both text and `--json` output, so a rotated
638
+ secret surfacing as drift does not leak its plaintext into CI logs. The `NN` is the
639
+ value's char length and `HHHHHHHH` is the first 8 hex of its sha256 — a **deterministic,
640
+ stable distinguisher** (#1308): the same secret masks to the same placeholder across runs,
641
+ so a consumer diffing two consecutive `--json` runs compares them correctly, while a
642
+ **rotated same-length** secret now masks to a **different** placeholder instead of a
643
+ byte-identical one (the length-only mask erased that change). The hash is non-reversible for
644
+ a high-entropy value; a low-entropy value's short hash is brute-forceable, so it is a
645
+ change-distinguisher, not a confidentiality guarantee — but the plaintext itself is never
646
+ printed. In `--json` a masked finding additionally carries a `"redacted": true` sibling, an
647
+ **out-of-band marker** so a consumer can tell a masked value from a literal live string that
648
+ happens to look like the placeholder (a non-secret finding has no `redacted` field). The
649
+ finding still surfaces (detection is preserved) and the property/key name stays visible —
640
650
  only the value is hidden. The same protection covers persistence: `record` writes a
641
651
  **hash** of these values into the git-committed baseline instead of the plaintext, so
642
652
  the secret never lands in a committed file while a later change still re-surfaces as
package/dist/cli.js CHANGED
@@ -563,6 +563,20 @@ const RULE_OBJECT_KEYS = new Set([
563
563
  "region"
564
564
  ]);
565
565
  const FILE_HEADER = "# cdkrd ignore rules — properties cdkrd should stop reporting as drift.\n# Each rule: { path, stack?, account?, region? }; `path` is a\n# \"<constructPath|logicalId>.<property>\" glob, the scopes narrow WHERE it applies.\n# Add a comment above a rule to record WHY it is ignored.\n";
566
+ function looksUtf16(buf, nulAtOddIndex) {
567
+ const n = Math.min(buf.length, 64);
568
+ if (n < 2) return false;
569
+ let pairs = 0;
570
+ for (let i = nulAtOddIndex ? 1 : 0; i < n; i += 2) {
571
+ if (buf[i] !== 0) return false;
572
+ pairs++;
573
+ }
574
+ return pairs > 0;
575
+ }
576
+ function decodeConfig(buf) {
577
+ const encoding = buf[0] === 255 && buf[1] === 254 ? "utf-16le" : buf[0] === 254 && buf[1] === 255 ? "utf-16be" : looksUtf16(buf, true) ? "utf-16le" : looksUtf16(buf, false) ? "utf-16be" : "utf-8";
578
+ return new TextDecoder(encoding).decode(buf);
579
+ }
566
580
  /**
567
581
  * Load `.cdkrd/ignore.yaml` (cwd-relative). Absent file -> empty config (no migration
568
582
  * needed). A comments-only / empty file parses to null -> empty config too. Invalid
@@ -575,7 +589,7 @@ const FILE_HEADER = "# cdkrd ignore rules — properties cdkrd should stop repor
575
589
  async function loadConfig() {
576
590
  let raw;
577
591
  try {
578
- raw = await readFile(CONFIG_PATH, "utf8");
592
+ raw = decodeConfig(await readFile(CONFIG_PATH));
579
593
  } catch (e) {
580
594
  if (e.code === "ENOENT") return { ignore: [] };
581
595
  throw e;
@@ -796,7 +810,7 @@ async function addIgnoreRules(newRules) {
796
810
  await mkdir(dirname(CONFIG_PATH), { recursive: true });
797
811
  let existingRaw;
798
812
  try {
799
- existingRaw = await readFile(CONFIG_PATH, "utf8");
813
+ existingRaw = decodeConfig(await readFile(CONFIG_PATH));
800
814
  } catch (e) {
801
815
  if (e.code !== "ENOENT") throw e;
802
816
  }
@@ -10794,7 +10808,7 @@ function resolveRefNode(node, definitions) {
10794
10808
  return n;
10795
10809
  }
10796
10810
  function pointerToDotted$1(p) {
10797
- return p.replace(/^\/properties\//, "").replace(/\/properties\//g, "/").replace(/\/properties$/, "").replace(/\//g, ".");
10811
+ return p.replace(/^\/?properties\//, "").replace(/\/properties\//g, "/").replace(/\/properties$/, "").replace(/\//g, ".");
10798
10812
  }
10799
10813
  function variantBranches(node) {
10800
10814
  return [
@@ -11856,7 +11870,10 @@ function stackCountAnnouncement(stackNames) {
11856
11870
  //#endregion
11857
11871
  //#region src/report/redact.ts
11858
11872
  function maskPlaceholder(value) {
11859
- if (typeof value === "string") return `<redacted:${value.length} chars>`;
11873
+ if (typeof value === "string") {
11874
+ const sig = createHash("sha256").update(value).digest("hex").slice(0, 8);
11875
+ return `<redacted:${value.length} chars:${sig}>`;
11876
+ }
11860
11877
  return "<redacted>";
11861
11878
  }
11862
11879
  const maskWhole = (value) => maskPlaceholder(value);
@@ -11909,7 +11926,10 @@ function isRedactedPath(resourceType, path) {
11909
11926
  }
11910
11927
  function redactFinding(f) {
11911
11928
  if (!isRedactedPath(f.resourceType, f.path)) return f;
11912
- const out = { ...f };
11929
+ const out = {
11930
+ ...f,
11931
+ redacted: true
11932
+ };
11913
11933
  if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
11914
11934
  if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
11915
11935
  if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);