When a page is embedded in an iframe of another website, where should the intercept be written in the response header?

📅 October 10, 2026 👁️ 31

When a page is embedded by another website using an iframe, intercept the script written in the response header, not in a script segment in the page. The two available options are: X-Frame-Options and the frame-ancestors directive in the content security policy.The former only has two reliable values, DENY and SAMEORIGIN, while the latter can express 'which sources are allowed to embed'. If you just need 'no one can embed' or 'only same-origin embedding is allowed', the former is sufficient.Once it is necessary to allow a specific partner, frame-ancestors must be used.

The problem caused by embedding the page is not a display issue

The risk of being nested lies in the fact that the user sees the interface of our site, but the operation is arranged in someone else's page. The cooperative promotion pages, aggregation sites, and even pages disguised as normal sites can put login boxes, comment forms into an invisible frame, and lead the user's click to the real function of our site. This kind of problem is generally called clickjacking, and its conditions are very simple - the page is allowed to be embedded, and there are interactive functions on the page.

So, the decision of whether to block or not is not based on whether anyone is embedded, but on whether there are interactive actions on this page.

The applicable scope of each of the two response headers.

The two reliable values of X-Frame-Options: DENY means the document cannot be loaded in any frame, regardless of same origin or cross-origin; SAMEORIGIN means that embedding is only allowed if all上级 frames are of the same origin with this page. The writing style of ALLOW-FROM specifying the source has been deprecated, and the specification document clearly states that modern browsers will completely ignore the response header containing this instruction - that is to say, once ALLOW-FROM is written, the entire intercept is equivalent to not being added, rather than degraded to only allowing that source.

To express 'Allow embedding from some sources', you need to use the frame-ancestors directive in the content security policy header, which defines 'which parent pages can embed this page using frame, iframe, object, or embed'. The document also hints that when a more comprehensive choice than X-Frame-Options is needed, frame-ancestors should be used instead.

Embedding strategy table by page type

Page Type Suggested tier Reason
Background and login-related pages DENY Only direct access is allowed, any nesting is unreasonable
Interactive form page for messages, comments, etc. DENY or SAMEORIGIN Forms are most easily borrowed in nested states.
Product and business handling page. SAMEORIGIN Allow internal frames of the site, deny external sites.
Content pages that need to be distributed externally. frame-ancestors specify the origin. Allow partners to embed, while tightening the scope of origins.

A common mistake in writing policies is 'one-size-fits-all DENY' which also closes legitimate distribution scenarios, or vice versa, write ALLOW-FROM for convenience but think it has already cleared the whitelist.

The existing injection protection in the station does not reach this layer

Content sites usually consider injection risks as basic items: AnQiCMS内置JWT authentication, content sensitive word filtering and anti-crawling interference code, used to prevent SQL injection and XSS attacks; comments and reviews also have content review and sensitive word filtering before being published. These two layers handle whether the submitted content can be executed and can be published.

The issue of nesting is the opposite: the content itself is clean, but the page appears in someone else's frame, and the user and context are no longer controllable. Therefore, it cannot be solved by sensitive word filtering or content review, but only by the source declaration strategy in the response header. Conversely, if the site adds headers at the reverse proxy or server layer, it is necessary to confirm whether the three types of pages (background, form pages, distribution pages) use the same configuration - classifying by path is more cost-effective than one configuration for the entire site.

Common questions

Question: Is it feasible to add a script to the top of the page to prohibit nesting?Answer: It is not feasible as a defense line. The script needs to be executed to take effect, while the nested page can first lay out the outer styles and occlusion; the declaration must take effect as soon as the response reaches the browser, that is, written in the response header.

Question: Can two response headers be written at the same time?Answer: Yes. During the transition period, it is a common practice to issue them simultaneously, using X-Frame-Options to cover the old environments that do not support fine-grained instructions, and using frame-ancestors to express the real strategy; but it is necessary to confirm that the semantics of both do not conflict, to avoid one DENY and one allowing.

Ask: How can you judge if your embedding function fails after adding the interceptor?First, see which layer fails: The same-origin page embedded in the site page should be exempt from SAMEORIGIN; if a third-party component puts content into the frame for display, it belongs to the distribution scenario, and it should be tightened by origin instead of being turned off all at once.

