feat: encrypt env blob with _VARLOCK_ENV_KEY#656
Conversation
|
The changes in this PR will be included in the next version bump.
|
varlock
@varlock/astro-integration
@varlock/cloudflare-integration
@varlock/expo-integration
@varlock/nextjs-integration
@varlock/vite-integration
@varlock/1password-plugin
@varlock/akeyless-plugin
@varlock/aws-secrets-plugin
@varlock/azure-key-vault-plugin
@varlock/bitwarden-plugin
@varlock/dashlane-plugin
@varlock/doppler-plugin
@varlock/google-secret-manager-plugin
@varlock/hashicorp-vault-plugin
@varlock/infisical-plugin
@varlock/keepass-plugin
@varlock/keeper-plugin
@varlock/pass-plugin
@varlock/passbolt-plugin
@varlock/proton-pass-plugin
commit: |
When _VARLOCK_ENV_KEY (64-char hex) is set at build time, the resolved env blob injected into build output is encrypted with AES-256-GCM. At runtime, the init bundles detect the varlock:v1: prefix and decrypt using the same key from the runtime environment. This lets Vercel users set a single env var and have all other config travel encrypted inside the deployment artifact. - New crypto module with sync (node:crypto) and async (Web Crypto) paths - All integration injection points (Next.js, Vite) encrypt when key is present - _VARLOCK_ENV_KEY auto-excluded from injected blob and type generation - varlock generate-key CLI command with --plain flag for piping - Docs for Next.js and Vite integrations - Framework tests for encrypted blob flow
d467143 to
93ac514
Compare
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
varlock-website | 93ac514 | Commit Preview URL Branch Preview URL |
Apr 25 2026, 08:37 AM |


Summary
Adds opt-in encryption for the resolved env blob (
__VARLOCK_ENV) that gets injected into build output by the Next.js and Vite integrations._VARLOCK_ENV_KEY(64-char hex) is set at build time, the JSON blob is encrypted with AES-256-GCM before injectionvarlock:v1:prefix and decrypt using the same key from the runtime environmentvarlock generate-keyCLI command with--plainflag for piping to platform CLIs_VARLOCK_ENV_KEYcan be defined in.env.schemafor validation — it's automatically excluded from the injected blob and type generationNOTE — Ideally we'd reinject vars back into the platform's native secret storage, but doing this atomically with a deployment is not always possible.
Quick setup (Vercel)
varlock generate-key --plain | vercel env add _VARLOCK_ENV_KEY production preview development --sensitiveChanges
varlockruntime/crypto.tswith sync (node:crypto) + async (Web Crypto) encrypt/decryptvarlockinit-server.ts/init-edge.tsdecrypt beforeinitVarlockEnv()varlockenv.tshandles encrypted strings onglobalThis.__varlockLoadedEnvvarlockgenerate-keyCLI command with--plainflagvarlock./encrypt-envsubpath export@varlock/nextjs-integration@varlock/vite-integrationresolved-envSSR mode encrypts when key presentDocs
generate-keycommandTest plan
_VARLOCK_ENV_KEY, verifyvarlock:v1:prefix in output, verify runtime decryptionresolved-envmode with encryption