From 22b10aa634c9aaeb11a916406353de87457ebbfe Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Nov 2026 23:38:48 +0000 Subject: [PATCH 1/2] Do not write reserved names from Hyphen ENV to process.env `Env.load` wrote each remote name to `process.env`. Some names control the Node.js runtime, OpenSSL, the dynamic loader, and the command shell. A person with write access to the ENV data could use these names to change the behavior of the application and of its child processes. `Env.load` does not write these names now. It sends one `warn` event that lists the names and not the values. The returned object contains all the remote values, as before. Co-authored-by: Jared Wray --- packages/nodejs-sdk/src/env-service.ts | 47 ++++++++++- packages/nodejs-sdk/test/env-service.test.ts | 85 ++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/packages/nodejs-sdk/src/env-service.ts b/packages/nodejs-sdk/src/env-service.ts index 523545d..f934199 100644 --- a/packages/nodejs-sdk/src/env-service.ts +++ b/packages/nodejs-sdk/src/env-service.ts @@ -31,6 +31,33 @@ const environmentNamePattern = /^[a-z0-9_-]+$/; const base64UrlPattern = /^[A-Za-z0-9_-]+={0,2}$/; const utf8Decoder = new TextDecoder("utf-8", { fatal: true }); +/** + * `load` does not write these names to `process.env`. The Node.js runtime, + * OpenSSL, and the command shell read them to load code, to find programs and + * modules, or to trust certificates. `HYPHEN_API_KEY` is the SDK credential. + */ +const reservedNames = new Set([ + "BASH_ENV", + "COMSPEC", + "HYPHEN_API_KEY", + "NODE_COMPILE_CACHE", + "NODE_EXTRA_CA_CERTS", + "NODE_OPTIONS", + "NODE_PATH", + "NODE_REPL_EXTERNAL_MODULE", + "NODE_TLS_REJECT_UNAUTHORIZED", + "OPENSSL_CONF", + "OPENSSL_ENGINES", + "OPENSSL_MODULES", + "PATH", + "PATHEXT", + "SSL_CERT_DIR", + "SSL_CERT_FILE", +]); + +/** The dynamic loader reads each name that starts with one of these prefixes. */ +const reservedNamePrefixes = ["DYLD_", "LD_"]; + class SafeEnvError extends Error {} export class Env extends BaseService { @@ -103,11 +130,20 @@ export class Env extends BaseService { ); } + const override = options?.override ?? true; + const skippedNames: string[] = []; for (const [name, value] of entries) { - if ((options?.override ?? true) || process.env[name] === undefined) { + if (isReservedName(name)) { + skippedNames.push(name); + } else if (override || process.env[name] === undefined) { process.env[name] = value; } } + if (skippedNames.length > 0) { + this.warn( + `Hyphen ENV did not add these reserved names to process.env: ${skippedNames.join(", ")}.`, + ); + } return variables; } @@ -204,6 +240,15 @@ function normalizeEnvironmentName(environment: string): string { return name; } +function isReservedName(name: string): boolean { + // Windows ignores the case of a variable name. + const upperName = name.toUpperCase(); + return ( + reservedNames.has(upperName) || + reservedNamePrefixes.some((prefix) => upperName.startsWith(prefix)) + ); +} + function validateKey(key: { secretKeyId: unknown; secretKey: unknown; diff --git a/packages/nodejs-sdk/test/env-service.test.ts b/packages/nodejs-sdk/test/env-service.test.ts index b401da7..9c482bb 100644 --- a/packages/nodejs-sdk/test/env-service.test.ts +++ b/packages/nodejs-sdk/test/env-service.test.ts @@ -29,6 +29,7 @@ const testVariableNames = [ "NAMED_ONLY", "NEW_VALUE", "ONLY_NAMED", + "ORDINARY_NAME", "QUOTED", "SETTER_KEY", "SHARED", @@ -287,6 +288,90 @@ describe("Env", () => { expect(process.env.SHARED).toBe("remote"); }); + describe("reserved names", () => { + test.each([ + "BASH_ENV", + "COMSPEC", + "DYLD_INSERT_LIBRARIES", + "HYPHEN_API_KEY", + "LD_PRELOAD", + "NODE_COMPILE_CACHE", + "NODE_EXTRA_CA_CERTS", + "NODE_OPTIONS", + "NODE_PATH", + "NODE_REPL_EXTERNAL_MODULE", + "NODE_TLS_REJECT_UNAUTHORIZED", + "OPENSSL_CONF", + "OPENSSL_ENGINES", + "OPENSSL_MODULES", + "PATH", + "PATHEXT", + "SSL_CERT_DIR", + "SSL_CERT_FILE", + "ld_library_path", + "node_options", + "Path", + ])("does not write the reserved name %s to process.env", async (name) => { + const before = process.env[name]; + const service = createService({ decryptionKey }); + vi.spyOn(service.log, "warn").mockImplementation(() => undefined); + vi.spyOn(service, "get").mockResolvedValue( + mockEnvResponse(`${name}=remote\nORDINARY_NAME=written\n`), + ); + + await expect(service.load()).resolves.toEqual({ + [name]: "remote", + ORDINARY_NAME: "written", + }); + expect(process.env[name]).toBe(before); + expect(process.env.ORDINARY_NAME).toBe("written"); + + await service.load("default", { override: false }); + expect(process.env[name]).toBe(before); + }); + + test.each(["LDAP_URL", "NODE_CONFIG", "NODE_ENV", "PATHNAME"])( + "writes the name %s, which is not reserved", + async (name) => { + const service = createService({ decryptionKey }); + const warnListener = vi.fn(); + service.on("warn", warnListener); + vi.spyOn(service, "get").mockResolvedValue( + mockEnvResponse(`${name}=remote\n`), + ); + + await service.load(); + + expect(process.env[name]).toBe("remote"); + expect(warnListener).not.toHaveBeenCalled(); + }, + ); + + test("reports each skipped name and no value", async () => { + const service = createService({ decryptionKey }); + const logSpy = vi + .spyOn(service.log, "warn") + .mockImplementation(() => undefined); + const warnListener = vi.fn(); + service.on("warn", warnListener); + vi.spyOn(service, "get").mockResolvedValue( + mockEnvResponse( + "NODE_OPTIONS=--first-secret\nORDINARY_NAME=written\nLD_PRELOAD=second-secret\n", + ), + ); + + await service.load(); + + expect(warnListener).toHaveBeenCalledOnce(); + const [message] = warnListener.mock.calls[0]; + expect(message).toContain("NODE_OPTIONS"); + expect(message).toContain("LD_PRELOAD"); + expect(message).not.toContain("ORDINARY_NAME"); + expect(message).not.toContain("secret"); + expect(logSpy).toHaveBeenCalledExactlyOnceWith(message); + }); + }); + test("uses an explicit key without requiring a project or requesting the key store", async () => { const service = new Env({ apiKey, From a8bbcc795571a8a58bdd875366881da0495dba2b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Nov 2026 23:38:48 +0000 Subject: [PATCH 2/2] Document the reserved names of Env.load in the Node.js SDK README The ENV section lists the names that `Env.load` does not add to `process.env`. It also tells the user about the `warn` event and the limit of the list. Co-authored-by: Jared Wray --- packages/nodejs-sdk/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/nodejs-sdk/README.md b/packages/nodejs-sdk/README.md index 2ddf541..dacd916 100644 --- a/packages/nodejs-sdk/README.md +++ b/packages/nodejs-sdk/README.md @@ -634,6 +634,28 @@ await hyphen.env.load('production', { }); ``` +The service does not add a reserved name to `process.env`. Node.js, OpenSSL, the +dynamic loader, and the command shell read these names to load code, to find +programs and modules, or to trust certificates. The comparison ignores the case +of the name. These names are reserved: + +- `NODE_OPTIONS`, `NODE_PATH`, `NODE_REPL_EXTERNAL_MODULE`, and + `NODE_COMPILE_CACHE` +- `NODE_EXTRA_CA_CERTS` and `NODE_TLS_REJECT_UNAUTHORIZED` +- `OPENSSL_CONF`, `OPENSSL_ENGINES`, `OPENSSL_MODULES`, `SSL_CERT_DIR`, and + `SSL_CERT_FILE` +- `PATH`, `PATHEXT`, `COMSPEC`, and `BASH_ENV` +- Each name that starts with `LD_` or `DYLD_` +- `HYPHEN_API_KEY` + +The service sends one `warn` event that lists the names that it did not add. The +event does not contain the values. The returned object contains the reserved +names and their values. Other names, for example `NODE_ENV`, are not reserved. + +The list contains only the names that these programs read. A different +program can read a different name. Give write access to your ENV data only to +persons who can change the code of the application. + The service reads missing configuration from `HYPHEN_API_KEY`, `HYPHEN_ORGANIZATION_ID`, `HYPHEN_PROJECT_ID`, and `HYPHEN_APPLICATION_ID`, with `HYPHEN_APP_ID` supported as a compatibility