LoginSignup
27
12

More than 3 years have passed since last update.

Content-TypeとX-Content-Type-Options: nosniff

Last updated at Posted at 2019-11-28

Content-Typeとは?

  • HTTPレスポンスヘッダに付与する属性。
  • 返却するファイル形式が何なのか?、を知らせる目的がある。
# Content-Typeの例
text/plain → テキストファイル  
text/html  → HTMLファイル  
application/json → JSONファイル
application/pdf → PDFファイル  

X-Content-Type-Options:nosniffとは?

  • この属性を付与するとファイルの内容をContent-Type属性から判断してねとお願いできる。
  • IEではContent-Typeを指定していても、htmlと勝手に判断してJavascriptが実行されてしまうことがあるためMSが実装した。
  • IE以外のブラウザでも使える属性である。

なんのために使うの?

  • ファイルダウンロード時にファイル形式をブラウザに誤認させてJavascriptを実行させてしまうような攻撃(XSS攻撃)を防ぐことができる。
27
12
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
27
12