{"action":"created","issue":{"url":"https://api.github.com/repos/binarylogic/authlogic/issues/442","labels_url":"https://api.github.com/repos/binarylogic/authlogic/issues/442/labels{/name}","comments_url":"https://api.github.com/repos/binarylogic/authlogic/issues/442/comments","events_url":"https://api.github.com/repos/binarylogic/authlogic/issues/442/events","html_url":"https://github.com/binarylogic/authlogic/issues/442","id":48213483,"number":442,"title":"SCrypt security","user":{"login":"MG67Yjkkljd","id":9066231,"avatar_url":"https://avatars.githubusercontent.com/u/9066231?v=3","gravatar_id":"","url":"https://api.github.com/users/MG67Yjkkljd","html_url":"https://github.com/MG67Yjkkljd","followers_url":"https://api.github.com/users/MG67Yjkkljd/followers","following_url":"https://api.github.com/users/MG67Yjkkljd/following{/other_user}","gists_url":"https://api.github.com/users/MG67Yjkkljd/gists{/gist_id}","starred_url":"https://api.github.com/users/MG67Yjkkljd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MG67Yjkkljd/subscriptions","organizations_url":"https://api.github.com/users/MG67Yjkkljd/orgs","repos_url":"https://api.github.com/users/MG67Yjkkljd/repos","events_url":"https://api.github.com/users/MG67Yjkkljd/events{/privacy}","received_events_url":"https://api.github.com/users/MG67Yjkkljd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-11-09T21:00:43Z","updated_at":"2015-01-30T17:53:47Z","closed_at":null,"body":"In the SCrypt crypto_provider ('scrypt.rb'), the 'matches?' method seems to use the 2-way nature of SCrypt to decrypt the password/salt then compare against the supplied password value. This is a security weak spot as every attempt will bring the password into plain text inside the memory, thus negating the one main reason for generating hashed passwords. Instead, SCrypt's '==' or 'is_password?' method should be used to compare the attempted password and salt against the already hashed secret, something like this:\r\n\r\n# Does the hash match the tokens? Uses the same tokens that were used to encrypt.\r\n        def matches?(hash, *tokens)\r\n          totalSecret = join_tokens(tokens)\r\n          password = ::SCrypt::Password.new(hash)\r\n          result = password.is_password?(totalSecret)\r\n          return\r\n        end"},"comment":{"url":"https://api.github.com/repos/binarylogic/authlogic/issues/comments/72241600","html_url":"https://github.com/binarylogic/authlogic/issues/442#issuecomment-72241600","issue_url":"https://api.github.com/repos/binarylogic/authlogic/issues/442","id":72241600,"user":{"login":"jjarmoc","id":48389,"avatar_url":"https://avatars.githubusercontent.com/u/48389?v=3","gravatar_id":"","url":"https://api.github.com/users/jjarmoc","html_url":"https://github.com/jjarmoc","followers_url":"https://api.github.com/users/jjarmoc/followers","following_url":"https://api.github.com/users/jjarmoc/following{/other_user}","gists_url":"https://api.github.com/users/jjarmoc/gists{/gist_id}","starred_url":"https://api.github.com/users/jjarmoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjarmoc/subscriptions","organizations_url":"https://api.github.com/users/jjarmoc/orgs","repos_url":"https://api.github.com/users/jjarmoc/repos","events_url":"https://api.github.com/users/jjarmoc/events{/privacy}","received_events_url":"https://api.github.com/users/jjarmoc/received_events","type":"User","site_admin":false},"created_at":"2015-01-30T17:53:47Z","updated_at":"2015-01-30T17:53:47Z","body":"I don't think this is valid.\r\n\r\nThe code inlined in the comment doesn't appear in https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/scrypt.rb\r\n\r\n`scrypt` is a one-way key derivation function.  It's not reversible as you describe, so I don't see how this could have been valid anyhow.    The code as it exists today (and appears to have always existed from the git history) instantiates a `SCrypt::Password` and calls `==` to compare it to the password attempt.\r\n\r\nAs the reporter seems to be aware, the Scrypt gem defines `==` which calculates the scrypt digest of the attempted password, and compares this to the stored digest.\r\nhttps://github.com/pbhogan/scrypt/blob/master/lib/scrypt.rb#L237"}}