@kaynooo/env-tools 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ev.js CHANGED
@@ -789,13 +789,52 @@ var {Glob } = globalThis.Bun;
789
789
  var SESSION_FILES = new Glob("*.json");
790
790
  var ACCOUNT_DIRS = new Glob("*/sessions");
791
791
  // package.json
792
- var version = "0.7.1";
792
+ var version = "0.7.3";
793
793
 
794
794
  // src/commands/audit.ts
795
795
  import { stat as stat4 } from "fs/promises";
796
796
  import { relative, resolve } from "path";
797
797
  import process7 from "process";
798
798
 
799
+ // ../kit/src/shell.ts
800
+ var SEPARATORS = new Set([`
801
+ `, ";", "|"]);
802
+ var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
803
+ var GLOB_CHARS = new Set(["*", "?", "["]);
804
+ var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
805
+ var SAFE_WORD = /^[\w@%+=:,./-]+$/;
806
+ var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
807
+ var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
808
+ var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh"]);
809
+ var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, "su", "runuser"]);
810
+ var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
811
+ var PRINTERS = new Set(["echo", "printf"]);
812
+ var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
813
+ function wrapper(short = "", long = [], operands = 0) {
814
+ return { short, long, operands };
815
+ }
816
+ var WRAPPERS = new Map([
817
+ ["command", wrapper()],
818
+ ["builtin", wrapper()],
819
+ ["nohup", wrapper()],
820
+ ["setsid", wrapper()],
821
+ ["busybox", wrapper()],
822
+ ["exec", wrapper("a")],
823
+ ["time", wrapper("fo", ["--format", "--output"])],
824
+ ["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
825
+ ["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
826
+ ["doas", wrapper("uC")],
827
+ ["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
828
+ ["nice", wrapper("n", ["--adjustment"])],
829
+ ["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
830
+ ["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
831
+ ["chroot", wrapper("", ["--userspec", "--groups"], 1)],
832
+ ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
833
+ ]);
834
+ function shellQuote(word) {
835
+ return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
836
+ }
837
+
799
838
  // src/audit.ts
800
839
  import { readdir as readdir2, stat as stat2 } from "fs/promises";
801
840
  import { dirname as dirname2, join as join2 } from "path";
@@ -1517,7 +1556,6 @@ var options = {
1517
1556
  json: jsonOption("the findings and the folders it could not read"),
1518
1557
  fix: { type: "boolean", description: "move inline compose secrets into a .env and shut other accounts out" }
1519
1558
  };
1520
- var SHELL_SAFE = /^[\w./-]+$/;
1521
1559
  var MAX_UNREAD_LISTED = 3;
1522
1560
  var CHECKS = {
1523
1561
  same: "docker compose config resolves the same",
@@ -1532,9 +1570,6 @@ async function isFolder(path) {
1532
1570
  return false;
1533
1571
  }
1534
1572
  }
1535
- function quoted2(path) {
1536
- return SHELL_SAFE.test(path) ? path : `'${path.replaceAll("'", "'\\''")}'`;
1537
- }
1538
1573
  function shown(path) {
1539
1574
  return path.startsWith(`${process7.cwd()}/`) ? relative(process7.cwd(), path) : path;
1540
1575
  }
@@ -1553,9 +1588,9 @@ async function fixAll(exposed, json) {
1553
1588
  ...fix === undefined || fix.moved.length === 0 ? [] : [`moved ${fix.moved.join(", ")} into ${shown(fix.env)}`],
1554
1589
  ...fix?.left.map(({ key, why }) => `left ${key} in place: ${why}`) ?? [],
1555
1590
  ...fix?.check === undefined ? [] : [CHECKS[fix.check]],
1556
- ...open.map((file) => `another account owns ${file === path ? "it" : shown(file)}, so it stays readable: sudo chmod go-rwx ${quoted2(shown(file))}`),
1591
+ ...open.map((file) => `another account owns ${file === path ? "it" : shown(file)}, so it stays readable: sudo chmod go-rwx ${shellQuote(shown(file))}`),
1557
1592
  ...readable && !open.includes(path) ? ["now unreadable by other accounts"] : [],
1558
- ...tracked ? [`tracked by git: git rm --cached ${quoted2(shown(path))}, then ignore it`] : []
1593
+ ...tracked ? [`tracked by git: git rm --cached ${shellQuote(shown(path))}, then ignore it`] : []
1559
1594
  ];
1560
1595
  console.log(`${shown(path)}
1561
1596
  ${lines.join(`
@@ -1597,8 +1632,8 @@ async function audit2(args) {
1597
1632
  const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
1598
1633
  const problems = [
1599
1634
  ...secrets === undefined ? [] : [`writes out ${secrets.join(", ")}: ev audit --fix moves the values into a .env beside it`],
1600
- ...readable ? [group === true ? `readable by its group or an ACL: ${sudo}chmod go-rwx ${quoted2(shown(path))}` : `readable by any account: ${sudo}chmod o-rwx ${quoted2(shown(path))}`] : [],
1601
- ...tracked ? [`tracked by git: git rm --cached ${quoted2(shown(path))}, then ignore it`] : []
1635
+ ...readable ? [group === true ? `readable by its group or an ACL: ${sudo}chmod go-rwx ${shellQuote(shown(path))}` : `readable by any account: ${sudo}chmod o-rwx ${shellQuote(shown(path))}`] : [],
1636
+ ...tracked ? [`tracked by git: git rm --cached ${shellQuote(shown(path))}, then ignore it`] : []
1602
1637
  ];
1603
1638
  console.log(`${shown(path)}
1604
1639
  ${problems.join(`
package/dist/redact.js CHANGED
@@ -789,7 +789,7 @@ var {Glob } = globalThis.Bun;
789
789
  var SESSION_FILES = new Glob("*.json");
790
790
  var ACCOUNT_DIRS = new Glob("*/sessions");
791
791
  // package.json
792
- var version = "0.7.1";
792
+ var version = "0.7.3";
793
793
 
794
794
  // src/files.ts
795
795
  import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from "fs/promises";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/env-tools",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.3",
5
5
  "description": "ev lists and edits .env files with secrets masked, redact masks secrets in any piped output.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",