{"id":3359,"date":"2015-06-25T16:14:56","date_gmt":"2015-06-25T21:14:56","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=3359"},"modified":"2018-01-06T18:49:10","modified_gmt":"2018-01-07T00:49:10","slug":"never-store-answers-to-security-questions-in-plain-text","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/never-store-answers-to-security-questions-in-plain-text\/","title":{"rendered":"Answers to password reset questions are passwords too \u2014 so why aren&#8217;t we treating them that way?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-3363 colorbox-3359\" src=\"\/blog\/wp-content\/uploads\/identity-theft.jpg\" alt=\"identity-theft\" width=\"174\" height=\"174\" srcset=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/identity-theft.jpg 250w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/identity-theft-150x150.jpg 150w\" sizes=\"auto, (max-width: 174px) 100vw, 174px\" \/>If you&#8217;re a developer working on or maintaining a website catering to the general public, chances are you&#8217;ve implemented some form of password reset via security question-and-answer into your site.\u00a0How are you storing the answers to these questions in your database? Are you encrypting them? Storing the (hopefully cryptographic, salted) hashes? Or are you storing them plain text?<\/p>\n<p>I can&#8217;t answer for you, but I can tell you that I&#8217;ve never used a system that didn&#8217;t leave tell-tale signs of storing these answers in plaintext. Here&#8217;s the thing &#8211; if it&#8217;s possible to use these answers to reset a password, then these answers, by extension, are passwords too.<\/p>\n<p>In some ways, <b>answers to password reset questions are\u00a0<em>more<\/em> important than the password itself<\/b>. With the password, an attacker can compromise and gain control of a user&#8217;s account. With the answers to security questions, an attacker can compromise a user&#8217;s entire online <i>and<\/i> offline\u00a0security, steal their identity, and quite-literally ruin their lives. Think about it, these same questions (mother&#8217;s maiden name, childhood best friend, street you grew up on, where you were on New Year&#8217;s Eve of 2000) are the same questions\u00a0<em>every<\/em> site asks you to confirm your identity and reset your password. They&#8217;re the questions your telephone banker asks before divulging account info or letting you wire money to an international account. They&#8217;re the questions that you&#8217;ll be asked when applying for a credit card to prove you&#8217;re who you claim to be.<\/p>\n<p><!--more--><\/p>\n<p>For many, a strictly email-based password reset interface isn&#8217;t an option, whether it&#8217;s because you need to implement some form of over-the-phone verification when speaking to customer support to perform actions requiring authentication (\u00e0 la every bank and wireless carrier), as an extra step to prevent against password resets by people with access to your email (\u00e0 la Facebook, Gmail, etc.), or to bypass email entirely when you can&#8217;t guarantee your users (still) have access to their email or are capable of following the oh-so-complicated process of logging in to a separate system in order to reset the password on yours.<\/p>\n<p>Regardless of your reasons for using a security-question-and-answer password reset interface, regardless of whether it&#8217;s the only the first or just the only step in the password reset process, answers to these questions are\u00a0<em>sensitive<\/em> and they should be treated as such. It doesn&#8217;t matter who you are, how good your intentions are, or how &#8220;secure&#8221; your system is &#8211; at some point, you and your customers will wish these answers weren&#8217;t stored in plain text in your database. It&#8217;s not just about when (never <em>if<\/em>) your database is compromised &#8211; can you guarantee you&#8217;ll never have a security breach or an untrustworthy employee?<\/p>\n<p>How do you protect your users&#8217; passwords? It&#8217;s 2015, and it&#8217;s probably safe to say that even the most oblivious of developers and architects know that storing passwords in the database in plaintext is a horrible idea (which doesn&#8217;t mean they won&#8217;t still do it, but that&#8217;s getting off-topic), and probably even know that storing the MD5 (salted or not) isn&#8217;t such a hot idea either (even if they don&#8217;t quite know why). If you know what you&#8217;re doing, you&#8217;re probably storing your passwords in the database with some sort of key-stretching algorithm using PBKDF2, scrypt, bcrypt, or similar. Awesome. But what about these valuable answers to the security questions?\u00a0<strong>Store these answers in the database with [scrypt|bcrypt|pbkdf2] as well.<\/strong><\/p>\n<p>There really is no way around this. If you love\u00a0<em>or\u00a0<\/em>respect your users at all, you will treat these answers as sacred. You will show your users that you value the fact that they&#8217;ve entrusted you with them, and you will never, ever,\u00a0<em>ever<\/em> store them as plain-text in the database ever again.<\/p>\n<p><strong>But I need to validate these answers over the phone!<\/strong><\/p>\n<p>OK, and where&#8217;s the problem? Your customer support agents ask the customer &#8220;what&#8217;s your mother&#8217;s maiden name&#8221; and then they have to enter it into an input box for validation, whereupon the password hash is calculated and compared to the correct hash. Why are they doing the comparison visually in the first place? Look at it this way &#8211; not only are you protecting your users against database compromise, you&#8217;ve also solved your problem with attackers using your technical support staff as socially-engineered proxies to do their bidding.<\/p>\n<p><b>But I don&#8217;t want the answers to be case-sensitive!<\/b><\/p>\n<p>Here the workarounds and hacks start, but your users&#8217; data is worth it. There is no rule on what you can or can&#8217;t do to the input text (so long as you&#8217;re careful). Instead of your answer\u00a0hash, as stored in the database, being\u00a0<code>h(answer)<\/code> it can be <code>h(tolower(answer))<\/code>, where\u00a0<code>tolower<\/code> is a unicode-aware, multibyte-safe, culture-invariant transform, of course.<\/p>\n<p><strong>But I need to present the user with a hint!<\/strong><\/p>\n<p>Getting into dangerous territory here, you should probably ask yourself if you&#8217;re sure you want to do that. But assuming you insist, and you want to present your customer with a censored\/redacted version of the answer as a &#8220;hint,&#8221; you can store the redacted hint in the database separately. But really, you shouldn&#8217;t.<\/p>\n<p>(e.g. instead of storing &#8220;Willowbrook Rd&#8221; as-is in the database so you can show a hint &#8220;W***o*****k R*&#8221; to the user, go ahead and store the literal string\u00a0&#8220;W***o*****k R*&#8221; in the database. But don&#8217;t.)<\/p>\n<p><strong>But I want to handle misspellings gracefully!<\/strong><\/p>\n<p>Are you sure you want your customer support agents accepting Smyth instead of Smith? Are you\u00a0<em>sure<\/em>? Fine, on your own head be it, but fuzzy-hashing is a thing. I&#8217;m not entirely sure on how you can safely use that in conjunction with a key-stretching algorithm for maximum security, but anything beats plaintext.<\/p>\n<p><strong>But no one else cares!<\/strong><\/p>\n<p>Alas, here we come to the crux of the matter. This post is written largely in vain. It&#8217;s likely far\u00a0too late; chances are, if you&#8217;re reading this, the answers to your own questions are already sitting there in a database, just waiting to be leaked and abused. Actually, they probably already have been &#8211; attackers have long prioritized username\/password data over anything else because it&#8217;s the lowest hanging fruit and can be brute-forced to gain access to email and bank accounts, etc. but for dedicated attackers or identity thieves, that information&#8217;s already out there just waiting to be abused.<\/p>\n<p>Writing this post feels like an exercise in futility. The number one rule in security is that when something is leaked, it&#8217;s leaked. You don&#8217;t bother protecting an access key that was accidentally uploaded to a GitHub repository &#8211; you nuke it, revoke it, and generate a new one. You can&#8217;t unspill a glass of milk any more than you can undivulge a secret &#8211; only we don&#8217;t have that luxury when dealing with our identity. The Social Security Administration doesn&#8217;t believe in issuing new SSNs to replace old ones, and there&#8217;s no changing the name of the street you grew up in &#8211; not when all the credit bureaus already know and won&#8217;t accept anything else as the answer.<\/p>\n<p>Is it honestly too late?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re a developer working on or maintaining a website catering to the general public, chances are you&#8217;ve implemented some form of password reset via security question-and-answer into your site.\u00a0How are you storing the answers to these questions in your &hellip; <a href=\"https:\/\/neosmart.net\/blog\/never-store-answers-to-security-questions-in-plain-text\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[975,1],"tags":[897,11,12],"class_list":["post-3359","post","type-post","status-publish","format-standard","hentry","category-security","category-software","tag-cryptography","tag-programming","tag-security"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-Sb","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=3359"}],"version-history":[{"count":14,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3359\/revisions"}],"predecessor-version":[{"id":4303,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3359\/revisions\/4303"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=3359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=3359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=3359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}