IntelliJ IDEA HTTP client ${env.VAR} placeholder limits for credential-light testing
0 reputation · 27 Sept 2020, 20:32 UTC
0 reputation · 27 Sept 2020, 20:32 UTC
Goal is to test an integration using IntelliJ IDEA HTTP Client without committing production API keys. The documented capability to use ${env.VAR} placeholders in headers and bodies, available from IntelliJ IDEA 2023.3 onward, suggests credential-light requests can be authored with dummy values.
Constraints include the scope of placeholder resolution, the interaction with run configurations that reference ${env.ACCESS_TOKEN}, and the reported session-only nature of OAuth2 token storage which requires re-provisioning each debugging session. There is also uncertainty about exposure of resolved values in IDE logs or shared .http files.
Does placeholder substitution apply consistently across headers, bodies, and OAuth2 pre-requests? Is the resolution limited to system environment variables or also to run-configuration environment? What controls exist to prevent resolved values from being persisted in shared configuration?
34775 reputation · 27 Sept 2020, 23:56 UTC
Yes — since IntelliJ IDEA 2023.3, ${env.VAR} substitution applies consistently across URLs, query parameters, headers, request bodies, and the OAuth2 authentication dialog fields. Resolution draws from both run-configuration environment variables and system environment variables, with the run configuration taking precedence when the request is executed through one. The placeholder itself is the only thing persisted in the .http file, so shared files stay credential-free by design.
Placeholders resolve anywhere a string value is accepted in a request: the request line, headers, body, and the auth configuration (including OAuth2 token fields). Tokens fetched at runtime through the OAuth2 flow are held in memory for the IDE session only, which matches the re-provisioning behavior you've observed — restarting the IDE means re-authenticating. (The refresh token, if used, is kept in the IDE's encrypted credential store; access tokens are not.)
When you run a request via a Run Configuration (or the "Execute with" gutter dropdown), that configuration's environment variables are passed to the HTTP Client and override same-named system variables. Without a run configuration, only system environment variables are used. Two practical caveats:
${env.VAR:-fallback} does not work). A missing variable resolves to an empty string, which can produce silently malformed requests.The .http file is safe: placeholders are never rewritten with resolved values. The risks are elsewhere:
.idea/runConfigurations/*.xml or workspace.xml. Keep real secrets out of committed files — use dummy values in shared configs and real ones only in local, uncommitted system env vars..http files with ${env.ACCESS_TOKEN}-style placeholders everywhere a secret would appear.ACCESS_TOKEN=dummy) so integration tests run against a mock or sandbox endpoint.Create a scratch request using ${env.TEST_VAR} in the URL, a header, and the body. Run it once with a run configuration defining TEST_VAR=from-run-config and once without; the Run window shows which source wins. Then reopen the .http file to confirm placeholders are intact, and grep idea.log for the resolved value to confirm your logging setting. Behavior described reflects 2023.3+; verify against your exact IDE version, as placeholder handling has evolved across releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.