@gadicc/loom 1.37.0 → 1.38.0
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 +10 -0
- package/esm/src/cli/localDb.js +2 -2
- package/esm/src/cli/migrationEnv.js +2 -2
- package/esm/src/cli/mod.d.ts +1 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +164 -4
- package/esm/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/esm/src/cli/vercelBuildEnv.js +23 -6
- package/esm/src/cli/vercelEnvMask.d.ts +38 -0
- package/esm/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/esm/src/cli/vercelEnvMask.js +136 -0
- package/esm/src/cli/vercelProjectRelease.js +2 -2
- package/esm/src/cli/vercelPulledEnv.d.ts +65 -0
- package/esm/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/esm/src/cli/vercelPulledEnv.js +132 -0
- package/package.json +2 -2
- package/script/src/cli/localDb.js +2 -2
- package/script/src/cli/migrationEnv.js +2 -2
- package/script/src/cli/mod.d.ts +1 -0
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +164 -4
- package/script/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/script/src/cli/vercelBuildEnv.js +23 -6
- package/script/src/cli/vercelEnvMask.d.ts +38 -0
- package/script/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/script/src/cli/vercelEnvMask.js +142 -0
- package/script/src/cli/vercelProjectRelease.js +2 -2
- package/script/src/cli/vercelPulledEnv.d.ts +65 -0
- package/script/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/script/src/cli/vercelPulledEnv.js +138 -0
- package/skills/loom/references/dependency-upgrades.md +4 -0
- package/skills/loom/references/release-safety.md +10 -3
- package/skills/loom-auth/references/secrets-and-rotation.md +2 -1
- package/skills/loom-scaffold/references/greenfield-workflow.md +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercelEnvMask.d.ts","sourceRoot":"","sources":["../../../src/src/cli/vercelEnvMask.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;AAE9B,KAAK,SAAS,GAAG;IACf,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAoCzC,mEAAmE;AACnE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,WAGjD;AAeD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,QAAQ,CACf,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,CAAC,CAC/D,YAwBF;AAQD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB,EACD,EAAE,EAAE,SAAS,SA2Cd"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIN_MASKED_VALUE_LENGTH = void 0;
|
|
4
|
+
exports.isPublicPulledEnvName = isPublicPulledEnvName;
|
|
5
|
+
exports.pulledEnvMaskCommands = pulledEnvMaskCommands;
|
|
6
|
+
exports.maskVercelPulledEnvironment = maskVercelPulledEnvironment;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const vercelPulledEnv_js_1 = require("./vercelPulledEnv.js");
|
|
9
|
+
/**
|
|
10
|
+
* Values shorter than this are not masked. A value this short is too small to
|
|
11
|
+
* be a meaningful secret, and GitHub masks every occurrence of a registered
|
|
12
|
+
* value in later log lines, so masking `1`, `true` or `production` would turn
|
|
13
|
+
* unrelated output into `***`.
|
|
14
|
+
*/
|
|
15
|
+
exports.MIN_MASKED_VALUE_LENGTH = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Pulled variables whose values are public by construction. Vercel documents
|
|
18
|
+
* these system variables as deployment metadata (URLs, IDs, flags, Git
|
|
19
|
+
* details), and the TURBO_/NX_ names are the fixed build settings `vercel pull`
|
|
20
|
+
* writes. Everything else, including VERCEL_AUTOMATION_BYPASS_SECRET,
|
|
21
|
+
* VERCEL_OIDC_TOKEN, VERCEL_HASH_SALT, TURBO_TOKEN and TURBO_TEAM, is masked:
|
|
22
|
+
* masking a public value is cosmetic, leaving a secret unmasked is a leak.
|
|
23
|
+
*/
|
|
24
|
+
const PUBLIC_PULLED_ENV_NAMES = new Set([
|
|
25
|
+
"CI",
|
|
26
|
+
"NX_DAEMON",
|
|
27
|
+
"TURBO_CACHE",
|
|
28
|
+
"TURBO_DOWNLOAD_LOCAL_ENABLED",
|
|
29
|
+
"TURBO_REMOTE_ONLY",
|
|
30
|
+
"TURBO_RUN_SUMMARY",
|
|
31
|
+
"VERCEL",
|
|
32
|
+
"VERCEL_BRANCH_URL",
|
|
33
|
+
"VERCEL_DEPLOYMENT_ID",
|
|
34
|
+
"VERCEL_ENV",
|
|
35
|
+
"VERCEL_PROJECT_ID",
|
|
36
|
+
"VERCEL_PROJECT_PRODUCTION_URL",
|
|
37
|
+
"VERCEL_REGION",
|
|
38
|
+
"VERCEL_SKEW_PROTECTION_ENABLED",
|
|
39
|
+
"VERCEL_TARGET_ENV",
|
|
40
|
+
"VERCEL_URL",
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Name prefixes that are public by construction: `NEXT_PUBLIC_` values are
|
|
44
|
+
* inlined into browser bundles, and every documented `VERCEL_GIT_` variable is
|
|
45
|
+
* repository or commit metadata.
|
|
46
|
+
*/
|
|
47
|
+
const PUBLIC_PULLED_ENV_PREFIXES = ["NEXT_PUBLIC_", "VERCEL_GIT_"];
|
|
48
|
+
/** Whether a pulled variable's value is public by construction. */
|
|
49
|
+
function isPublicPulledEnvName(name) {
|
|
50
|
+
return PUBLIC_PULLED_ENV_NAMES.has(name) ||
|
|
51
|
+
PUBLIC_PULLED_ENV_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
52
|
+
}
|
|
53
|
+
function isMaskableValue(value) {
|
|
54
|
+
// Measured without surrounding whitespace so a run of spaces never qualifies.
|
|
55
|
+
return value.trim().length >= exports.MIN_MASKED_VALUE_LENGTH;
|
|
56
|
+
}
|
|
57
|
+
/** Escapes command data the way GitHub's workflow command parser expects. */
|
|
58
|
+
function escapeCommandData(value) {
|
|
59
|
+
return value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the de-duplicated `::add-mask::` workflow commands for the entries
|
|
63
|
+
* of a parsed env file. An entry is skipped when its name is public by
|
|
64
|
+
* construction; otherwise its on-disk text, decoded value and trimmed value
|
|
65
|
+
* are each registered unless shorter than {@link MIN_MASKED_VALUE_LENGTH}.
|
|
66
|
+
* Registering every form costs only readability and covers whichever one a
|
|
67
|
+
* tool prints. A multi-line value is also registered line by line, without
|
|
68
|
+
* line terminators, because GitHub matches masks against each log line.
|
|
69
|
+
*/
|
|
70
|
+
function pulledEnvMaskCommands(entries) {
|
|
71
|
+
const commands = new Set();
|
|
72
|
+
const add = (value) => {
|
|
73
|
+
if (isMaskableValue(value)) {
|
|
74
|
+
commands.add(`::add-mask::${escapeCommandData(value)}`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const addForms = (raw, value) => {
|
|
78
|
+
add(raw);
|
|
79
|
+
add(value);
|
|
80
|
+
add(value.trim());
|
|
81
|
+
if (/[\r\n]/.test(value)) {
|
|
82
|
+
for (const line of value.split(/\r\n|\r|\n/))
|
|
83
|
+
add(line);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
for (const { alternateRaw, key, raw, value } of entries) {
|
|
87
|
+
if (isPublicPulledEnvName(key))
|
|
88
|
+
continue;
|
|
89
|
+
addForms(raw, value);
|
|
90
|
+
if (alternateRaw !== undefined) {
|
|
91
|
+
addForms(alternateRaw, (0, vercelPulledEnv_js_1.decodePulledEnvEscapes)(alternateRaw));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return [...commands];
|
|
95
|
+
}
|
|
96
|
+
function fileErrorCode(error) {
|
|
97
|
+
return typeof error === "object" && error !== null && "code" in error
|
|
98
|
+
? error.code
|
|
99
|
+
: undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Implements `loom db release mask-env <env-file>`: reads a pulled Vercel env
|
|
103
|
+
* file directly (so a process variable of the same name cannot shadow the
|
|
104
|
+
* file's value) and writes one `::add-mask::` command per secret-capable value.
|
|
105
|
+
* Nothing else reaches stdout, and failures name neither variables nor values.
|
|
106
|
+
* Refuses outside GitHub Actions, where the commands would print the values
|
|
107
|
+
* instead of registering masks.
|
|
108
|
+
*/
|
|
109
|
+
function maskVercelPulledEnvironment({ env, envFile }, io) {
|
|
110
|
+
if (env.GITHUB_ACTIONS !== "true") {
|
|
111
|
+
io.err("loom db release mask-env only runs in GitHub Actions (GITHUB_ACTIONS=true); elsewhere its output would print the values it masks.");
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
let bytes;
|
|
115
|
+
try {
|
|
116
|
+
bytes = (0, node_fs_1.readFileSync)(envFile);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
io.err(fileErrorCode(error) === "ENOENT"
|
|
120
|
+
? `Pulled Vercel env file not found: ${envFile}`
|
|
121
|
+
: `Pulled Vercel env file could not be read: ${envFile}`);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
let parsed;
|
|
125
|
+
try {
|
|
126
|
+
parsed = (0, vercelPulledEnv_js_1.parsePulledEnv)((0, vercelPulledEnv_js_1.decodePulledEnvBytes)(bytes));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
io.err(`Pulled Vercel env file is not valid UTF-8: ${envFile}`);
|
|
130
|
+
return 1;
|
|
131
|
+
}
|
|
132
|
+
// Mask whatever could be read before refusing the rest, so a file with an
|
|
133
|
+
// unexpected line still hides the values it does contain.
|
|
134
|
+
for (const command of pulledEnvMaskCommands(parsed.entries)) {
|
|
135
|
+
io.out(command);
|
|
136
|
+
}
|
|
137
|
+
if (parsed.unrecognizedLines.length) {
|
|
138
|
+
io.err(`Pulled Vercel env file could not be parsed: lines ${parsed.unrecognizedLines.join(", ")} are not dotenv assignments in ${envFile}`);
|
|
139
|
+
return 1;
|
|
140
|
+
}
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
@@ -7,7 +7,7 @@ exports.promoteVercelProjectRelease = promoteVercelProjectRelease;
|
|
|
7
7
|
const node_crypto_1 = require("node:crypto");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
|
-
const
|
|
10
|
+
const vercelPulledEnv_js_1 = require("./vercelPulledEnv.js");
|
|
11
11
|
const API_ORIGIN = "https://api.vercel.com";
|
|
12
12
|
const FETCH_TIMEOUT_MS = 30_000;
|
|
13
13
|
const MAX_PROJECT_BYTES = 2 * 1024 * 1024;
|
|
@@ -185,7 +185,7 @@ function serializeVercelPulledEnvironment(records) {
|
|
|
185
185
|
included.map((key) => `${key}="${escapeLikeVercelCli(records[key])}"`).join("\n") + "\n";
|
|
186
186
|
let roundTrip;
|
|
187
187
|
try {
|
|
188
|
-
roundTrip = (0,
|
|
188
|
+
roundTrip = (0, vercelPulledEnv_js_1.parsePulledEnv)(source).values;
|
|
189
189
|
}
|
|
190
190
|
catch {
|
|
191
191
|
throw new Error("Vercel environment could not be represented safely.");
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** One assignment read from a dotenv file, in file order. */
|
|
2
|
+
export type PulledEnvEntry = {
|
|
3
|
+
/**
|
|
4
|
+
* The on-disk text up to the last `"` on the line, when a dotenv-style early
|
|
5
|
+
* close (see {@link parsePulledEnv}) ended {@link raw} sooner. A Vercel value
|
|
6
|
+
* can itself contain `" #`, so masking registers this form too.
|
|
7
|
+
*/
|
|
8
|
+
alternateRaw?: string;
|
|
9
|
+
/** 1-based line on which the assignment ends (later for multi-line). */
|
|
10
|
+
endLine: number;
|
|
11
|
+
key: string;
|
|
12
|
+
/** 1-based line on which the assignment starts. */
|
|
13
|
+
line: number;
|
|
14
|
+
/**
|
|
15
|
+
* The value as written on disk between its quotes (or the trimmed unquoted
|
|
16
|
+
* text), before `\n`/`\r` escapes are decoded.
|
|
17
|
+
*/
|
|
18
|
+
raw: string;
|
|
19
|
+
/** The decoded value (see {@link parsePulledEnv} for how it is chosen). */
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
/** A parsed dotenv file. */
|
|
23
|
+
export type PulledEnvFile = {
|
|
24
|
+
entries: PulledEnvEntry[];
|
|
25
|
+
/** 1-based lines that are neither blank, a comment, nor an assignment. */
|
|
26
|
+
unrecognizedLines: number[];
|
|
27
|
+
/** Final value per key; a later assignment wins, as in dotenv. */
|
|
28
|
+
values: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
/** Decodes the `\n` and `\r` escapes `vercel pull` writes in quoted values. */
|
|
31
|
+
export declare function decodePulledEnvEscapes(raw: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Parses dotenv text so that masking and placeholder checks see the value
|
|
34
|
+
* Vercel stored.
|
|
35
|
+
*
|
|
36
|
+
* `vercel pull` writes every variable as `KEY="<value>"`, escaping only newline
|
|
37
|
+
* and carriage return (as `\n` and `\r`) and writing `"`, `\`, `#`, `$`, U+2028
|
|
38
|
+
* and U+2029 as they are. No consumer reads that format back exactly:
|
|
39
|
+
*
|
|
40
|
+
* - Node's `util.parseEnv` ends the value at its first embedded `"`, so
|
|
41
|
+
* `KEY="{"a":1}"` reads as `{`.
|
|
42
|
+
* - `vercel build` loads the file with its bundled dotenv 4.0.0, which trims
|
|
43
|
+
* inside the quotes, decodes `\n` but not `\r`, does not treat `#` specially,
|
|
44
|
+
* and drops any line containing U+2028 or U+2029.
|
|
45
|
+
* - Next.js (`@next/env`) uses dotenv 16, which cuts a value containing both
|
|
46
|
+
* `"` and `#` (`KEY="a"b#c"` reads as `"a"b`), and then expands `$VAR`.
|
|
47
|
+
*
|
|
48
|
+
* This reader is deliberately closer to the stored value than any of them,
|
|
49
|
+
* because masking has to cover the secret itself: a double-quoted value that
|
|
50
|
+
* closes on its line runs to the last `"` (or an earlier `"` followed only by a
|
|
51
|
+
* comment, see {@link PulledEnvEntry.alternateRaw}), nothing is trimmed inside
|
|
52
|
+
* the quotes, `#` and `$` are literal, and only `\n` and `\r` are decoded.
|
|
53
|
+
* Everything else follows dotenv 16: unquoted values end at `#` and are
|
|
54
|
+
* trimmed, single- and backtick-quoted values are literal, and quoted values
|
|
55
|
+
* may span lines.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parsePulledEnv(source: string): PulledEnvFile;
|
|
58
|
+
/** Decodes UTF-8, throwing on invalid bytes instead of replacing them. */
|
|
59
|
+
export declare function decodePulledEnvBytes(bytes: Uint8Array): any;
|
|
60
|
+
/**
|
|
61
|
+
* Reads and parses a dotenv file with {@link parsePulledEnv}. Throws on bytes
|
|
62
|
+
* that are not UTF-8 rather than silently replacing them.
|
|
63
|
+
*/
|
|
64
|
+
export declare function readPulledEnvFile(path: string): PulledEnvFile;
|
|
65
|
+
//# sourceMappingURL=vercelPulledEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercelPulledEnv.d.ts","sourceRoot":"","sources":["../../../src/src/cli/vercelPulledEnv.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,0EAA0E;IAC1E,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAAC;AAMF,+EAA+E;AAC/E,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,UAEjD;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CA0E5D;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,OAErD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAE7D"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodePulledEnvEscapes = decodePulledEnvEscapes;
|
|
4
|
+
exports.parsePulledEnv = parsePulledEnv;
|
|
5
|
+
exports.decodePulledEnvBytes = decodePulledEnvBytes;
|
|
6
|
+
exports.readPulledEnvFile = readPulledEnvFile;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
// `[\s\S]` rather than `.`: Vercel writes U+2028 and U+2029 unescaped, and `.`
|
|
9
|
+
// would stop at them and reject the whole line.
|
|
10
|
+
const ASSIGNMENT = /^\s*(?:export\s+)?([\w.-]+)(?:\s*=|:\s)\s*([\s\S]*)$/;
|
|
11
|
+
/** Decodes the `\n` and `\r` escapes `vercel pull` writes in quoted values. */
|
|
12
|
+
function decodePulledEnvEscapes(raw) {
|
|
13
|
+
return raw.replaceAll("\\n", "\n").replaceAll("\\r", "\r");
|
|
14
|
+
}
|
|
15
|
+
function escapeRegExp(text) {
|
|
16
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Where a double-quoted value that closes on its own line ends: at the first
|
|
20
|
+
* `"` followed only by whitespace and an optional `# comment` (dotenv's early
|
|
21
|
+
* close, which hand-written files rely on), and otherwise at the last `"`.
|
|
22
|
+
* Vercel never writes comments, so its lines end at the last `"` unless the
|
|
23
|
+
* value itself contains `"` followed by ` #`.
|
|
24
|
+
*/
|
|
25
|
+
function closingQuoteIndex(rest) {
|
|
26
|
+
for (let index = rest.indexOf('"', 1); index > 0;) {
|
|
27
|
+
if (/^\s*(?:#[\s\S]*)?$/.test(rest.slice(index + 1)))
|
|
28
|
+
return index;
|
|
29
|
+
index = rest.indexOf('"', index + 1);
|
|
30
|
+
}
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses dotenv text so that masking and placeholder checks see the value
|
|
35
|
+
* Vercel stored.
|
|
36
|
+
*
|
|
37
|
+
* `vercel pull` writes every variable as `KEY="<value>"`, escaping only newline
|
|
38
|
+
* and carriage return (as `\n` and `\r`) and writing `"`, `\`, `#`, `$`, U+2028
|
|
39
|
+
* and U+2029 as they are. No consumer reads that format back exactly:
|
|
40
|
+
*
|
|
41
|
+
* - Node's `util.parseEnv` ends the value at its first embedded `"`, so
|
|
42
|
+
* `KEY="{"a":1}"` reads as `{`.
|
|
43
|
+
* - `vercel build` loads the file with its bundled dotenv 4.0.0, which trims
|
|
44
|
+
* inside the quotes, decodes `\n` but not `\r`, does not treat `#` specially,
|
|
45
|
+
* and drops any line containing U+2028 or U+2029.
|
|
46
|
+
* - Next.js (`@next/env`) uses dotenv 16, which cuts a value containing both
|
|
47
|
+
* `"` and `#` (`KEY="a"b#c"` reads as `"a"b`), and then expands `$VAR`.
|
|
48
|
+
*
|
|
49
|
+
* This reader is deliberately closer to the stored value than any of them,
|
|
50
|
+
* because masking has to cover the secret itself: a double-quoted value that
|
|
51
|
+
* closes on its line runs to the last `"` (or an earlier `"` followed only by a
|
|
52
|
+
* comment, see {@link PulledEnvEntry.alternateRaw}), nothing is trimmed inside
|
|
53
|
+
* the quotes, `#` and `$` are literal, and only `\n` and `\r` are decoded.
|
|
54
|
+
* Everything else follows dotenv 16: unquoted values end at `#` and are
|
|
55
|
+
* trimmed, single- and backtick-quoted values are literal, and quoted values
|
|
56
|
+
* may span lines.
|
|
57
|
+
*/
|
|
58
|
+
function parsePulledEnv(source) {
|
|
59
|
+
// dotenv normalizes line endings before parsing; Vercel escapes CR and LF
|
|
60
|
+
// inside values, so a real CR here is always part of a line ending.
|
|
61
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
62
|
+
const entries = [];
|
|
63
|
+
const unrecognizedLines = [];
|
|
64
|
+
for (let index = 0; index < lines.length; index++) {
|
|
65
|
+
const lineText = lines[index];
|
|
66
|
+
const trimmed = lineText.trim();
|
|
67
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
68
|
+
continue;
|
|
69
|
+
const match = lineText.match(ASSIGNMENT);
|
|
70
|
+
if (!match) {
|
|
71
|
+
unrecognizedLines.push(index + 1);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const [, key, rest] = match;
|
|
75
|
+
const line = index + 1;
|
|
76
|
+
const quote = rest[0];
|
|
77
|
+
const closing = quote === '"' ? closingQuoteIndex(rest) : -1;
|
|
78
|
+
if (closing > 0) {
|
|
79
|
+
const raw = rest.slice(1, closing);
|
|
80
|
+
const last = rest.lastIndexOf('"');
|
|
81
|
+
entries.push({
|
|
82
|
+
...(last > closing ? { alternateRaw: rest.slice(1, last) } : {}),
|
|
83
|
+
endLine: line,
|
|
84
|
+
key,
|
|
85
|
+
line,
|
|
86
|
+
raw,
|
|
87
|
+
value: decodePulledEnvEscapes(raw),
|
|
88
|
+
});
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (quote === '"' || quote === "'" || quote === "`") {
|
|
92
|
+
// As in dotenv: the first unescaped closing quote, possibly on a later
|
|
93
|
+
// line, followed only by whitespace or a comment.
|
|
94
|
+
const q = escapeRegExp(quote);
|
|
95
|
+
const remaining = [rest.slice(1), ...lines.slice(index + 1)].join("\n");
|
|
96
|
+
const closed = remaining.match(new RegExp(`^((?:\\\\${q}|[^${q}])*)${q}[ \\t]*(?:#[^\\n]*)?(?:\\n|$)`));
|
|
97
|
+
if (closed) {
|
|
98
|
+
const raw = closed[1];
|
|
99
|
+
index += (closed[0].replace(/\n$/, "").match(/\n/g) ?? []).length;
|
|
100
|
+
entries.push({
|
|
101
|
+
endLine: index + 1,
|
|
102
|
+
key,
|
|
103
|
+
line,
|
|
104
|
+
raw,
|
|
105
|
+
value: quote === '"' ? decodePulledEnvEscapes(raw) : raw,
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// dotenv's unquoted form: up to the first `#`, trimmed, with one pair of
|
|
111
|
+
// matching surrounding quotes removed.
|
|
112
|
+
const text = rest.split("#", 1)[0].trim();
|
|
113
|
+
const surrounding = text.match(/^(['"`])([\s\S]*)\1$/);
|
|
114
|
+
const raw = surrounding ? surrounding[2] : text;
|
|
115
|
+
entries.push({
|
|
116
|
+
endLine: line,
|
|
117
|
+
key,
|
|
118
|
+
line,
|
|
119
|
+
raw,
|
|
120
|
+
value: text.startsWith('"') ? decodePulledEnvEscapes(raw) : raw,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const values = {};
|
|
124
|
+
for (const entry of entries)
|
|
125
|
+
values[entry.key] = entry.value;
|
|
126
|
+
return { entries, unrecognizedLines, values };
|
|
127
|
+
}
|
|
128
|
+
/** Decodes UTF-8, throwing on invalid bytes instead of replacing them. */
|
|
129
|
+
function decodePulledEnvBytes(bytes) {
|
|
130
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reads and parses a dotenv file with {@link parsePulledEnv}. Throws on bytes
|
|
134
|
+
* that are not UTF-8 rather than silently replacing them.
|
|
135
|
+
*/
|
|
136
|
+
function readPulledEnvFile(path) {
|
|
137
|
+
return parsePulledEnv(decodePulledEnvBytes((0, node_fs_1.readFileSync)(path)));
|
|
138
|
+
}
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
dependency-build settings with an explicit `allowBuilds` map before pnpm 11.
|
|
13
13
|
- For GitHub Actions on pnpm 11+, use the maintained `pnpm/setup` action rather
|
|
14
14
|
than `pnpm/action-setup`.
|
|
15
|
+
- Do not add `engines.pnpm` next to a pnpm `packageManager` pin. Without
|
|
16
|
+
Corepack, Vercel chooses pnpm from the lockfile version rather than from
|
|
17
|
+
`packageManager`, and `engines.pnpm` can reject that choice with
|
|
18
|
+
`ERR_PNPM_UNSUPPORTED_ENGINE`. `loom check` warns when both are present.
|
|
15
19
|
- Run `loom check` before changing the pin. Compatibility findings are warnings
|
|
16
20
|
while the app remains on pnpm 10 and issues once it declares pnpm 11 or newer.
|
|
17
21
|
- Keep `@gadicc/loom` in `minimumReleaseAgeExclude`. It is a first-party package
|
|
@@ -14,9 +14,16 @@ required smoke check. Preserve the configured project-token or team-token mode.
|
|
|
14
14
|
- After `vercel pull`, or after project-scoped preparation with
|
|
15
15
|
`loom db release prepare-vercel-project production`, treat
|
|
16
16
|
`.vercel/.env.<target>.local` as a plaintext secret file. Mask usable pulled
|
|
17
|
-
values before build output
|
|
18
|
-
`
|
|
19
|
-
|
|
17
|
+
values before build output with a step running
|
|
18
|
+
`loom db release mask-env .vercel/.env.<target>.local` (through the app's
|
|
19
|
+
package runner, for example `pnpm exec`) instead of an inline `::add-mask::`
|
|
20
|
+
script. It reads the file directly, skips only values shorter than 8
|
|
21
|
+
characters and names public by construction (`NEXT_PUBLIC_*`, `VERCEL_GIT_*`,
|
|
22
|
+
and listed non-secret Vercel system variables), masks every other name
|
|
23
|
+
including `VERCEL_AUTOMATION_BYPASS_SECRET` and `TURBO_TOKEN`, and masks
|
|
24
|
+
multi-line values line by line. Sensitive values are not readable there or
|
|
25
|
+
through `vercel env run`; CLI versions may write either an empty value or a
|
|
26
|
+
redaction sentinel.
|
|
20
27
|
- For external prebuilds, query Vercel env metadata, preserve usable pulled
|
|
21
28
|
values, add unique build-only placeholders only for confirmed Sensitive
|
|
22
29
|
entries, and reject any marker across the complete deployable artifact graph,
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
the deployable artifact.
|
|
28
28
|
- Treat `.vercel/.env.<target>.local` as a plaintext secret file even though
|
|
29
29
|
Sensitive entries are redacted. Keep it ignored, mask usable pulled values in
|
|
30
|
-
GitHub Actions
|
|
30
|
+
GitHub Actions with `loom db release mask-env <env-file>`, and never cache or
|
|
31
|
+
upload it as an artifact.
|
|
31
32
|
- `vercel env run` does not provide Sensitive values either. A command that
|
|
32
33
|
genuinely needs a secret outside Vercel runtime needs a separately governed
|
|
33
34
|
secret source; do not reuse a build placeholder.
|
|
@@ -199,7 +199,8 @@ The app-local workflow must:
|
|
|
199
199
|
|
|
200
200
|
1. install frozen dependencies and hydrate Loom's ignored skill links;
|
|
201
201
|
2. run typecheck, Biome, tests, and `loom check --production`;
|
|
202
|
-
3. pull Vercel Production settings and mask readable secrets
|
|
202
|
+
3. pull Vercel Production settings and mask readable secrets with
|
|
203
|
+
`loom db release mask-env .vercel/.env.production.local`;
|
|
203
204
|
4. prepare metadata-backed placeholders only for unreadable Sensitive values;
|
|
204
205
|
5. validate the preserved migration environment with `--connect`;
|
|
205
206
|
6. build and scan the exact prebuilt artifact;
|