I have implemented a routine where when a user submits a form an email is sent to the administrator. For this I have used Java Mail API. And I setup a dummy account on Microsoft Outlook for sending out the emails. In the code I have hard-coded the password. I am concerned this will be a security issue when I host the webpage.
Here is my code.
I have written a private function:
private void getSession(){
this.session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication
getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "xxxxx_password_xxx");
}
});
}
In my public execute()
method I call the getSession()
method and generate the message.
public String execute() throws Exception {
getSession();
Message message = new MimeMessage(this.session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Form submit notification");
//...
}
Is it secure to hard code the password in the session method when I host the web page?
And if not, then some pointers to implement the alternatives.
Thanks!
In this case he can't hash the password. A password can be hashed only when it needs to be CHECKED and not USED. Using the password (i.e. the back end needs to login to an SMTP server to send an email, or to another database to extract data) implies the need to know it.
There are 3+1 levels of alternatives in this case, basically shifting the insecurity from the code to somewhere else. But the attacker will always be able to recover the password given the same pre-conditions of the program. The likelihood of getting to them measures the level of security of that password.
A raking of the risk of these solutions
0-- Password hardcoded in srcs --> The risk is connected to the ease of retrieval of the code; decompilation to extract harcoded strings is not difficult even in C/C++, in Java and .NET is trivial and instant
Of course, from 1 to 3, the implementation gets much harder. 4 is a matter of the HSM's api.