악의적 인 사용자가 내 사이트에 등록 할 때 추가 매개 변수를 추가 할 가능성이 있습니다. 나는 Rails 3.2.8과 Devise 2.1.2를 사용하고있다. 나는 admin
속성을 가진 클래스 User
이보안 - Devise로 사용자를 생성 할 때 필터 속성
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :trackable,
:validatable, :token_authenticatable, :lockable
end
schema.rb
create_table "users", :force => true do |t|
t.boolean "admin"
t.string "email", :null => false
t.string "encrypted_password", :default => "", :null => false
# other devise columns are not relevant for the question...
end
나는 사용자의 등록을 위해 제공 Devise::RegistrationsController
을 사용하고 있습니다 , 사용자 정의보기는 email
및 password
:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="form_line">
<%= f.label :email, 'Email' %>
<%= f.email_field :email %>
</div>
<div class="form_line">
<%= f.label :password, 'Password' %>
<%= f.password_field :password %>
</div>
<div class="form_line">
<%= f.label :password_confirmation, 'Password confirmation' %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Register", class: 'button' %>
</div>
<% end %>
내가 완벽하게 작동하지만, 악의적 인 사용자가 POST 요청의 값 true
와 매개 변수 admin
을 추가하는 경우는, 사용자는 관리자 권한으로 작성됩니다.
Started POST "/users" for 127.0.0.1 at 2012-09-10 18:46:15 +0200
Processing by RegistrationsController#create as HTML
Parameters: { "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "admin"=>"true" }
내 사이트의 보안 취약점입니다. 사용자가 등록 (또는 프로필을 업데이트 할 때 동일한 문제가 발생할 것임) 할 때 추가 매개 변수를 무시하도록 Devise를 구성 할 수 있습니까 (이메일과 비밀번호 만 필요함)? 가능하지 않다면 다른 해결책이 있습니까?
고맙습니다. 작동합니다. 나는'attr_accessible'을 사용하고 Ruby on Rails 보안 가이드에서 제안한'config.active_record.whitelist_attributes = true' 옵션을 사용하기로했습니다. http://guides.rubyonrails.org/security.html#mass-assignment – Baldrick