mediumCWE-540A02:2021

Inadequate .gitignore

A .gitignore that doesn't cover .env files, build artifacts, and IDE configs can lead to secrets or sensitive data being accidentally committed.

How It Works

If .env, .env.local, and similar files aren't in .gitignore, one 'git add .' commits all your secrets. Similarly, IDE config files often contain API tokens, personal settings, or absolute paths that leak developer machine information. Build artifacts can contain source maps that reveal your full source code.

Vulnerable Code
# BAD: minimal .gitignore that misses common secret files
node_modules/
dist/
# Missing: .env, .env.local, .env.production, *.pem, .DS_Store
Secure Code
# GOOD: comprehensive .gitignore for a Node.js project
node_modules/
dist/
.next/
# Secrets
.env
.env.local
.env.*.local
*.pem
*.key
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
Thumbs.db

Real-World Example

In 2022, a developer accidentally committed .env.production to a public GitHub repo. It contained Stripe production keys, database credentials, and Twilio API tokens. The repo was public for 8 hours before being discovered, resulting in fraudulent charges.

How to Prevent It

  • Use GitHub's official .gitignore templates as a starting point for your language/framework
  • Always include .env, .env.local, .env.*.local, *.pem, and *.key in .gitignore
  • Run 'git status' and review every file before committing, especially when first setting up a project
  • Install the gitignore global config for your OS (like .DS_Store) in ~/.gitignore_global

Affected Technologies

Node.js

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities