varlock 0.4.2 → 0.6.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/dist/auto-load.js +6 -6
- package/dist/{chunk-PCRIVT4T.js → chunk-2AGKN64R.js} +663 -258
- package/dist/chunk-2AGKN64R.js.map +1 -0
- package/dist/{chunk-BGPQX6XO.js → chunk-3J7BFRB4.js} +372 -446
- package/dist/chunk-3J7BFRB4.js.map +1 -0
- package/dist/{chunk-3U2C5ACW.js → chunk-4JMFWK65.js} +5 -5
- package/dist/{chunk-3U2C5ACW.js.map → chunk-4JMFWK65.js.map} +1 -1
- package/dist/{chunk-TYIS6T2T.js → chunk-BC7LU4LG.js} +3 -3
- package/dist/{chunk-TYIS6T2T.js.map → chunk-BC7LU4LG.js.map} +1 -1
- package/dist/chunk-EXG5VPNZ.js +17 -0
- package/dist/chunk-EXG5VPNZ.js.map +1 -0
- package/dist/{chunk-P7WVEZYA.js → chunk-FYZ7LKLX.js} +27 -7
- package/dist/chunk-FYZ7LKLX.js.map +1 -0
- package/dist/{chunk-CBWJHW3M.js → chunk-G7FDCTNA.js} +8 -8
- package/dist/{chunk-CBWJHW3M.js.map → chunk-G7FDCTNA.js.map} +1 -1
- package/dist/{chunk-WAMBVZL2.js → chunk-IMB5QAZS.js} +38 -16
- package/dist/chunk-IMB5QAZS.js.map +1 -0
- package/dist/{chunk-NWY5IIPW.js → chunk-J7PA7B2U.js} +6 -81
- package/dist/chunk-J7PA7B2U.js.map +1 -0
- package/dist/{chunk-HS2NN4VF.js → chunk-JCJISIY6.js} +6 -6
- package/dist/{chunk-HS2NN4VF.js.map → chunk-JCJISIY6.js.map} +1 -1
- package/dist/{chunk-I4RYFNPM.js → chunk-KKNNZWYD.js} +3 -3
- package/dist/{chunk-I4RYFNPM.js.map → chunk-KKNNZWYD.js.map} +1 -1
- package/dist/{chunk-QQDWRXNU.js → chunk-LVZSZAKN.js} +3 -3
- package/dist/{chunk-QQDWRXNU.js.map → chunk-LVZSZAKN.js.map} +1 -1
- package/dist/{chunk-ZXJ4CEDK.js → chunk-MYHVSJ3X.js} +3 -3
- package/dist/{chunk-ZXJ4CEDK.js.map → chunk-MYHVSJ3X.js.map} +1 -1
- package/dist/{chunk-PIOJV2A7.js → chunk-NPPZVF24.js} +4 -4
- package/dist/{chunk-PIOJV2A7.js.map → chunk-NPPZVF24.js.map} +1 -1
- package/dist/{chunk-RQDMJMKL.js → chunk-PMBDCWD5.js} +6 -5
- package/dist/chunk-PMBDCWD5.js.map +1 -0
- package/dist/{chunk-YWFNGAPT.js → chunk-SHONHP24.js} +6 -6
- package/dist/{chunk-YWFNGAPT.js.map → chunk-SHONHP24.js.map} +1 -1
- package/dist/chunk-TLEEAUD7.js +68 -0
- package/dist/chunk-TLEEAUD7.js.map +1 -0
- package/dist/{chunk-LJTQEZE2.js → chunk-UVWLW5KD.js} +6 -6
- package/dist/{chunk-LJTQEZE2.js.map → chunk-UVWLW5KD.js.map} +1 -1
- package/dist/{chunk-MIBOBKI4.js → chunk-XLYSNOR3.js} +15 -3
- package/dist/chunk-XLYSNOR3.js.map +1 -0
- package/dist/{chunk-LFBK6MZU.js → chunk-ZLAUDWOL.js} +6 -6
- package/dist/{chunk-LFBK6MZU.js.map → chunk-ZLAUDWOL.js.map} +1 -1
- package/dist/cli/cli-executable.js +24 -24
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/config-item-NO5PKZRH.js +5 -0
- package/dist/{config-item-K7KWEJD2.js.map → config-item-NO5PKZRH.js.map} +1 -1
- package/dist/dotenv-compat.js +6 -6
- package/dist/{env-graph-COORmJlH.d.ts → env-graph-Cz_c5P6Y.d.ts} +24 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -11
- package/dist/init.command-AV4EWYIT.js +12 -0
- package/dist/{init.command-SZPMB525.js.map → init.command-AV4EWYIT.js.map} +1 -1
- package/dist/load.command-5JQUW3H7.js +11 -0
- package/dist/{load.command-XSOTCSGA.js.map → load.command-5JQUW3H7.js.map} +1 -1
- package/dist/plugin-lib.d.ts +2 -2
- package/dist/printenv.command-SBB6GVC2.js +12 -0
- package/dist/{printenv.command-4HWCHHCY.js.map → printenv.command-SBB6GVC2.js.map} +1 -1
- package/dist/run.command-HTGTG6ER.js +12 -0
- package/dist/{run.command-2HLQ2AYT.js.map → run.command-HTGTG6ER.js.map} +1 -1
- package/dist/runtime/env.d.ts +7 -2
- package/dist/runtime/env.js +2 -2
- package/dist/runtime/init-edge.cjs +297 -0
- package/dist/runtime/init-edge.d.cts +1 -0
- package/dist/runtime/init-server.cjs +370 -0
- package/dist/runtime/init-server.d.cts +20 -0
- package/dist/runtime/patch-console.js +3 -3
- package/dist/runtime/patch-response.js +3 -3
- package/dist/runtime/patch-server-response.js +3 -3
- package/dist/scan.command-ADKVWN5T.js +13 -0
- package/dist/{scan.command-4J64EB4Z.js.map → scan.command-ADKVWN5T.js.map} +1 -1
- package/dist/telemetry.command-CQFTGXPF.js +11 -0
- package/dist/{telemetry.command-NLJFD63U.js.map → telemetry.command-CQFTGXPF.js.map} +1 -1
- package/dist/typegen.command-A544SFYM.js +12 -0
- package/dist/{typegen.command-7BE3K6PU.js.map → typegen.command-A544SFYM.js.map} +1 -1
- package/package.json +12 -2
- package/dist/chunk-6SS4YD2I.js +0 -156
- package/dist/chunk-6SS4YD2I.js.map +0 -1
- package/dist/chunk-BGPQX6XO.js.map +0 -1
- package/dist/chunk-MBYYRBL6.js +0 -17
- package/dist/chunk-MBYYRBL6.js.map +0 -1
- package/dist/chunk-MIBOBKI4.js.map +0 -1
- package/dist/chunk-NWY5IIPW.js.map +0 -1
- package/dist/chunk-P7WVEZYA.js.map +0 -1
- package/dist/chunk-PCRIVT4T.js.map +0 -1
- package/dist/chunk-RQDMJMKL.js.map +0 -1
- package/dist/chunk-WAMBVZL2.js.map +0 -1
- package/dist/config-item-K7KWEJD2.js +0 -5
- package/dist/init.command-SZPMB525.js +0 -12
- package/dist/load.command-XSOTCSGA.js +0 -11
- package/dist/printenv.command-4HWCHHCY.js +0 -12
- package/dist/run.command-2HLQ2AYT.js +0 -12
- package/dist/scan.command-4J64EB4Z.js +0 -13
- package/dist/telemetry.command-NLJFD63U.js +0 -11
- package/dist/typegen.command-7BE3K6PU.js +0 -12
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zlib = require('zlib');
|
|
4
|
+
var http = require('http');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
9
|
+
|
|
10
|
+
// src/runtime/lib/redaction.ts
|
|
11
|
+
function redactString(valStr, modeOrOpts, hideLength = true) {
|
|
12
|
+
if (!valStr) return valStr;
|
|
13
|
+
let mode;
|
|
14
|
+
{
|
|
15
|
+
mode = modeOrOpts;
|
|
16
|
+
}
|
|
17
|
+
const hiddenLength = hideLength ? 5 : valStr.length - 2;
|
|
18
|
+
const hiddenStr = "\u2592".repeat(hiddenLength);
|
|
19
|
+
if (mode === "show_last_2") {
|
|
20
|
+
return `${hiddenStr}${valStr.substring(valStr.length - 2, valStr.length)}`;
|
|
21
|
+
} else if (mode === "show_first_last") {
|
|
22
|
+
return `${valStr.substring(0, 1)}${hiddenStr}${valStr.substring(valStr.length - 1, valStr.length)}`;
|
|
23
|
+
} else {
|
|
24
|
+
return `${valStr.substring(0, 2)}${hiddenStr}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/lib/detect-runtime.ts
|
|
29
|
+
var versionsStr = "versions";
|
|
30
|
+
var processVersions = typeof process !== "undefined" && process[versionsStr];
|
|
31
|
+
processVersions && processVersions.node != null;
|
|
32
|
+
typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && "userAgent" in navigator && typeof navigator.userAgent === "string" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
|
|
33
|
+
typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
|
|
34
|
+
processVersions && processVersions.bun != null;
|
|
35
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement === "function" && typeof navigator !== "undefined" && typeof navigator.userAgent === "string";
|
|
36
|
+
|
|
37
|
+
// src/runtime/lib/debug.ts
|
|
38
|
+
function debug(...args) {
|
|
39
|
+
if (!globalThis.process?.env.DEBUG_VARLOCK) return;
|
|
40
|
+
console.log(...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/runtime/env.ts
|
|
44
|
+
function isString(s) {
|
|
45
|
+
return Object.prototype.toString.call(s) === "[object String]";
|
|
46
|
+
}
|
|
47
|
+
var UNMASK_STR = "\u{1F441}";
|
|
48
|
+
var REDACTION_STATE_KEY = "__varlockRedactionState";
|
|
49
|
+
function getRedactionState() {
|
|
50
|
+
if (!globalThis[REDACTION_STATE_KEY]) {
|
|
51
|
+
globalThis[REDACTION_STATE_KEY] = {
|
|
52
|
+
sensitiveSecretsMap: {},
|
|
53
|
+
redactorFindReplace: void 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return globalThis[REDACTION_STATE_KEY];
|
|
57
|
+
}
|
|
58
|
+
function resetRedactionMap(graph) {
|
|
59
|
+
const state = getRedactionState();
|
|
60
|
+
state.sensitiveSecretsMap = {};
|
|
61
|
+
for (const itemKey in graph.config) {
|
|
62
|
+
const item = graph.config[itemKey];
|
|
63
|
+
if (item.isSensitive && item.value && isString(item.value)) {
|
|
64
|
+
const redacted = redactString(item.value);
|
|
65
|
+
if (redacted) state.sensitiveSecretsMap[item.value] = { key: itemKey, redacted };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!Object.keys(state.sensitiveSecretsMap).length) {
|
|
69
|
+
state.redactorFindReplace = void 0;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const findRegex = new RegExp(
|
|
73
|
+
[
|
|
74
|
+
`(${UNMASK_STR} )?`,
|
|
75
|
+
"(",
|
|
76
|
+
Object.keys(state.sensitiveSecretsMap).map((s) => s.replace(/[()[\]{}*+?^$|#.,/\\\s-]/g, "\\$&")).sort((a, b) => b.length - a.length).join("|"),
|
|
77
|
+
")",
|
|
78
|
+
`( ${UNMASK_STR})?`
|
|
79
|
+
].join(""),
|
|
80
|
+
"g"
|
|
81
|
+
);
|
|
82
|
+
const replaceFn = (match, pre, val, post) => {
|
|
83
|
+
if (pre && post) return match;
|
|
84
|
+
return state.sensitiveSecretsMap[val].redacted;
|
|
85
|
+
};
|
|
86
|
+
state.redactorFindReplace = { find: findRegex, replace: replaceFn };
|
|
87
|
+
}
|
|
88
|
+
function redactSensitiveConfig(o) {
|
|
89
|
+
const { redactorFindReplace } = getRedactionState();
|
|
90
|
+
if (!redactorFindReplace) return o;
|
|
91
|
+
if (!o) return o;
|
|
92
|
+
if (Array.isArray(o)) {
|
|
93
|
+
return o.map(redactSensitiveConfig);
|
|
94
|
+
}
|
|
95
|
+
if (o && typeof o === "object" && Object.getPrototypeOf(o) === Object.prototype) {
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(redactSensitiveConfig(JSON.stringify(o)));
|
|
98
|
+
} catch (err) {
|
|
99
|
+
return o;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const type = typeof o;
|
|
103
|
+
if (type === "string" || type === "object" && Object.prototype.toString.call(o) === "[object String]") {
|
|
104
|
+
return o.replaceAll(redactorFindReplace.find, redactorFindReplace.replace);
|
|
105
|
+
}
|
|
106
|
+
return o;
|
|
107
|
+
}
|
|
108
|
+
function revealSensitiveConfig(secretStr) {
|
|
109
|
+
if (!globalThis._varlockOrigWriteToConsoleFn) return secretStr;
|
|
110
|
+
return `${UNMASK_STR} ${secretStr} ${UNMASK_STR}`;
|
|
111
|
+
}
|
|
112
|
+
function scanForLeaks(toScan, meta) {
|
|
113
|
+
debug("\u26A1\uFE0F varlock scanning for leaks");
|
|
114
|
+
if (!toScan) return toScan;
|
|
115
|
+
function scanStrForLeaks(strToScan) {
|
|
116
|
+
const { sensitiveSecretsMap } = getRedactionState();
|
|
117
|
+
for (const sensitiveValue in sensitiveSecretsMap) {
|
|
118
|
+
if (strToScan.includes(sensitiveValue)) {
|
|
119
|
+
const itemKey = sensitiveSecretsMap[sensitiveValue].key;
|
|
120
|
+
console.error([
|
|
121
|
+
"",
|
|
122
|
+
`\u{1F6A8} ${"DETECTED LEAKED SENSITIVE CONFIG"} \u{1F6A8}`,
|
|
123
|
+
`> Config item key: ${itemKey}`,
|
|
124
|
+
...meta?.method ? [`> Scan method: ${meta.method}`] : [],
|
|
125
|
+
...meta?.file ? [`> File: ${meta.file}`] : [],
|
|
126
|
+
""
|
|
127
|
+
].join("\n"));
|
|
128
|
+
throw new Error(`\u{1F6A8} DETECTED LEAKED SENSITIVE CONFIG - ${itemKey}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (isString(toScan)) {
|
|
133
|
+
scanStrForLeaks(toScan);
|
|
134
|
+
return toScan;
|
|
135
|
+
} else if (typeof Buffer !== "undefined" && toScan instanceof Buffer) {
|
|
136
|
+
scanStrForLeaks(toScan.toString());
|
|
137
|
+
return toScan;
|
|
138
|
+
} else if (toScan instanceof ReadableStream) {
|
|
139
|
+
if (toScan.locked) {
|
|
140
|
+
return toScan;
|
|
141
|
+
}
|
|
142
|
+
const chunkDecoder = new TextDecoder();
|
|
143
|
+
return toScan.pipeThrough(
|
|
144
|
+
new TransformStream({
|
|
145
|
+
transform(chunk, controller) {
|
|
146
|
+
const chunkStr = chunkDecoder.decode(chunk);
|
|
147
|
+
scanStrForLeaks(chunkStr);
|
|
148
|
+
controller.enqueue(chunk);
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return toScan;
|
|
154
|
+
}
|
|
155
|
+
var initializedEnv = false;
|
|
156
|
+
var envValues = {};
|
|
157
|
+
var varlockSettings = {};
|
|
158
|
+
var processExists = !!globalThis.process;
|
|
159
|
+
var originalProcessEnv = { ...processExists && process.env };
|
|
160
|
+
var varlockInjectedProcessEnvKeys;
|
|
161
|
+
function initVarlockEnv(opts) {
|
|
162
|
+
debug("\u26A1\uFE0F INIT VARLOCK ENV!", initializedEnv, !!globalThis.__varlockLoadedEnv, !!globalThis.process?.env.__VARLOCK_ENV);
|
|
163
|
+
if (isBrowser && !globalThis.process?.env.__VARLOCK_ENV) {
|
|
164
|
+
initializedEnv = true;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
let serializedEnvData;
|
|
168
|
+
if (globalThis.__varlockLoadedEnv) {
|
|
169
|
+
serializedEnvData = globalThis.__varlockLoadedEnv;
|
|
170
|
+
} else if (processExists && process.env.__VARLOCK_ENV) {
|
|
171
|
+
serializedEnvData = JSON.parse(process.env.__VARLOCK_ENV);
|
|
172
|
+
} else {
|
|
173
|
+
if (opts?.allowFail) return;
|
|
174
|
+
console.error([
|
|
175
|
+
"",
|
|
176
|
+
"\u{1F6A8} initVarlockEnv failed \u{1F6A8}",
|
|
177
|
+
"try rerunning your command via `varlock run`",
|
|
178
|
+
""
|
|
179
|
+
].join("\n"));
|
|
180
|
+
throw new Error("initVarlockEnv failed");
|
|
181
|
+
}
|
|
182
|
+
Object.assign(varlockSettings, serializedEnvData.settings);
|
|
183
|
+
resetRedactionMap(serializedEnvData);
|
|
184
|
+
const setProcessEnv = processExists;
|
|
185
|
+
if (setProcessEnv) {
|
|
186
|
+
if (varlockInjectedProcessEnvKeys) {
|
|
187
|
+
for (const key of varlockInjectedProcessEnvKeys) delete process.env[key];
|
|
188
|
+
for (const key of Object.keys(originalProcessEnv)) process.env[key] = originalProcessEnv[key];
|
|
189
|
+
}
|
|
190
|
+
varlockInjectedProcessEnvKeys = [];
|
|
191
|
+
}
|
|
192
|
+
for (const itemKey in serializedEnvData.config) {
|
|
193
|
+
const itemValue = serializedEnvData.config[itemKey].value;
|
|
194
|
+
envValues[itemKey] = itemValue;
|
|
195
|
+
if (setProcessEnv) {
|
|
196
|
+
varlockInjectedProcessEnvKeys?.push(itemKey);
|
|
197
|
+
process.env[itemKey] = itemValue === void 0 ? "" : String(itemValue);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
initializedEnv = true;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
if (!initializedEnv) {
|
|
204
|
+
initVarlockEnv({ allowFail: true });
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
}
|
|
208
|
+
var IGNORED_PROXY_KEYS = [
|
|
209
|
+
// vue - see https://github.com/vuejs/core/blob/70773d00985135a50556c61fb9855ed6b930cb82/packages/reactivity/src/ref.ts#L101
|
|
210
|
+
"__v_isRef"
|
|
211
|
+
];
|
|
212
|
+
var EnvProxy = new Proxy({}, {
|
|
213
|
+
get(target, prop) {
|
|
214
|
+
if (typeof prop === "symbol") return;
|
|
215
|
+
if (IGNORED_PROXY_KEYS.includes(prop)) return;
|
|
216
|
+
if (!initializedEnv) {
|
|
217
|
+
throw new Error("varlock ENV not initialized");
|
|
218
|
+
}
|
|
219
|
+
if (prop in envValues) return envValues[prop];
|
|
220
|
+
if (globalThis.__varlockThrowOnMissingKeys) {
|
|
221
|
+
if (globalThis.__varlockValidKeys && globalThis.__varlockValidKeys.includes(prop)) {
|
|
222
|
+
throw new Error(`\`ENV.${prop}\` exists, but is not available in this environment`);
|
|
223
|
+
} else {
|
|
224
|
+
throw new Error(`\`ENV.${prop}\` does not exist`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
var ENV = EnvProxy;
|
|
231
|
+
|
|
232
|
+
// src/runtime/patch-console.ts
|
|
233
|
+
function patchGlobalConsole() {
|
|
234
|
+
debug("\u26A1\uFE0F PATCHING global console methods");
|
|
235
|
+
if (console.log._varlockPatchedFn) {
|
|
236
|
+
debug("> already patched");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (varlockSettings.redactLogs === false) {
|
|
240
|
+
debug("> disabled by settings");
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === "kWriteToConsole");
|
|
244
|
+
globalThis._varlockOrigWriteToConsoleFn ||= globalThis.console[kWriteToConsoleSymbol];
|
|
245
|
+
globalThis.console[kWriteToConsoleSymbol] = function() {
|
|
246
|
+
globalThis._varlockOrigWriteToConsoleFn.apply(this, [
|
|
247
|
+
arguments[0],
|
|
248
|
+
redactSensitiveConfig(arguments[1]),
|
|
249
|
+
arguments[2]
|
|
250
|
+
]);
|
|
251
|
+
};
|
|
252
|
+
for (const logMethodName of ["trace", "debug", "info", "log", "info", "warn", "error"]) {
|
|
253
|
+
const originalLogMethod = globalThis.console[logMethodName];
|
|
254
|
+
const patchedFn = function() {
|
|
255
|
+
originalLogMethod.apply(this, Array.from(arguments).map(redactSensitiveConfig));
|
|
256
|
+
};
|
|
257
|
+
patchedFn._varlockPatchedFn = true;
|
|
258
|
+
globalThis.console[logMethodName] = patchedFn;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
var patchedKey = "_patchedByVarlock";
|
|
262
|
+
function patchGlobalServerResponse(opts) {
|
|
263
|
+
debug("\u26A1\uFE0F PATCHING global ServerResponse");
|
|
264
|
+
if (Object.getOwnPropertyDescriptor(http.ServerResponse.prototype, patchedKey)) {
|
|
265
|
+
debug("> already patched");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (varlockSettings.preventLeaks === false) {
|
|
269
|
+
debug("> disabled by settings");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
Object.defineProperty(http.ServerResponse.prototype, patchedKey, { value: true });
|
|
273
|
+
const serverResponseWrite = http.ServerResponse.prototype.write;
|
|
274
|
+
http.ServerResponse.prototype.write = function varlockPatchedServerResponseWrite(...args) {
|
|
275
|
+
const rawChunk = args[0];
|
|
276
|
+
const contentType = this.getHeader("content-type")?.toString() || "";
|
|
277
|
+
let runScan = contentType.startsWith("text/") || contentType.startsWith("application/json") || !contentType && typeof rawChunk === "string";
|
|
278
|
+
this.req.url;
|
|
279
|
+
if (!runScan) {
|
|
280
|
+
return serverResponseWrite.apply(this, args);
|
|
281
|
+
}
|
|
282
|
+
const compressionType = this.getHeader("Content-Encoding");
|
|
283
|
+
let chunkStr;
|
|
284
|
+
if (typeof rawChunk === "string") {
|
|
285
|
+
chunkStr = rawChunk;
|
|
286
|
+
} else if (!compressionType) {
|
|
287
|
+
const decoder = new TextDecoder();
|
|
288
|
+
chunkStr = decoder.decode(rawChunk);
|
|
289
|
+
} else if (compressionType === "gzip") {
|
|
290
|
+
if (!this._zlibChunks) {
|
|
291
|
+
this._zlibChunks = [rawChunk];
|
|
292
|
+
} else {
|
|
293
|
+
this._zlibChunks?.push(rawChunk);
|
|
294
|
+
try {
|
|
295
|
+
const unzippedChunk = zlib__default.default.unzipSync(Buffer.concat(this._zlibChunks || []), {
|
|
296
|
+
flush: zlib__default.default.constants.Z_SYNC_FLUSH,
|
|
297
|
+
finishFlush: zlib__default.default.constants.Z_SYNC_FLUSH
|
|
298
|
+
});
|
|
299
|
+
const fullUnzippedData = unzippedChunk.toString("utf-8");
|
|
300
|
+
chunkStr = fullUnzippedData.substring(this._lastChunkEndIndex || 0);
|
|
301
|
+
this._lastChunkEndIndex = fullUnzippedData.length;
|
|
302
|
+
} catch (err) {
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (chunkStr) {
|
|
307
|
+
try {
|
|
308
|
+
scanForLeaks(chunkStr, { method: "patched ServerResponse.write", file: this.req.url });
|
|
309
|
+
} catch (err) {
|
|
310
|
+
{
|
|
311
|
+
throw err;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return serverResponseWrite.apply(this, args);
|
|
316
|
+
};
|
|
317
|
+
const serverResponseEnd = http.ServerResponse.prototype.end;
|
|
318
|
+
http.ServerResponse.prototype.end = function patchedServerResponseEnd(...args) {
|
|
319
|
+
const endChunk = args[0];
|
|
320
|
+
if (endChunk && typeof endChunk === "string") {
|
|
321
|
+
scanForLeaks(endChunk, { method: "patched ServerResponse.end" });
|
|
322
|
+
}
|
|
323
|
+
return serverResponseEnd.apply(this, args);
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/runtime/patch-response.ts
|
|
328
|
+
function patchGlobalResponse() {
|
|
329
|
+
debug("\u26A1\uFE0F PATCHING global Response");
|
|
330
|
+
if (globalThis.Response._patchedByVarlock) {
|
|
331
|
+
debug("> already patched");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (varlockSettings.preventLeaks === false) {
|
|
335
|
+
debug("> disabled by settings");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const _UnpatchedResponse = globalThis.Response;
|
|
339
|
+
globalThis.Response = class VarlockPatchedResponse extends _UnpatchedResponse {
|
|
340
|
+
static _patchedByVarlock = true;
|
|
341
|
+
// Make native fetch() responses (which are instances of the original Response)
|
|
342
|
+
// pass instanceof checks against the patched globalThis.Response.
|
|
343
|
+
static [Symbol.hasInstance](instance) {
|
|
344
|
+
return instance instanceof _UnpatchedResponse;
|
|
345
|
+
}
|
|
346
|
+
constructor(body, init) {
|
|
347
|
+
debug("\u26A1\uFE0F patched Response constructor");
|
|
348
|
+
super(scanForLeaks(body, { method: "patched Response constructor" }), init);
|
|
349
|
+
}
|
|
350
|
+
static json(data, init) {
|
|
351
|
+
debug("\u26A1\uFE0F patched Response.json");
|
|
352
|
+
scanForLeaks(JSON.stringify(data), { method: "patched Response.json" });
|
|
353
|
+
const r = _UnpatchedResponse.json(data, init);
|
|
354
|
+
Object.setPrototypeOf(r, Response.prototype);
|
|
355
|
+
return r;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/runtime/init-server.ts
|
|
361
|
+
initVarlockEnv();
|
|
362
|
+
patchGlobalConsole();
|
|
363
|
+
patchGlobalServerResponse();
|
|
364
|
+
patchGlobalResponse();
|
|
365
|
+
globalThis.__varlockPatchConsole = patchGlobalConsole;
|
|
366
|
+
|
|
367
|
+
exports.ENV = ENV;
|
|
368
|
+
exports.redactSensitiveConfig = redactSensitiveConfig;
|
|
369
|
+
exports.revealSensitiveConfig = revealSensitiveConfig;
|
|
370
|
+
exports.scanForLeaks = scanForLeaks;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redacts senstive config values from any string/array/object/etc
|
|
3
|
+
*
|
|
4
|
+
* NOTE - must be used only after varlock has loaded config
|
|
5
|
+
* */
|
|
6
|
+
declare function redactSensitiveConfig(o: any): any;
|
|
7
|
+
/**
|
|
8
|
+
* utility to unmask a secret/sensitive value when logging to the console
|
|
9
|
+
* currently this only works on a single secret, not objects or aggregated strings
|
|
10
|
+
* */
|
|
11
|
+
declare function revealSensitiveConfig(secretStr: string): string;
|
|
12
|
+
declare function scanForLeaks(toScan: string | ReadableStream | null, meta?: {
|
|
13
|
+
method?: string;
|
|
14
|
+
file?: string;
|
|
15
|
+
}): string | ReadableStream<any> | null;
|
|
16
|
+
interface TypedEnvSchema {
|
|
17
|
+
}
|
|
18
|
+
declare const ENV: TypedEnvSchema;
|
|
19
|
+
|
|
20
|
+
export { ENV, redactSensitiveConfig, revealSensitiveConfig, scanForLeaks };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { patchGlobalConsole, unpatchGlobalConsole } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { patchGlobalConsole, unpatchGlobalConsole } from '../chunk-BC7LU4LG.js';
|
|
2
|
+
import '../chunk-IMB5QAZS.js';
|
|
3
|
+
import '../chunk-XLYSNOR3.js';
|
|
4
4
|
import '../chunk-6PEHRAEP.js';
|
|
5
5
|
//# sourceMappingURL=patch-console.js.map
|
|
6
6
|
//# sourceMappingURL=patch-console.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { patchGlobalResponse } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { patchGlobalResponse } from '../chunk-LVZSZAKN.js';
|
|
2
|
+
import '../chunk-IMB5QAZS.js';
|
|
3
|
+
import '../chunk-XLYSNOR3.js';
|
|
4
4
|
import '../chunk-6PEHRAEP.js';
|
|
5
5
|
//# sourceMappingURL=patch-response.js.map
|
|
6
6
|
//# sourceMappingURL=patch-response.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { patchGlobalServerResponse } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { patchGlobalServerResponse } from '../chunk-MYHVSJ3X.js';
|
|
2
|
+
import '../chunk-IMB5QAZS.js';
|
|
3
|
+
import '../chunk-XLYSNOR3.js';
|
|
4
4
|
import '../chunk-6PEHRAEP.js';
|
|
5
5
|
//# sourceMappingURL=patch-server-response.js.map
|
|
6
6
|
//# sourceMappingURL=patch-server-response.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { commandFn, commandSpec, getGitFiles, scanFileForValues, walkDirectory } from './chunk-G7FDCTNA.js';
|
|
2
|
+
import './chunk-Y3ITSQA4.js';
|
|
3
|
+
import './chunk-TLEEAUD7.js';
|
|
4
|
+
import './chunk-NPPZVF24.js';
|
|
5
|
+
import './chunk-4A54P4EM.js';
|
|
6
|
+
import './chunk-EXG5VPNZ.js';
|
|
7
|
+
import './chunk-J7PA7B2U.js';
|
|
8
|
+
import './chunk-2AGKN64R.js';
|
|
9
|
+
import './chunk-QZ6HBRJC.js';
|
|
10
|
+
import './chunk-XLYSNOR3.js';
|
|
11
|
+
import './chunk-6PEHRAEP.js';
|
|
12
|
+
//# sourceMappingURL=scan.command-ADKVWN5T.js.map
|
|
13
|
+
//# sourceMappingURL=scan.command-ADKVWN5T.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"scan.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"scan.command-ADKVWN5T.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-UVWLW5KD.js';
|
|
2
|
+
import './chunk-TLEEAUD7.js';
|
|
3
|
+
import './chunk-NPPZVF24.js';
|
|
4
|
+
import './chunk-4A54P4EM.js';
|
|
5
|
+
import './chunk-J7PA7B2U.js';
|
|
6
|
+
import './chunk-2AGKN64R.js';
|
|
7
|
+
import './chunk-QZ6HBRJC.js';
|
|
8
|
+
import './chunk-XLYSNOR3.js';
|
|
9
|
+
import './chunk-6PEHRAEP.js';
|
|
10
|
+
//# sourceMappingURL=telemetry.command-CQFTGXPF.js.map
|
|
11
|
+
//# sourceMappingURL=telemetry.command-CQFTGXPF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"telemetry.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"telemetry.command-CQFTGXPF.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-4JMFWK65.js';
|
|
2
|
+
import './chunk-NPPZVF24.js';
|
|
3
|
+
import './chunk-4A54P4EM.js';
|
|
4
|
+
import './chunk-FYZ7LKLX.js';
|
|
5
|
+
import './chunk-EXG5VPNZ.js';
|
|
6
|
+
import './chunk-J7PA7B2U.js';
|
|
7
|
+
import './chunk-2AGKN64R.js';
|
|
8
|
+
import './chunk-QZ6HBRJC.js';
|
|
9
|
+
import './chunk-XLYSNOR3.js';
|
|
10
|
+
import './chunk-6PEHRAEP.js';
|
|
11
|
+
//# sourceMappingURL=typegen.command-A544SFYM.js.map
|
|
12
|
+
//# sourceMappingURL=typegen.command-A544SFYM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"typegen.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"typegen.command-A544SFYM.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "varlock",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "AI-safe .env files: Schemas for agents, Secrets for humans.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -84,6 +84,16 @@
|
|
|
84
84
|
"types": "./dist/runtime/patch-server-response.d.ts",
|
|
85
85
|
"default": "./dist/runtime/patch-server-response.js"
|
|
86
86
|
},
|
|
87
|
+
"./init-server": {
|
|
88
|
+
"ts-src": "./src/runtime/init-server.ts",
|
|
89
|
+
"types": "./dist/runtime/init-server.d.cts",
|
|
90
|
+
"default": "./dist/runtime/init-server.cjs"
|
|
91
|
+
},
|
|
92
|
+
"./init-edge": {
|
|
93
|
+
"ts-src": "./src/runtime/init-edge.ts",
|
|
94
|
+
"types": "./dist/runtime/init-edge.d.cts",
|
|
95
|
+
"default": "./dist/runtime/init-edge.cjs"
|
|
96
|
+
},
|
|
87
97
|
"./exec-sync-varlock": {
|
|
88
98
|
"ts-src": "./src/lib/exec-sync-varlock.ts",
|
|
89
99
|
"types": "./dist/lib/exec-sync-varlock.d.ts",
|
|
@@ -108,7 +118,7 @@
|
|
|
108
118
|
"devDependencies": {
|
|
109
119
|
"@clack/core": "^1.0.0",
|
|
110
120
|
"@clack/prompts": "^1.0.0",
|
|
111
|
-
"@env-spec/parser": "0.
|
|
121
|
+
"@env-spec/parser": "0.2.0",
|
|
112
122
|
"@env-spec/utils": "0.0.0",
|
|
113
123
|
"@sindresorhus/is": "^7.2.0",
|
|
114
124
|
"@types/node": "25.3.2",
|
package/dist/chunk-6SS4YD2I.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { CliExitError } from './chunk-PIOJV2A7.js';
|
|
2
|
-
import { ansis_default } from './chunk-NWY5IIPW.js';
|
|
3
|
-
import { pathExistsSync } from './chunk-PCRIVT4T.js';
|
|
4
|
-
import { createDebug } from './chunk-QZ6HBRJC.js';
|
|
5
|
-
import { __name } from './chunk-6PEHRAEP.js';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import fs, { existsSync } from 'fs';
|
|
8
|
-
import { execSync } from 'child_process';
|
|
9
|
-
|
|
10
|
-
var debug = createDebug("varlock:js-package-manager-utils");
|
|
11
|
-
var JS_PACKAGE_MANAGERS = Object.freeze({
|
|
12
|
-
npm: {
|
|
13
|
-
name: "npm",
|
|
14
|
-
lockfiles: ["package-lock.json"],
|
|
15
|
-
add: "npm install",
|
|
16
|
-
// add also works
|
|
17
|
-
exec: "npm exec --",
|
|
18
|
-
dlx: "npx"
|
|
19
|
-
},
|
|
20
|
-
pnpm: {
|
|
21
|
-
name: "pnpm",
|
|
22
|
-
lockfiles: ["pnpm-lock.yaml"],
|
|
23
|
-
add: "pnpm add",
|
|
24
|
-
exec: "pnpm exec",
|
|
25
|
-
dlx: "pnpm dlx"
|
|
26
|
-
},
|
|
27
|
-
yarn: {
|
|
28
|
-
name: "yarn",
|
|
29
|
-
lockfiles: ["yarn.lock"],
|
|
30
|
-
add: "yarn add",
|
|
31
|
-
exec: "yarn exec --",
|
|
32
|
-
dlx: "yarn dlx"
|
|
33
|
-
},
|
|
34
|
-
bun: {
|
|
35
|
-
name: "bun",
|
|
36
|
-
lockfiles: ["bun.lock", "bun.lockb"],
|
|
37
|
-
add: "bun add",
|
|
38
|
-
exec: "bun run",
|
|
39
|
-
dlx: "bunx"
|
|
40
|
-
},
|
|
41
|
-
deno: {
|
|
42
|
-
//! deno not fully supported yet
|
|
43
|
-
name: "deno",
|
|
44
|
-
lockfiles: ["deno.lock"],
|
|
45
|
-
add: "deno add",
|
|
46
|
-
// TODO: don't think these are quite right...
|
|
47
|
-
exec: "deno run",
|
|
48
|
-
dlx: "deno run"
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
function detectJsPackageManager(opts) {
|
|
52
|
-
debug("Detecting js package manager");
|
|
53
|
-
let cwd = opts?.cwd || process.cwd();
|
|
54
|
-
let multipleLockfilesDetected;
|
|
55
|
-
do {
|
|
56
|
-
debug(`> scanning ${cwd}`);
|
|
57
|
-
const scanDir = cwd;
|
|
58
|
-
let pm;
|
|
59
|
-
let detectedPm;
|
|
60
|
-
for (pm in JS_PACKAGE_MANAGERS) {
|
|
61
|
-
const foundLockfile = JS_PACKAGE_MANAGERS[pm].lockfiles.find(
|
|
62
|
-
(lockfile) => pathExistsSync(path.join(scanDir, lockfile))
|
|
63
|
-
);
|
|
64
|
-
if (foundLockfile) {
|
|
65
|
-
if (detectedPm) {
|
|
66
|
-
debug(`> found multiple lockfiles: ${foundLockfile} and ${JS_PACKAGE_MANAGERS[detectedPm].lockfiles[0]}`);
|
|
67
|
-
multipleLockfilesDetected = [detectedPm, pm];
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
debug(`> found ${foundLockfile}`);
|
|
71
|
-
detectedPm = pm;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (detectedPm && !multipleLockfilesDetected) return JS_PACKAGE_MANAGERS[detectedPm];
|
|
75
|
-
if (multipleLockfilesDetected) break;
|
|
76
|
-
const parentDir = path.dirname(cwd);
|
|
77
|
-
if (parentDir === cwd) break;
|
|
78
|
-
cwd = parentDir;
|
|
79
|
-
if (opts?.workspaceRootPath) {
|
|
80
|
-
if (opts.workspaceRootPath === cwd) {
|
|
81
|
-
debug("> found workspace root");
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
if (pathExistsSync(path.join(cwd, ".git"))) {
|
|
86
|
-
debug("> found git root");
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
} while (cwd);
|
|
91
|
-
if (process.env.npm_config_user_agent) {
|
|
92
|
-
const pmFromAgent = process.env.npm_config_user_agent.split("/")[0];
|
|
93
|
-
if (Object.keys(JS_PACKAGE_MANAGERS).includes(pmFromAgent)) {
|
|
94
|
-
debug(`> found ${pmFromAgent} using npm_config_user_agent`);
|
|
95
|
-
return JS_PACKAGE_MANAGERS[pmFromAgent];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (multipleLockfilesDetected) {
|
|
99
|
-
debug(`> using ${multipleLockfilesDetected[0]} from multiple detected lockfiles`);
|
|
100
|
-
return JS_PACKAGE_MANAGERS[multipleLockfilesDetected[0]];
|
|
101
|
-
}
|
|
102
|
-
if (opts?.exitIfNotFound) {
|
|
103
|
-
throw new CliExitError("Unable to find detect your JavaScript package manager!", {
|
|
104
|
-
suggestion: "We look for lock files (ex: package-lock.json) so you may just need to run a dependency install (ie `npm install`)",
|
|
105
|
-
forceExit: true
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
__name(detectJsPackageManager, "detectJsPackageManager");
|
|
110
|
-
function installJsDependency(opts) {
|
|
111
|
-
const packageJsonPath = path.join(opts.packagePath || process.cwd(), "package.json");
|
|
112
|
-
if (!existsSync(packageJsonPath)) return false;
|
|
113
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
114
|
-
if (packageJson.dependencies?.varlock) return false;
|
|
115
|
-
execSync([
|
|
116
|
-
// move to the correct directory if needed
|
|
117
|
-
opts.packagePath && `cd ${opts.packagePath} &&`,
|
|
118
|
-
// `add` works in all of them
|
|
119
|
-
`${opts.packageManager} add ${opts.packageName}`,
|
|
120
|
-
// tells pnpm to either install in the workspace root explicitly
|
|
121
|
-
// or to not check if we are the in the root
|
|
122
|
-
opts.packageManager === "pnpm" && (opts.isMonoRepoRoot ? "-w" : "--ignore-workspace-root-check")
|
|
123
|
-
].filter(Boolean).join(" "));
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
__name(installJsDependency, "installJsDependency");
|
|
127
|
-
|
|
128
|
-
// src/cli/helpers/pretty-format.ts
|
|
129
|
-
var fmt = {
|
|
130
|
-
decorator: /* @__PURE__ */ __name((s) => ansis_default.magenta(s), "decorator"),
|
|
131
|
-
filePath: /* @__PURE__ */ __name((s) => `\u{1F4C2} ${ansis_default.cyan.italic(s)}`, "filePath"),
|
|
132
|
-
fileName: /* @__PURE__ */ __name((s) => `${ansis_default.cyan.italic(s)}`, "fileName"),
|
|
133
|
-
command: /* @__PURE__ */ __name((s, opts) => {
|
|
134
|
-
let jsPackageManager;
|
|
135
|
-
if (opts?.jsPackageManager === true) {
|
|
136
|
-
jsPackageManager = detectJsPackageManager();
|
|
137
|
-
} else if (opts?.jsPackageManager) {
|
|
138
|
-
jsPackageManager = opts.jsPackageManager;
|
|
139
|
-
}
|
|
140
|
-
if (jsPackageManager) {
|
|
141
|
-
s = `${jsPackageManager.exec} ${s}`;
|
|
142
|
-
}
|
|
143
|
-
return ansis_default.green.italic(s);
|
|
144
|
-
}, "command"),
|
|
145
|
-
packageName: /* @__PURE__ */ __name((s) => ansis_default.green.italic(s), "packageName")
|
|
146
|
-
};
|
|
147
|
-
var logLines = /* @__PURE__ */ __name((lines) => {
|
|
148
|
-
for (const line of lines) {
|
|
149
|
-
if (!line && line !== "") continue;
|
|
150
|
-
console.log(line);
|
|
151
|
-
}
|
|
152
|
-
}, "logLines");
|
|
153
|
-
|
|
154
|
-
export { detectJsPackageManager, fmt, installJsDependency, logLines };
|
|
155
|
-
//# sourceMappingURL=chunk-6SS4YD2I.js.map
|
|
156
|
-
//# sourceMappingURL=chunk-6SS4YD2I.js.map
|