當用戶點擊忘記的密碼時,它會將其帶到忘記的密碼頁面,其中有一個字段供他們輸入其電子郵件地址。如果他們的電子郵件地址在數據庫中,則一切都很好,但如果電子郵件地址不存在於數據庫中,它只會重定向到同一頁面,但不會顯示錯誤消息。設計 - 如果電子郵件不存在於分區中,則忘記密碼不會顯示錯誤消息
如何獲取錯誤消息?
/view/devise/passwords/new.html.erb
...
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<h1>Reset Password</h1>
<div class="login-fields">
<p>Instructions on resetting your password will be emailed to you.</p>
<%= render :partial => '/shared/messages' %>
<div class="field">
<%= f.label :email %>
<%= f.email_field :email, :placeholder => 'Email', :class => 'login username-field' %>
</div> <!-- /field -->
</div> <!-- /login-fields -->
<div class="login-actions">
<%= content_tag(:button, :type=>:submit, :class => "button btn btn-secondary btn-large") do %>
Send me reset password instructions
<% end %>
</div> <!-- .actions -->
<div class="login-social">
<%= render "devise/shared/links" %>
</div>
<% end %>
...
/views/shared/_messages.html.erb
<% if alert || flash[:alert] || flash[:error] %>
<div class="alert alert-error">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Error!</h4>
<%= alert %>
<%= flash[:error] %>
</div>
<% end %>
<% if flash[:success] || notice || flash[:notice]%>
<div class="alert alert-success">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Success!</h4>
<%= flash[:success] %>
<%= notice %>
</div>
<% end %>
是否有任何HTML被渲染?即它顯示「錯誤!」標題但不是實際的消息?或者它什麼都沒有顯示? – Flambino
請注意,這是將信息暴露給潛在的攻擊者。有人試圖猜測系統中有效的電子郵件地址,可以根據他們是否收到錯誤消息來判斷某人是否擁有賬戶。如果[您的登錄表單顯示用戶名或密碼不正確],則顯示的信息類似(https://www.informit.com/articles/article.aspx?p=1076787&seqNum=6)。您需要平衡安全性和針對您的特定應用程序的可用性。 – carols10cents