secrez 2.2.0-beta.4 → 2.2.0-beta.7

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/CHANGELOG.md CHANGED
@@ -1,20 +1,16 @@
1
1
  # Changelog
2
2
 
3
- **2.2.0-beta.1**
3
+ **2.2.0**
4
4
 
5
+ - replace the system editor with an integrated in-memory editor for `edit`. Secrets stay in memory and are no longer written to temporary files. The `-e`/`--editor` and `-i`/`--internal` options are removed; the in-memory editor is the only editor
6
+ - change how `edit` treats the git repo. The remote check runs while you edit, instead of blocking before the editor opens. If the repository was changed outside Secrez, the editor closes and later writes stay blocked for the session: quit, sync the repo by hand, then start Secrez again. If Secrez is only behind the remote, editing continues; on save you can write anyway, or return to the unsaved text and leave it with Ctrl-c
5
7
  - remove deprecated `bash` command (use `shell` instead)
6
- - `edit` accepts dataset-qualified paths (e.g. `main:/file.yml`)
7
- - in-memory editor: `Ctrl-k` deletes the current line and pulls up the next one
8
- - replace `shell` command implementation: run commands with `spawn` and `cwd` instead of interpolating the working directory into a shell string (fixes command injection via malicious paths)
9
- - harden `ssh` command: validate user and host, pass arguments to `ttab`/`ssh` without shell interpolation (fixes command injection via crafted hostnames)
10
- - replace external editor with an in-memory editor for `edit`: secrets are no longer written to temporary files on disk; removed `-e`/`--editor` and `-i`/`--internal` options (the internal editor is now the only editor)
11
- - add `editorProvider` hook for tests and improve `edit` command test reliability
8
+ - stop interpolating commands into a shell string: `shell` and `ssh` pass arguments with `spawn`, and `totp --from-clipboard` does the same for `xclip`
12
9
  - vault permissions (FS-1): secure legacy containers to `0o700` dirs / `0o600` files at login
13
10
  - strengthen password-based export encryption (`.secrez` files): new **v2** format uses PBKDF2 with a random salt stored in the file; password and iteration count are required at import (`-i`); legacy **v1** exports remain importable with password only
14
11
  - require Node.js 22.23.4 or later (`engines.node >=22.23.4`), matching the October 2026 Node.js security release
15
12
  - clear cryptographic secrets from memory on `signout`, `quit`, and double `^C` (best-effort buffer zeroing)
16
13
  - replace deprecated dependencies: `homedir` → `os.homedir`, `ethereumjs-util` → `ethers.getAddress`, `qrcode-reader` → `jsqr`, upgrade `jimp` to 1.x
17
- - harden `totp --from-clipboard` on Linux: run `xclip` with `spawn` and write PNG bytes to disk instead of shell redirection
18
14
  - companion workspace releases: `@secrez/core@1.1.0`, `@secrez/crypto@1.1.0`, `@secrez/fs@1.1.0`, `@secrez/utils@1.1.0`, `@secrez/eth@0.0.6`
19
15
  - warn at signup when PBKDF2 iterations are below 100,000 and require explicit confirmation to proceed (KDF-3)
20
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secrez",
3
- "version": "2.2.0-beta.4",
3
+ "version": "2.2.0-beta.7",
4
4
  "license": "MIT",
