@dotenvx/dotenvx 2.28.1 → 2.28.2

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
@@ -2,7 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.28.1...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.28.2...main)
6
+
7
+ ## [2.28.2](https://github.com/dotenvx/dotenvx/compare/v2.28.1...v2.28.2) (2026-09-19)
8
+
9
+ ### Changed
10
+
11
+ * Only owner can write to and read from .env.keys file ([#979](https://github.com/dotenvx/dotenvx/pull/979))
6
12
 
7
13
  ## [2.28.1](https://github.com/dotenvx/dotenvx/compare/v2.28.0...v2.28.1) (2026-09-19)
8
14
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.28.1",
2
+ "version": "2.28.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -54,7 +54,7 @@ async function encryptAction () {
54
54
  const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ envs, ik, ek, fk, noArmor, noCreate, noNative, no1Password, noBitwarden })
55
55
 
56
56
  if (keysSrc) {
57
- await fsx.writeFileX(fk, keysSrc)
57
+ await fsx.writeKeyFile(fk, keysSrc)
58
58
  }
59
59
 
60
60
  if (spinner) spinner.stop()
@@ -70,7 +70,7 @@ async function set (key, value) {
70
70
  const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ envs, key, value, fk, noArmor, noCreate, encrypt, noNative, no1Password, noBitwarden })
71
71
 
72
72
  if (keysSrc) {
73
- await fsx.writeFileX(fk, keysSrc)
73
+ await fsx.writeKeyFile(fk, keysSrc)
74
74
  }
75
75
 
76
76
  let withEncryption = ''
@@ -2,6 +2,7 @@ const fs = require('fs')
2
2
  const Errors = require('./errors')
3
3
 
4
4
  const ENCODING = 'utf8'
5
+ const KEY_FILE_OPTIONS = { encoding: ENCODING, mode: 0o600 }
5
6
 
6
7
  async function readFileX (filepath, encoding = null) {
7
8
  if (!encoding) {
@@ -19,9 +20,9 @@ function readFileXSync (filepath, encoding = null) {
19
20
  return fs.readFileSync(filepath, encoding) // utf8 default so it returns a string
20
21
  }
21
22
 
22
- function writeFileXSync (filepath, str) {
23
+ function writeFileXSync (filepath, str, options = ENCODING) {
23
24
  try {
24
- return fs.writeFileSync(filepath, str, ENCODING) // utf8 always
25
+ return fs.writeFileSync(filepath, str, options)
25
26
  } catch (error) {
26
27
  if (error.code === 'EACCES' || error.code === 'EPERM') {
27
28
  throw new Errors({ filepath }).fileNotWritable()
@@ -31,9 +32,9 @@ function writeFileXSync (filepath, str) {
31
32
  }
32
33
  }
33
34
 
34
- async function writeFileX (filepath, str) {
35
+ async function writeFileX (filepath, str, options = ENCODING) {
35
36
  try {
36
- return await fs.promises.writeFile(filepath, str, ENCODING)
37
+ return await fs.promises.writeFile(filepath, str, options)
37
38
  } catch (error) {
38
39
  if (error.code === 'EACCES' || error.code === 'EPERM') {
39
40
  throw new Errors({ filepath }).fileNotWritable()
@@ -43,6 +44,14 @@ async function writeFileX (filepath, str) {
43
44
  }
44
45
  }
45
46
 
47
+ function writeKeyFile (filepath, str) {
48
+ return writeFileX(filepath, str, KEY_FILE_OPTIONS)
49
+ }
50
+
51
+ function writeKeyFileSync (filepath, str) {
52
+ return writeFileXSync(filepath, str, KEY_FILE_OPTIONS)
53
+ }
54
+
46
55
  async function exists (filepath) {
47
56
  try {
48
57
  await fs.promises.access(filepath)
@@ -65,7 +74,9 @@ const fsx = {
65
74
  readFileX,
66
75
  readFileXSync,
67
76
  writeFileX,
68
- writeFileXSync
77
+ writeFileXSync,
78
+ writeKeyFile,
79
+ writeKeyFileSync
69
80
  }
70
81
 
71
82
  module.exports = fsx
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const fsx = require('./fsx')
3
4
 
4
5
  function escapeForRegex (value) {
5
6
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
@@ -34,7 +35,7 @@ function removeEnvKey (key, keysFilepath = '.env.keys') {
34
35
 
35
36
  if (hasRemainingKeys) {
36
37
  const nextSrc = `${nextLines.join(eol)}${eol}`
37
- fs.writeFileSync(resolvedKeysFilepath, nextSrc, 'utf8')
38
+ fsx.writeKeyFileSync(resolvedKeysFilepath, nextSrc)
38
39
  } else {
39
40
  fs.rmSync(resolvedKeysFilepath, { force: true })
40
41
  }
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const fsx = require('./fsx')
3
4
 
4
5
  function escapeForRegex (value) {
5
6
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
@@ -46,7 +47,7 @@ function upsertEnvKey (key, value, keysFilepath = '.env.keys') {
46
47
  const changed = created || nextSrc !== src
47
48
 
48
49
  if (changed) {
49
- fs.writeFileSync(resolvedKeysFilepath, nextSrc, 'utf8')
50
+ fsx.writeKeyFileSync(resolvedKeysFilepath, nextSrc)
50
51
  }
51
52
 
52
53
  return {
package/src/lib/main.js CHANGED
@@ -266,7 +266,7 @@ const set = async function (key, value, options = {}) {
266
266
  })
267
267
 
268
268
  if (keysSrc) {
269
- fsx.writeFileXSync(envKeysFilepath || '.env.keys', keysSrc)
269
+ fsx.writeKeyFileSync(envKeysFilepath || '.env.keys', keysSrc)
270
270
  }
271
271
 
272
272
  let withEncryption = ''