3

I'm creating a login module for Wildfly by extending org.jboss.security.auth.spi.DatabaseServerLoginModule and using log4j2 for debugging.

I've gotten into the habit of using log4j2's Logger.entry() and Logger.exit() methods for TRACE level logging, and the exit() method has the option of including the return value for a method.

In this particular instance, I'm overriding DatabaseServerLoginModule's createPasswordHash() method and I'm wondering if I need to skip including the return value in log.exit() - but it would be really helpful to see that the hashes being used to login match (or not) the hashes I am creating to register.

It smells wrong, but on my own I can't seem to come up with any reason not to since someone with access to the logs still wouldn't know what hash algorithm I used, how many iterations, salt, etc. But then again, I'm not the hacker trying to break into this account.

  • If not sure if I understood this correctly. a) You mean you want to do this live, not in a test environment? b) You're logging the hashed, salted passwords the users enter when they login, doesn't matter if right or wrong? c) Who can access this log? – deviantfan Dec 1 '15 at 1:14
  • 1
    Btw., relying that people don't know the algorithm is very very bad. Even more, with a hash+salt, as soon as the hash gets public there is a problem, independent if something is known about it. Not the problem that the users raw password (which could be used elsewhere too) is automatically known, but a big problem for your site/server. – deviantfan Dec 1 '15 at 1:15
  • I don't understand what you mean by In this particular instance, I'm overriding DatabaseServerLoginModule's createPasswordHash() method (overriding how?), but in general you never want to expose any hashes to any non-secure network. Especially if there is a chance the hashed passwords are weak. – cremefraiche Dec 1 '15 at 1:24
  • 1
    but it would be really helpful to see that the hashes being used to login match (or not) the hashes I am creating to register - ... won't you be able to tell that by whether the login succeeds or fails? – TessellatingHeckler Dec 1 '15 at 1:27
  • "but it would be really helpful to see that the hashes being used to login match (or not)" so log the state of the match, not the hash. Logging the hashes just increases the surface area exposed to attack/exploit. – Sammitch Dec 1 '15 at 1:30
9

Is logging a hashed password safe?

Do not do this.

Unless you protect your logs to the same degree as your database (which would be very unusual and probably difficult) you will be weakening your security.

If you have a secure hashing scheme (slow hash, good salt, etc.) the security impact should be minimal, but I doubt any impact would be worth the minor convenience you mentioned.

someone with access to the logs still wouldn't know what hash algorithm I used, how many iterations, salt, etc.

You don't want to depend on the parameters of your hashing scheme remaining a secret for security.

Information is very valuable to an attacker. They don't know these things yet, but a hash could help them figure it out. For example:

  1. The length and appearance of the hash might give some clues as to the algorithm
  2. They might be able to estimate the number of iterations (at least within a brute forceable range) by the time the server takes to complete the request
  3. If they know a password (eg. their own) this may leave the salt as the only unknown

It may then be computationally feasible to brute force the salt to confirm all the assumptions they made above.

Maybe an attacker can't do anything useful with this information, but maybe it will help them - you really don't want to give away any more than you have to.

Who knows, maybe they'll compromise your codebase at the same time they compromise your logs (not unlikely), or maybe a weakness will be discovered in your hashing algorithm sometime in the future.

  • Great, this answer was exactly what I was looking for, concrete reasons a hashed password in the logs might be useful for a hacker. Thank you. – Michael Guinn Dec 1 '15 at 5:02
  • I'm going to really disagree that the hash algorithm should be kept a secret. You've broken Kerchoffs principle en.wikipedia.org/wiki/Kerckhoffs%27s_principle , which states the only thing that should kept a secret is the key (in this case the password). This equally applies to the hash algorithm as it does to an encryption algorithm. Nobody would seriously think that keeping the crypto algorithm a secret adds seriously to the security, and nobody should think keeping the hash algorithm a secret adds to any security. – Steve Sether Dec 1 '15 at 18:17
  • @SteveSether I think you misread, my answer explicitly says "You don't want to depend on the parameters of your hashing scheme remaining a secret for security." – thexacre Dec 1 '15 at 18:20
  • @thexacre Then I don't understand these statements: "The length and appearance of the hash might give some clues as to the algorithm They might be able to estimate the number of iterations (at least within a brute forceable range) by the time the server takes to complete the request If they know a password (eg. their own) this may leave the salt as the only unknown" – Steve Sether Dec 1 '15 at 18:38
  • @SteveSether that is to challenge the assumption made in the question that an attacker could not know these things. – thexacre Dec 1 '15 at 18:57
1

thexacre's answer already contains the most important arguments. I want to add one more:

Even if you would assume that the hashed passwords are safe now (you should not), you never know what the future holds. A weakness might be discovered in your hashing algorithm or implementation which makes the hashed passwords crackable. Then you would not only have to worry about securing the hashes in the database with a new strategy, but also in the log files - including all existing log files.

  • should 'are save now' be 'are safe now' ? – rjdkolb Dec 1 '15 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.