HTTP Client environment file visibility and version control protection
0 reputation · 29 May 2021, 08:37 UTC
0 reputation · 29 May 2021, 08:37 UTC
PhpStorm's built-in HTTP Client supports the use of http-client.env.json files to manage request variables across different environments. To prevent sensitive credentials from being committed to version control, the IDE provides a "Private" environment file option, which typically ensures the file is excluded from the project's git tracking by adding it to the .idea/gitignore.
While the private flag automates the ignore process, there is no native mechanism to prevent a user from manually overriding these git settings or accidentally hardcoding secrets directly within the .http request files themselves. This creates a risk where sensitive data may be leaked if the developer bypasses the intended environment file workflow.
.http files?34775 reputation · 29 May 2021, 14:46 UTC
PhpStorm does not provide a built‑in setting that forces developers to use environment variables instead of hardcoded values in .http files, nor does it automatically warn when a file marked as “Private” is staged for commit. The IDE’s private‑file feature only adds an entry to .idea/gitignore; it cannot stop a user from overriding that ignore rule or from committing secrets directly in request files.
.idea/gitignore (e.g., http-client.env.json)..idea/gitignore are ignored by Git only as long as the ignore rule is not overridden by a later !pattern or by a forced git add -f.password\s*=\s*['\"][^'\"]+['\"]) inside .http files.git‑secrets, or repository‑level .gitignore rules) is the reliable way to block commits of private environment files or of files containing secret‑like patterns..idea/gitignore and verify a line like http-client.env.json exists.git check-ignore -v http-client.env.json – the output should show the rule from .idea/gitignore..gitignore entry for the environment file (or for *.env*) as a safety net in case the .idea directory is excluded.#!/usr/bin/env bash
if git diff --cached --name-only | grep -q '^http-client.env.json$'; then
echo "Error: Private environment file is staged for commit."
exit 1
fi
Make the script executable and place it in .git/hooks/pre-commit (or use a framework like husky)..http files:
Settings/Preferences | Editor | Inspections.+ button → Structural Search Replace → Add Template.$Password$\s*=\s*['\"][^'\"]+['\"] with a severity of Warning.*.http files.{{variable}} syntax and to never place raw credentials directly in .http files.git status – the private environment file should not appear under “Untracked files”.git add -f http-client.env.json; the file will be added only if you force it, confirming that the ignore rule is active but overridable..http file; a warning should appear in the editor.If you are using a PhpStorm version prior to 2023.2, the UI for marking a file as “Private” may differ slightly; the underlying .idea/gitignore mechanism remains the same.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 29 May 2021, 13:40 UTC
The Private flag only appends the file path to .idea/gitignore. If the .idea directory is excluded from the repository, the ignore rule disappears and the file can be tracked. A more reliable approach is to add a root‑level .gitignore entry, e.g. http-client.env.json or *.env*, and pair it with a pre‑commit hook that aborts on staged private files.
Additionally, you can leverage PhpStorm’s Structural Search and Replace to surface hard‑coded credential patterns in .http files, providing a lightweight inspection layer before a commit is made.