LoginSignup
14

More than 5 years have passed since last update.

Deviseで退会処理を作る時に気をつけたほうがいいこと

Posted at

前置き

DeviseのmodelをUserで設定した場合

ルーティングで

devise_for :users

ユーザー削除するルーティングが自動生成される。

DELETE /users(.:format)               devise/registrations#destroy

そのサイトにXSSがあるケース

任意のJavaScriptが実行できるようになってる場合、以下のコード埋め込んでおけば、ログインしてユーザーにそれを踏ませることでログインしてるユーザーを削除することができてしまう。

$.ajax({type: 'DELETE', url: '/users'})

Devise::RegistrationsController#destroyをオーバーライドしないでユーザー削除処理を独自実装してるケース

単純に削除以外に行いたい処理があって、別のコントローラーに別メソッドで実装してる場合

$.ajax({type: 'DELETE', url: '/users'})

を実行された場合に、デフォルトで生成されたDevise::RegistrationsController#destroyを通ってしまって、独自実装した処理が実行されないで削除されてしまう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14