11
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

X-Frame-Optionsが非推奨だよって言われたから調べたらそんなことなかった

11
Posted at

調べた経緯

先日、とあるウェブサイトの脆弱性診断の結果を読んだ際に「X-Frame-Optionsは非推奨になっています。CSP frame-ancestoresの利用を検討していください。」と言われました。対応しないと思っていた中で一応MDNのページを調べてみたところ、X-Frame-Optionsに非推奨の項目が見つからず、戸惑ったのが調べた経緯になります。

※2026/2/15日時点
image.png

X-Frame-Optionsとは?

iframe によって別のサイトに埋め込みを可能にするかを設定するHTTPのレスポンスヘッダーです。昔からあるヘッダーで、MDNによると、より詳細に設定できる CSP from-ancestorP ヘッダーを使用することがおすすめされています。
X-Frame-Optionsの設定値としては、DENY, SAMEORIGIN, ALLOW-FROM origin の3つがあります。それぞれの挙動は以下の通りです:

  • DENY: 他サイトへの埋め込みを禁止する
  • SAMEORIGIN: 同じドメインのサイトに対してのみ埋め込みを許可する
  • ALLOW-FROM origin(非推奨):設定したドメインに対して埋め込みを許可する

実際の挙動はMDNのiframeのページで埋め込みをURLを差し替えることで簡単に試すことができます。試しにQiitaサイトへ差し替えると、Qiitaサイトは SAMEORIGIN が設定されているため、MDNのオリジンでは埋め込むことができません。

image.png

非推奨になっていた経緯

現在のMDNを読むと、ALLOW-FROM originという設定値は確かに非推奨ですが、 X-Frame-Options自体が非推奨になっているような記述は見当たりませんでした。しかし他サイトを見ていると確かに過去にはヘッダー自体が非推奨になっていたようです。
GitHubのIssueを探してみたら、以下のように記載がありました。

Currently the spec has the following (emphasis my own):

The X-Frame-Options HTTP response header is a legacy way of controlling whether and how a Document may be loaded inside of a child navigable. It is obsoleted by the frame-ancestors CSP directive, which provides more granular control over the same situations. It was originally defined in HTTP Header Field X-Frame-Options, but the definition and processing model here supersedes that document. [CSP] [RFC7034]

That wording has been taken to mean that X-Frame-Options is deprecated and should be discouraged. That is not the case. However, outside of that, the use of X-Frame-Options is well supported and is unlikely to be removed from browsers (without causing a massive degradation in security for no real benefit). This is especially true as CSP usage considerably trails X-Frame-Options (and only half of those use frame-ancestors!)

どうやら HTML Standardで "legacy"や"obsoleted"という表現が曖昧だった結果、"非推奨"という意味に受け取られてしまい、MDNに反映されてしまったという流れのようです。この方は「X-Frame-Optionsは今もサポートされているし、X-Frame-Optionsから移行するのはセキュリティのデグレを起こす可能性がある」といって反論しています。

復活のX-Frame-Options

現在ではHTML Standardでも表現が変更されて、MDNからも非推奨の文言が削除されました。SAMEORIGINDENY の指定だけで済むようなケースであれば引き続き使用しても問題なさそうです。(脆弱性診断されたシステムSAMEORIGINしか使用していなかったので対応せずに済みそうです。)

さいごに

脆弱性診断で指摘されましたが調べた結果、対応不要で整理できました。今でもネット検索すると「X-Frame-Optionsは非推奨です!」という過去の時代の記事が散見されるので、少しでも不要な移行を少なくする助けになればと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?