feat: support configurable quote character for dotenv export - #389
feat: support configurable quote character for dotenv export#389mateuscmtropical wants to merge 1 commit into
Conversation
`infisical export` always wrapped values in single quotes. Single quoted dotenv values have no escape sequences, so a multiline value (e.g. a PEM private key) can't be represented with a real newline. Adds --dotenv-quote-char (default: '), letting the value be wrapped in double quotes instead, which lets the existing multiline encoding decode back into a real newline on read. Only affects the dotenv/dotenv-export formats; validated up front, before any network call. Closes Infisical/infisical#1103
|
| Filename | Overview |
|---|---|
| packages/cmd/export.go | Adds configurable dotenv quoting, but applies verbatim double-quoted values to shell-oriented dotenv-export output, enabling shell interpretation. |
| packages/cmd/export_test.go | Adds broad unit coverage for formatting and validation, although it does not test shell consumption of double-quoted dotenv-export output. |
Reviews (1): Last reviewed commit: "feat: support configurable quote charact..." | Re-trigger Greptile
| // something parsers only do for double quoted values. That is the whole reason | ||
| // to pick it over the single quote default. | ||
| func quoteDotEnvValue(env models.SingleEnvironmentVariable, quoteChar string) string { | ||
| return quoteChar + escapeNewLinesIfRequired(env) + quoteChar |
There was a problem hiding this comment.
Double Quotes Enable Injection
When dotenv-export uses the new double-quote mode, secret contents remain active shell syntax. A value such as $(command) is emitted as export KEY="$(command)", so sourcing the generated shell-environment output executes the command. Embedded double quotes can also end the assignment and inject more shell syntax. Keep dotenv-export shell-safe regardless of the selected quote character, or reject double-quote mode for this format.
How this was verified: Arbitrary secret values flow directly into a double-quoted export assignment without escaping command substitutions, backticks, dollar signs, or double quotes.
Knowledge Base Used: Secret workflows
Description 📣
Implements #1103 (possibility to export env-s with different quote character).
infisical exportalways wrapped values in single quotes. Single quoted dotenv values have no escape sequences, so a multiline value (e.g. a PEM private key) can't be represented with a real newline — you'd have to post-process the file afterward.--dotenv-quote-char(default', existing output unchanged), accepting'or"dotenv/dotenv-exportformats;json/csv/yaml/dotenv-evalare unaffected--templatepathType ✨
Tests 🛠️
Ran
go test ./packages/cmd/... -vet=off(all passing).Verified against the real
dotenvnpm package (not just Go tests) that double-quoted output round-trips correctly for values with trailing backslashes, embedded quotes, backslash+quote combinations, and multiline private keys: