DEV Community

Cover image for Be careful when using .env files
Miguel A. Calles
Miguel A. Calles

Posted on • Originally published at miguelacallesmba.Medium

1

Be careful when using .env files

Not even within 24 hours, a recently launched website was being sniffed for secrets. A bot was searching for a .env file where some projects store secrets. Fortunately, this website was protected by Cloudflare.

What can we learn from this?

The .env file should be treated as a potential source of a cyber breach. We should be cautious about what data we store there.

Should we put secrets in the .env file?

No, when possible.

Where should we store and use secrets?

Store secrets in a secrets manager or database. Limit the use of secrets to the backend code (i.e., the code not used in the frontend web application code).

How can we protect the .env file?

We should use a Web Application Firewall to stop external HTTP requests from reading this file. The file should only be read by the application code.


Originally published on Medium

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay