1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初心者向け】CSRFとは

Last updated at Posted at 2021-08-22

はじめに

今回は、CSRFについて書いていきます!!
現在Laravel学習中のため、Laravelでの記述方法についてもさらっと言及します。

CSRFとは

CSRF(クロスサイトリクエストフォージェリ)とは、Webアプリの脆弱性を利用したサイバー攻撃の一種で、以下のような流れで攻撃してきます。

  1. 攻撃者(悪い人)が罠となるサイトを用意する
  2. あるWebアプリにログインしているユーザーがそのサイトにアクセスする
  3. サイトに仕掛けられた罠リンク(URL)をクリックすると、ユーザーの意図しないリクエストがWebアプリに送信されてしまう

CSRF対策

サーバーサイドでしか分からないランダムな文字列(トークン)を生成し、そのトークンをinputタグのhidden要素でformに埋め込み、送信されたトークンと保存されているトークンが一致するかを確認することで、正しいリクエストであるかどうかチェックする、といったやり方でCSRF対策を行います。
Laravelでは、formタグの下に以下のように記述するだけで、ランダムな文字列を勝手に埋め込んでくれます。

{{ csrf_field() }}

これは

<input type="hidden" name="_token" value="{{ csrf_token() }}" />

と同様の意味であり、Laravel

@csrf

と書いてもOKです。

おわりに

世の中には悪い人がたくさんいるから気をつけなければいけませんね。。。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?