没有不值得去解决的问题,也没有不值得去学习的技术!

Implementing HTML iframe Tag Support for All Wildcard Domains Under a Specific Top-Level Domain While Restricting Others

Repeating step 1, it displays normally, meeting expectations

1. In the compatibility mode of the 360 Browser, the prompt “This content cannot be displayed in a frame” appears, as shown in Figure 1.

This content cannot be displayed in a frame

To help protect the security of information entered on this website, the publisher of this content does not allow it to be displayed in a frame.

In the compatibility mode of the 360 Browser, the prompt "This content cannot be displayed in a frame" appears
Figure 1

2. Viewing the web page source code, I determined that this was caused by an iframe and inconsistent URLs, as shown in Figure 2.

Viewing the web page source code, determined that it was caused by an iframe and inconsistent URLs
Figure 2

3. Further analysis revealed that the root cause was the inclusion of X-Frame-Options: SAMEORIGIN in the response headers, as shown in Figure 3.

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/X-Frame-Options Indicates that the page can be displayed in a frame on the same domain (i.e., it can only be displayed under the tv domain).
Further analysis revealed that the root cause was the inclusion of X-Frame-Options: SAMEORIGIN in the response headers
Figure 3

4. Locally, I created a new virtual host, tv.eastobacco.dev, and created a corresponding page, header.html, as shown in Figure 4.

Locally created a new virtual host, tv.eastobacco.dev, and created a corresponding page, header.html
Figure 4

5. I set the response header for tv.eastobacco.dev to X-Frame-Options: SAMEORIGIN, as shown in Figure 5.

Set the response header for tv.eastobacco.dev to X-Frame-Options: SAMEORIGIN
Figure 5

6. Locally, I created a new virtual host, mytv.eastobacco.dev, and created a corresponding page, index.html, as shown in Figure 6.

Locally created a new virtual host, mytv.eastobacco.dev, and created a corresponding page, index.html
Figure 6

7. I reproduced the issue locally: “This content cannot be displayed in a frame”, as shown in Figure 7.

Reproduced locally: This content cannot be displayed in a frame
Figure 7

8. On tv.eastobacco.dev, I created a corresponding page, index.html, which includes header.html from the same domain, as shown in Figure 8.

On tv.eastobacco.dev, created a corresponding page, index.html, which includes header.html from the same domain
Figure 8

9. The prompt “This content cannot be displayed in a frame” no longer appears, as shown in Figure 9.

The prompt "This content cannot be displayed in a frame" no longer appears
Figure 9

10. Therefore, it can be determined that the primary function of the response header X-Frame-Options: SAMEORIGIN is to allow header.html to be displayed only under the tv domain. However, the current requirement is to allow it to be displayed under all second-level domains. I set the response header to X-Frame-Options: frame-ancestors http://mytv.eastobacco.dev, as shown in Figure 10.
# add_header X-Frame-Options SAMEORIGIN;
add_header X-Frame-Options “Allow-From http://mytv.eastobacco.dev”;
add_header X-Frame-Options “Allow-From http://tv.eastobacco.dev”;

It can be determined that the primary function of the response header X-Frame-Options: SAMEORIGIN is to allow header.html to be displayed only under the tv domain
Figure 10

11. Repeating step 7, I found that header.html can be displayed under the mytv domain, as shown in Figure 11.

Repeating step 7, found that header.html can be displayed under the mytv domain
Figure 11

12. Repeating step 9, I found that header.html cannot be displayed under the tv domain, which does not meet expectations, as shown in Figure 12.

Repeating step 9, found that header.html cannot be displayed under the tv domain, which does not meet expectations
Figure 12

13. I reset the response header to X-Frame-Options: frame-ancestors http://*.eastobacco.dev, as shown in Figure 13.
add_header X-Frame-Options “Allow-From http://*.eastobacco.dev”;

Reset the response header to X-Frame-Options: frame-ancestors http://*.eastobacco.dev
Figure 13

14. Repeating step 7, I found that header.html cannot be displayed under the mytv domain, as shown in Figure 14.

Repeating step 7, found that header.html cannot be displayed under the mytv domain
Figure 14

