LoginSignup
0
1

More than 5 years have passed since last update.

メモ:CSRFフィルターを使っているプロジェクトでファイルアップロード処理を書くときの注意

Last updated at Posted at 2016-08-20

自分用メモ

こう書いてはまった

@helper.form(action = routes.Uploader.upload, 'enctype -> "multipart/form-data"){
    <input type="file" name="file">
    @helper.CSRF.formField
}

これはOK

@helper.form(action = routes.Uploader.upload, 'enctype -> "multipart/form-data"){
    @helper.CSRF.formField
    <input type="file" name="file">
}

何故?

Playはリクエストを読み込むときの最初のバッファ(ディフォルト:100KB)にCSRFトークンがないと安全なリクエストと認識しないらしい
前者のコードのようにファイルデータの後ろに@helper.CSRF.formFieldを付けると、
きちんとトークンを送信しているにもかかわらずInvalid CSRF token found in formのようなエラーが出る

0
1
0

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
0
1