I recently had an issue with one of my laravel websites where the smtp credentials got stolen and used for spam. I realized it was due to the debug mode set to true in .env file. I turned that off and set the mode to production, however I am still having the same issue. I checked if my .env file is exposed to the public by setting example.com/.env but it is not. Does anyone have any suggestions? Thanks.
@Sinnbeck Thank you for the response. I think it is best if I don't share the url but yes I am using file upload on it. Validation only allows for images. What issue could arise from it?
@shawon_kamal ok then hire a pen tester to find the security problem :)
My best idea is that you have some problem with your config of the site. But I don't know every single cve in my head. Or that your upload allows images with embedded Phar code and allows the user access to the output somehow. But these are just guesses based on no information
But perhaps concider using environment variables instead of an env file
Why are you using a .env file is production. If using, it needs to be out of web folders.
If this is shared hosting, put all of main laravel higher than webroot (out of).
If that's not possible point to public as document root. However if a host does not allow to move certain folders / files above web root, my suggestion is don't use that host.
You said that the .env file is not accessible via the web, which means that it's secure. Good stuff.
You say " I turned that off and set the mode to production, however I am still having the same issue" - what is the issue? Is it still acting as if debug=true even though set it to false?
If that's the case, make sure you run php artisan optimize:clear
If that's not it, then where/how are your credentials being exposed via the web? Without knowing that, there's nothing anybody here will be able to say to help you.
@shawnveltman I worded it poorly. I meant even after turning of debug mode and changing my smtp credentials, it got exposed again. I know that because the SMTP provider shut it down due to spam being sent from the account. None of the spams are sent from my server.
It's impossible that .env files or env var was exposed, at least that you expose them explicitly in some way (print phpinfo or dump env vars in a test controller or putting it in public directory).
In the other hand, you must to change all AWS credentials (inclusive root) because you don't know where is the lack.
Tell about your deployment process, how do you put sensitive values in the server? How to create the .env file?
It will be good review the below:
check apache logs to see bad intentioned requests (if the values are exposed by http you could see the responsible requests here)