15. I reset the response header to X-Frame-Options: frame-ancestors http://mytv.eastobacco.dev, http://tv.eastobacco.dev, as shown in Figure 15.
add_header X-Frame-Options “Allow-From http://mytv.eastobacco.dev, http://tv.eastobacco.dev”;

Reset the response header to X-Frame-Options: frame-ancestors http://mytv.eastobacco.dev, http://tv.eastobacco.dev
Figure 15

16. Repeating step 7, I found that header.html cannot be displayed under the mytv domain, as shown in Figure 16.

Repeating step 7, found that header.html cannot be displayed under the mytv domain
Figure 16

17. I reset the response header to X-Frame-Options: frame-ancestors http://mytv.eastobacco.dev; http://tv.eastobacco.dev, as shown in Figure 17.
add_header X-Frame-Options “Allow-From http://mytv.eastobacco.dev; http://tv.eastobacco.dev”;

Reset the response header to X-Frame-Options: frame-ancestors http://mytv.eastobacco.dev; http://tv.eastobacco.dev
Figure 17

18. Repeating step 7, I found that header.html cannot be displayed under the mytv domain, as shown in Figure 18.

Repeating step 7, found that header.html cannot be displayed under the mytv domain
Figure 18

19. Referring to the URL: https://blogs.msdn.microsoft.com/ieinternals/2010/03/30/combating-clickjacking-with-x-frame-options/ , Allow-From does not support wildcards or a list of multiple sources, as shown in Figure 19.

Referring to the URL: https://blogs.msdn.microsoft.com/ieinternals/2010/03/30/combating-clickjacking-with-x-frame-options/ , Allow-From does not support wildcards or a list of multiple sources
Figure 19

20. Referring to the URL: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy__by_cnvoid , I reset the response header to Content-Security-Policy: frame-ancestors http://*.eastobacco.dev, as shown in Figure 20.
add_header Content-Security-Policy “frame-ancestors http://*.eastobacco.dev”;

Referring to the URL: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy__by_cnvoid , reset the response header to Content-Security-Policy: frame-ancestors http://*.eastobacco.dev
Figure 20

21. Repeating step 7, I found that header.html can be displayed under the mytv domain, which meets expectations, as shown in Figure 21.

Repeating step 7, found that header.html can be displayed under the mytv domain, meeting expectations
Figure 21

22. Repeating step 9, I found that header.html can be displayed under the tv domain, which meets expectations, as shown in Figure 22.

Repeating step 9, found that header.html can be displayed under the tv domain, meeting expectations
Figure 22

23. Including header.html from tv under another top-level domain still succeeds, which does not meet expectations. Because compatibility mode does not support Content-Security-Policy, I decided to abandon the display restriction in compatibility mode and allow all domains to include header.html from tv, as shown in Figure 23.

Including header.html from tv under another top-level domain still succeeds, which does not meet expectations. Because compatibility mode does not support Content-Security-Policy, decided to abandon the display restriction in compatibility mode and allow all domains to include header.html from tv
Figure 23

24. Enabling speed mode and repeating step 7, I found that header.html can be displayed under the mytv domain, which meets expectations, as shown in Figure 24.

Enabling speed mode and repeating step 7, found that header.html can be displayed under the mytv domain, meeting expectations
Figure 24

25. Enabling speed mode and repeating step 9, I found that header.html can be displayed under the tv domain, which meets expectations, as shown in Figure 25.

Enabling speed mode and repeating step 9, found that header.html can be displayed under the tv domain, meeting expectations
Figure 25

26. Including header.html from tv under another top-level domain, I found that header.html cannot be displayed, which meets expectations, as shown in Figure 26.

Including header.html from tv under another top-level domain, found that header.html cannot be displayed, meeting expectations
Figure 26

27. Repeating step 1, it displays normally, which meets expectations, as shown in Figure 27.

Repeating step 1, it displays normally, meeting expectations
Figure 27

28. Compatibility mode is essentially the IE browser, and speed mode is essentially the Chrome browser. By setting only the Content-Security-Policy response header, security settings are forfeited in the IE browser. This ensures that across all browsers, http://*.eastobacco.dev can include header.html from tv, while other top-level domains cannot.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系