5
5
  "nyc": {
6
6
  "include": "src",
package/src/Command.js CHANGED
@@ -141,46 +141,67 @@ class Command extends PreCommand {
141
141
  }
142
142
 
143
143
  /**
144
- * Check for git conflicts before performing data-changing operations
145
- * Returns true if the operation should proceed, false if it should be cancelled
144
+ * Fetch git status without prompting. `checkFailed` means the caller may proceed.
146
145
  */
147
- async checkGitConflictsBeforeOperation() {
146
+ async readGitConflictStatus() {
148
147
  try {
149
- const conflictCheck = await this.internalFs.checkGitSyncStatus();
150
-
151
- if (conflictCheck.hasRisk) {
152
- // Show the warning message
153
- this.Logger.yellow(conflictCheck.message);
154
-
155
- // If bypass is not allowed (e.g., external changes detected), block the operation
156
- if (!conflictCheck.allowBypass) {
157
- this.Logger.grey(
158
- "Operation blocked for data integrity. Please quit and re-enter Secrez."
159
- );
160
- return false;
161
- }
148
+ return await this.internalFs.checkGitSyncStatus();
149
+ } catch (e) {
150
+ return { hasRisk: false, checkFailed: true };
151
+ }
152
+ }
162
153
 
163
- // Otherwise, ask user if they want to continue
164
- const shouldContinue = await this.useInput({
165
- type: "confirm",
166
- message: "Do you want to continue anyway?",
167
- default: false,
168
- });
154
+ logGitConflictBlocked(conflictCheck) {
155
+ const checker = this.internalFs && this.internalFs.gitConflictChecker;
156
+ if (!checker || !checker.sessionBlockAnnounced) {
157
+ this.Logger.yellow(conflictCheck.message);
158
+ if (checker) checker.sessionBlockAnnounced = true;
159
+ }
160
+ this.Logger.red(
161
+ "Operation blocked for data integrity. Quit Secrez, sync the repo by hand, then start Secrez again."
162
+ );
163
+ }
169
164
 
170
- if (!shouldContinue) {
171
- this.Logger.grey("Operation cancelled.");
172
- return false;
173
- }
165
+ async askToBypassGitConflict(conflictCheck, options = {}) {
166
+ this.Logger.yellow(conflictCheck.message);
167
+ const shouldContinue = await this.useInput({
168
+ type: "confirm",
169
+ message: "Do you want to continue anyway?",
170
+ default: false,
171
+ });
172
+ if (!shouldContinue) {
173
+ if (!options.reopenEditor) {
174
+ this.Logger.grey("Operation cancelled.");
174
175
  }
176
+ return false;
177
+ }
178
+ return true;
179
+ }
175
180
 
176
- return true;
177
- } catch (e) {
178
- // If git check fails, log a warning but continue
181
+ /**
182
+ * Check for git conflicts before performing data-changing operations
183
+ * Returns true if the operation should proceed, false if it should be cancelled
184
+ */
185
+ async checkGitConflictsBeforeOperation() {
186
+ const conflictCheck = await this.readGitConflictStatus();
187
+
188
+ if (conflictCheck.checkFailed) {
179
189
  this.Logger.yellow(
180
190
  "Warning: Could not check git status. Proceeding anyway."
181
191
  );
182
192
  return true;
183
193
  }
194
+
195
+ if (!conflictCheck.hasRisk) {
196
+ return true;
197
+ }
198
+
199
+ if (!conflictCheck.allowBypass) {
200
+ this.logGitConflictBlocked(conflictCheck);
201
+ return false;
202
+ }
203
+
204
+ return this.askToBypassGitConflict(conflictCheck);
184
205
  }
185
206
  }
186
207
 
package/src/PreCommand.js CHANGED
@@ -17,7 +17,9 @@ class PreCommand {
17
17
  const wasRaw = typeof stdin.isRaw === "boolean" ? stdin.isRaw : false;
18
18
 
19
19
  try {
20
- return await editInMemory(options.content || "");
20
+ return await editInMemory(options.content || "", {
21
+ onReady: options.onEditorReady,
22
+ });
21
23
  } finally {
22
24
  if (stdin.isTTY && typeof stdin.setRawMode === "function") {
23
25
  try {
@@ -61,57 +61,130 @@ class Edit extends require("../Command") {
61
61
  };
62
62
  }
63
63
 
64
- async edit(options) {
65
- let data = await this.internalFs.getTreeIndexAndPath(options.path);
66
- let file = data.path;
67
- let tree = data.tree;
68
-
69
- let sanitizedPath = Entry.sanitizePath(file);
70
- if (sanitizedPath !== file) {
71
- throw new Error("A filename cannot contain \\/><|:&?*^$ chars.");
64
+ async edit(options, checkPromise) {
65
+ let editorAbort = null;
66
+ let hardBlocked = false;
67
+ let userLeftEditor = false;
68
+
69
+ const reportHardBlock = (result) => {
70
+ if (hardBlocked) return;
71
+ hardBlocked = true;
72
+ if (editorAbort) editorAbort();
73
+ this.logGitConflictBlocked(result);
74
+ };
75
+
76
+ if (checkPromise) {
77
+ checkPromise
78
+ .then((result) => {
79
+ if (userLeftEditor) return;
80
+ if (result && result.hasRisk && result.allowBypass === false) {
81
+ reportHardBlock(result);
82
+ }
83
+ })
84
+ .catch(() => {});
72
85
  }
73
86
 
74
- let exists = false;
75
- let fileData;
76
87
  try {
77
- fileData = await this.prompt.commands.cat.cat(
78
- { path: options.path },
79
- true
80
- );
81
- exists = true;
82
- } catch (e) {
83
- if (options.field) {
84
- throw new Error("Field can be specified only for existent files");
88
+ let data = await this.internalFs.getTreeIndexAndPath(options.path);
89
+ let file = data.path;
90
+ let tree = data.tree;
91
+
92
+ let sanitizedPath = Entry.sanitizePath(file);
93
+ if (sanitizedPath !== file) {
94
+ throw new Error("A filename cannot contain \\/><|:&?*^$ chars.");
85
95
  }
86
- fileData = [{ content: "" }];
87
- }
88
96
 
89
- let p = tree.getNormalizedPath(file);
90
- let fields = {};
91
- if (exists && !options.unformatted && isYaml(p)) {
92
- fields = fileData[0].content ? yamlParse(fileData[0].content) : {};
93
- if (typeof fields === "object") {
94
- options.choices = Object.keys(fields);
95
- if (options.choices.length && !options.field) {
96
- options.message = "Select the field to edit";
97
- options.field = await this.useSelect(options);
98
- if (!options.field) {
99
- this.Logger.reset("Changes aborted or file not changed");
100
- return;
97
+ let exists = false;
98
+ let fileData;
99
+ try {
100
+ fileData = await this.prompt.commands.cat.cat(
101
+ { path: options.path },
102
+ true
103
+ );
104
+ exists = true;
105
+ } catch (e) {
106
+ if (options.field) {
107
+ throw new Error("Field can be specified only for existent files");
108
+ }
109
+ fileData = [{ content: "" }];
110
+ }
111
+
112
+ let p = tree.getNormalizedPath(file);
113
+ let fields = {};
114
+ if (exists && !options.unformatted && isYaml(p)) {
115
+ fields = fileData[0].content ? yamlParse(fileData[0].content) : {};
116
+ if (typeof fields === "object") {
117
+ options.choices = Object.keys(fields);
118
+ if (options.choices.length && !options.field) {
119
+ options.message = "Select the field to edit";
120
+ options.field = await this.useSelect(options);
121
+ if (!options.field) {
122
+ if (!hardBlocked) {
123
+ this.Logger.reset("Changes aborted or file not changed");
124
+ }
125
+ return;
126
+ }
101
127
  }
128
+ } else {
129
+ delete options.field;
102
130
  }
103
- } else {
131
+ } else if (!isYaml(p)) {
104
132
  delete options.field;
105
133
  }
106
- } else if (!isYaml(p)) {
107
- delete options.field;
108
- }
109
- let content = options.field
110
- ? fields[options.field] || ""
111
- : fileData[0].content;
112
- let newContent = await this.useEditor(Object.assign(options, { content }));
134
+ if (hardBlocked) return;
135
+
136
+ const originalContent = options.field
137
+ ? fields[options.field] || ""
138
+ : fileData[0].content;
139
+ let draft = originalContent;
140
+ let newContent;
141
+
142
+ while (true) {
143
+ if (hardBlocked) return;
144
+
145
+ newContent = await this.useEditor(
146
+ Object.assign(options, {
147
+ content: draft,
148
+ onEditorReady: checkPromise
149
+ ? (handle) => {
150
+ editorAbort = handle.abort;
151
+ if (hardBlocked) handle.abort();
152
+ }
153
+ : undefined,
154
+ })
155
+ );
156
+
157
+ if (hardBlocked) return;
158
+
159
+ if (!(newContent && newContent !== originalContent)) {
160
+ userLeftEditor = true;
161
+ this.Logger.reset("Changes aborted or file not changed");
162
+ return;
163
+ }
164
+
165
+ draft = newContent;
166
+
167
+ if (checkPromise) {
168
+ const result = await checkPromise;
169
+ if (hardBlocked) return;
170
+ if (result.checkFailed) {
171
+ this.Logger.yellow(
172
+ "Warning: Could not check git status. Proceeding anyway."
173
+ );
174
+ } else if (result.hasRisk && result.allowBypass === false) {
175
+ reportHardBlock(result);
176
+ return;
177
+ } else if (result.hasRisk) {
178
+ const shouldContinue = await this.askToBypassGitConflict(result, {
179
+ reopenEditor: true,
180
+ });
181
+ if (!shouldContinue) continue;
182
+ }
183
+ }
184
+
185
+ break;
186
+ }
113
187
 
114
- if (newContent && newContent !== content) {
115
188
  if (exists) {
116
189
  let node = tree.root.getChildFromPath(p);
117
190
  let entry = node.getEntry();
@@ -129,8 +202,8 @@ class Edit extends require("../Command") {
129
202
  });
130
203
  }
131
204
  this.Logger.reset("File saved.");
132
- } else {
133
- this.Logger.reset("Changes aborted or file not changed");
205
+ } finally {
206
+ userLeftEditor = true;
134
207
  }
135
208
  }
136
209
 
@@ -143,12 +216,8 @@ class Edit extends require("../Command") {
143
216
  path: true,
144
217
  });
145
218
 
146
- const shouldProceed = await this.checkGitConflictsBeforeOperation();
147
- if (!shouldProceed) {
148
- return;
149
- }
150
-
151
- await this.edit(options);
219
+ const checkPromise = this.readGitConflictStatus();
220
+ await this.edit(options, checkPromise);
152
221
  } catch (e) {
153
222
  this.Logger.red(e.message);
154
223
  }
@@ -294,6 +294,10 @@ function createEditor(text) {
294
294
  p.update();
295
295
  p.render();
296
296
 
297
+ emitter.abort = () => {
298
+ if (isClosed) return;
299
+ p.abort({});
300
+ };
297
301
  emitter.pause = pause;
298
302
  emitter.resume = resume;
299
303
  emitter.setText = (nextText) => {
@@ -309,15 +313,25 @@ function createEditor(text) {
309
313
  return emitter;
310
314
  }
311
315
 
312
- function editInMemory(text) {
316
+ function editInMemory(text, hooks = {}) {
313
317
  return new Promise((resolve) => {
314
318
  const editor = createEditor(text);
319
+ let settled = false;
315
320
  const finish = (value) => {
321
+ if (settled) return;
322
+ settled = true;
316
323
  editor.pause();
317
324
  resolve(value);
318
325
  };
319
326
  editor.on("submit", finish);
320
327
  editor.on("abort", () => finish(undefined));
328
+ if (typeof hooks.onReady === "function") {
329
+ hooks.onReady({
330
+ abort() {
331
+ editor.abort();
332
+ },
333
+ });
334
+ }
321
335
  });
322
336
  }
323
337