@jondotsoy/envs 0.1.9-alpha.1 → 0.1.9-alpha.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.
Files changed (3) hide show
  1. package/SECURITY.md +2 -2
  2. package/envs.js +8 -7
  3. package/package.json +1 -1
package/SECURITY.md CHANGED
@@ -27,7 +27,7 @@ I will reply as soon as possible and we will coordinate the fix and the disclosu
27
27
  | --- | --- | --- |
28
28
  | `envs init` | — | Creates `<root>/.envs/`, `<root>/.envs/.gitignore` and `<root>/.envs/values.yml`, only if they do not exist. Never overwrites. |
29
29
  | `envs pull` | `<worktree>/.env` of each worktree | Rewrites `<root>/.envs/values.yml`. The file is serialized again, so YAML comments are lost. |
30
- | `envs push` | `<root>/.envs/values.yml` | Creates or updates `<worktree>/.env` of each worktree that has values. Updates existing variables in place, appends new ones at the end and keeps the rest of the file, except the orphan variables: those `envs` manages (they are or were in `values.yml` or its history) that the worktree no longer resolves are removed. If there are `defaults`, this includes all worktrees. |
30
+ | `envs push` | `<root>/.envs/values.yml` | Creates or updates `<worktree>/.env` of each worktree that has values. Updates existing variables in place, appends new ones at the end and keeps the rest of the file (it sets the mode of every `.env` it writes to `600`, so another user, such as a container mounting it, can no longer read it), except the orphan variables: those `envs` manages (they are or were in `values.yml` or its history) that the worktree no longer resolves are removed. If there are `defaults`, this includes all worktrees. |
31
31
  | `envs edit` | Same as `pull` and `push` | Same as `pull` and `push`. It also runs `code -w <root>/.envs/values.yml`. With `--ui` it serves the web editor instead (see below). |
32
32
  | `envs use`, `envs restore` | `<root>/.envs/values.yml`, `<root>/.envs/history.ndjson` | Rewrite `values.yml` and then act as `push`. |
33
33
  | `envs config` | `<root>/.envs/config.yml` | Creates or updates `<root>/.envs/config.yml` (mode `600`). |
@@ -62,7 +62,7 @@ The server listens on `127.0.0.1` only and exposes the values of every `.env`, s
62
62
  `envs push` prints one line for each variable whose value changes, in the form `↻ NAME=VALUE → branch, ...`, and `envs pull` prints `↓ pulling branch, ... - N variables`. To keep secrets out of the terminal and CI logs:
63
63
 
64
64
  - The value is replaced by `********` when the variable name contains a sensitive word: `SECRET`, `PASSWORD`, `PASSWD`, `PWD`, `TOKEN`, `KEY` (including `API_KEY` and `PRIVATE_KEY`), `CREDENTIAL`, `AUTH`, `SALT` or `SIGNING`. The match is case-insensitive and applies to whole `_`-separated words, so `KEY_FOO` and `AWS_BUCKET_SECRET` are masked but `MONKEY` is not.
65
- - A URL keeps its host and loses its secrets: `postgres://user:********@host/db?token=********` (the password and the values of sensitive query parameters are masked). A secret stored in a variable with an innocuous name and no URL form is still printed as is.
65
+ - A URL keeps its host and loses its secrets: `postgres://user:********@host/db?token=********` (the password and the values of sensitive query parameters are masked). A value in a well-known secret format (AWS key, GitHub or Slack token, `sk-…` key, private key) is masked whatever the variable is called; any other secret stored in a variable with an innocuous name and no URL form is still printed as is.
66
66
  - `envs pull` never prints values, only branch names and the number of variables.
67
67
  - `envs lint` messages never include the matched value.
68
68
  - Set `NO_COLOR` to a non-empty value to print the output without colors.
package/envs.js CHANGED
@@ -17,8 +17,9 @@ function dotenvProblem(key, text) {
17
17
  if (!/^[\w.-]+$/.test(key)) {
18
18
  return "the name is not a valid variable name (only letters, digits, `_`, `.` and `-`)";
19
19
  }
20
- if (text.includes("'") && text.includes('"') && text.includes("`")) {
21
- return "the value has single, double and backtick quotes at once, so no .env quoting can hold it as is";
20
+ const needsBackticks = text.includes("'") && (text.includes('"') || /\\[nr]/.test(text));
21
+ if (needsBackticks && text.includes("`")) {
22
+ return "the value needs backtick quoting (it has a single quote and a double quote or a literal `\\n`) and also has a backtick, so no .env quoting can hold it as is";
22
23
  }
23
24
  if (/[\r\n]/.test(text)) {
24
25
  return "the value has a line break, which a .env file cannot hold safely (write it on one line, with `\\n` escapes if the application expects them)";
@@ -97,10 +98,10 @@ var init_lint_rules = __esm(() => {
97
98
  "xxx"
98
99
  ]);
99
100
  SECRET_PATTERNS = [
100
- [/AKIA[0-9A-Z]{16}/, "an AWS access key id"],
101
- [/gh[pousr]_[A-Za-z0-9]{36,}/, "a GitHub token"],
102
- [/sk-[A-Za-z0-9_-]{20,}/, "an API secret key"],
103
- [/xox[abprs]-[A-Za-z0-9-]{10,}/, "a Slack token"],
101
+ [/(?<![A-Za-z0-9])AKIA[0-9A-Z]{16}/, "an AWS access key id"],
102
+ [/(?<![A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{36,}/, "a GitHub token"],
103
+ [/(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}/, "an API secret key"],
104
+ [/(?<![A-Za-z0-9])xox[abprs]-[A-Za-z0-9-]{10,}/, "a Slack token"],
104
105
  [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, "a private key"]
105
106
  ];
106
107
  rules = [
@@ -871,7 +872,7 @@ function parseDotenv(text) {
871
872
  continue;
872
873
  let value = match[2].trim();
873
874
  const quote = value[0];
874
- if ((quote === '"' || quote === "'") && value.lastIndexOf(quote) > 0) {
875
+ if ((quote === '"' || quote === "'" || quote === "`") && value.lastIndexOf(quote) > 0) {
875
876
  value = value.slice(1, value.lastIndexOf(quote));
876
877
  } else {
877
878
  value = value.replace(/\s+#.*$/, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jondotsoy/envs",
3
- "version": "0.1.9-alpha.1",
3
+ "version": "0.1.9-alpha.2",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Jonathan Delgado",