feat: encrypt env blob with _VARLOCK_ENV_KEY#656
Open
theoephraim wants to merge 1 commit intomainfrom
Open
Conversation
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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