Related articles

There is a paper saying that GEO can increase visibility by about 40%, how can this number be reviewed on the site?

The widely cited limit statement in the original paper on generative engine optimization is: Under the benchmark test environment, the GEO method can increase visibility by about 40%, while the author explicitly states that the effects differ greatly across different fields. It is a common misreading to take this number as the expected return for your own site. This paper analyzes the experimental settings of this number and provides a set of in-site review paths: fixed baseline and question set, record the brand and page landing points in the answers, and then explain the model description files and collection modules that can be配合 with the upper-level site.

2026-10-10

If one of the three sites managed by the same backend is messed up in style, check which layer first.

When there is a style mess in only one site in the group, first divide the shape incorrectly and then decide which layer to check: large area images or missing style files, navigation position deviation, which is often related to the static resources and configuration of each site; only when there is a misalignment of the whole block structure or deformation of a certain column, check the template layer. This article gives the minimum action for checking per site and explains the boundary of templates, navigation, and backup under multiple sites, to avoid one change affecting the other two sites.

2026-10-10

After setting the image to lazy loading, the first screen will be faster, but will the content caught be less?

The purpose of lazy loading is to mark resources as non-critical and fetch them only when needed, thereby shortening the critical rendering path; the slow-down of the first screen is more due to rendering blocking resources, not much related to images. After setting lazy loading for images, the content written in the document remains unchanged, the change occurs in whether to retrieve it during the first rendering. This article gives a tiered approach according to the type of resources and explains the connection with the automatic title matching images and the media addresses in the sitemap.

2026-10-10

After AI crawling starts charging per item, content sites need to confirm which few things

The per-crawl charging control mechanism has already been provided in the document: the site sets the price for crawling, and if the payment proof is not provided during automatic access, a response code requiring payment will be received. It is currently in closed beta, and the rates are configured according to the domain area hierarchy instead of specific directory paths. The content side needs to confirm three things under this trend: how to express the exclusion rules, what was written in the site description file for large models, and whether anti-crawling and authorization are contradictory.

2026-10-10

The server push of HTTP/2 has been removed by most browsers, what does the first screen rely on to fetch resources in advance?

The official goal of HTTP/2 is to reduce latency and head-of-line blocking by using full request and response multiplexing, and to use HPACK to efficiently compress header fields; due to the difficulty of implementation in practice, server push introduced in the same version has been removed from most mainstream browser engines, and alternative means are the rel=preload declaration in the page and the 103 Early Hints status code. This article explains to what extent these two methods can be preloaded, how the list of resources on the first screen should be arranged, and what changes need to be made on the program side and the gateway side to avoid relying on a mechanism that has been removed.

2026-10-10

The information disclosure announcement of the password-free login module is only rated medium, what kind of content is leaked?

An announcement for the two-factor authentication and password-free login module, categorized as information leakage, rated as moderately critical, with a risk score of twelve to twenty-five. The confidentiality in the dimension string is noted as partially affected, integrity is zero, and the exploitation conditions are marked as theoretical. This article analyzes the 'moderate' from which dimensions are composed one by one, explaining that it should not be inferred specifically from leakage announcements without public details, and gives the order of closing the login state and content visibility of the self-owned site.

2026-10-10

The entry file of the peer CMS has been replaced with a tampering script, what can be read from the public issue list?

A public issue record documented two changes: The entry startup file was tampered with on June 23, 2026, and the homepage file was tampered with the next day. The issue was created on June 25 and closed on July 8. The script written first determines if the visitor came from a search engine, and then outputs the content retrieved from the external address. This article lists the order of file integrity verification, recovery paths, and verification actions after the changes.

2026-10-10

The editor module issued multiple unauthorized announcements, what standard does the backend role permission collect according to?

The access bypass公告 of the editor module is rated as moderately critical, with a risk score of thirteen to twenty-five, requiring basic attack conditions and user permission requirements. This article analyzes the reading method of the unauthorized access issues based on the announcement fields, dividing the intake into action layers: editing, submission, and publication, respectively assigned to different user groups, first confirming whether the module is enabled and then narrowing the executable range, and using content review and sensitive word filtering to maintain the last confirmation before publication.

2026-10-10