The browser will mark whether the request is from this site or an external site, and how the server can prevent cross-site requests based on this.

📅 October 12, 2026 👁️ 23

The browser indicates whether the request is from the same site or an external site, the server blocks cross-site request forgery based on this, relying on several source markers that cannot be changed by the front end. The specification leaves four positions for this set of headers, with the values automatically filled in by the browser before sending the request. The web script cannot create new fields with the same name, nor can it change existing content, so the server can use it as a relatively可信 signal to judge whether the request is from its own page or borrowed by another site to carry login state.

Who added this set of request headers?

This set of headers is called fetch metadata request headers, which is also known as the pull metadata request headers, and the browser writes it for you before actually sending out the request.The four members are Sec-Fetch-Site (site relationship), Sec-Fetch-Mode (initiation mode), Sec-Fetch-User (whether initiated by the user), Sec-Fetch-Dest (target type).The specifications classify them into the category of forbidden request headers, meaning that web pages cannot customize headers with the same name, and the method of forging a source marker has been blocked.

There is also a boundary that is easy to ignore, which is the trusted address: the browser only attaches this set of headers to requests deemed trustworthy, and sites running on plaintext addresses do not receive them. Therefore, the signals at the server end actually have two states, one is explicitly written as cross-site, and the other is completely without this set of headers, and the two need to be handled separately; missing cannot be taken as a reason to allow.

What do the four values mean?

Sec-Fetch-Site specifies the relationship between the initiator and the recipient, divided into four types: same-origin, same-site, cross-site, and no initiator. The meaning and handling are listed in the table below. Same-origin requires that the protocol, host, and port be completely consistent, while same-site refers to the host name being the same or a subdomain.

Value The relationship indicated Typical scenarios Common handling on the server
same-origin (same origin) The protocol, host, and port are completely consistent Interface calls initiated from the page on this site Pass according to normal business logic
same-site (same site) The host name is the same or a subdomain The main page calls the interface subdomain Read and write are separated, relaxed according to the nature of the interface
cross-site (cross-site) Both parties have no site relationship Request sent from an external site with a login state Write operation is directly rejected
none (no initiator) Cannot see the source page Direct access from the address bar, bookmarks open Only place browser navigation requests

These three headers answer other aspects. Sec-Fetch-Mode indicates the mode in which the request is issued, whether it is page navigation, embedded resource, or interface call; Sec-Fetch-Dest indicates what type of target the request wants to fall on, whether it is a document, script, or data; Sec-Fetch-User only appears in a few requests triggered directly by user actions, indicating that this is a jump caused by a user's action. These items combined can distinguish between the interface calls of this site and the automatic submission of external pages.

How to write an access strategy based on context on the server?

A feasible way is to declare for each type of interface which contexts it accepts. Interfaces with login status usually only accept requests from the same origin and the same station. Read requests according to business needs can be relaxed, and requests with cross-site tags should be directly rejected without going around to verify tokens, because the source relationship itself has already been established. For header missing, it needs to be set up separately according to the nature of the interface: pages that can be opened directly in the browser can accept missing headers, and pure interface paths can be rejected to avoid interpreting the absence of signals as beneficial signals.

This set of headers has an easily overlooked impact, which is caching. Since the passage is determined by the context, the same address may get different results in different contexts, and the cache must also distinguish these contexts, otherwise, the rejected response may be reused on normal requests, and vice versa. A safe approach is to let the interface for passing according to the context carry the source information into the cache key, or simply exclude such interfaces from the shared cache.

Is it complementary to the write operation confirmation rather than a substitute?

This marking answers who initiated this request, and does not answer whether the initiator has the permission to do this. It can prevent others from secretly sending a write operation using the login state, but it cannot prevent a legitimate user from clicking an inappropriate button on their own page, so it is just a face-saving measure and cannot replace the confirmation before writing.

Within the AI interface side (MCP) of the station, there is round-level approval for write operations, which will merge a batch of changes into one confirmation. The changes will only take effect after the person nods in this round. The two layers of objects do not overlap: the source tag manages who initiated the request, and the round-level approval manages whether the person needs to nod for this change. The former filters out external sources at the service endpoint, and the latter gathers batch changes into the same confirmation point on the agent side, and no one can replace each other.

Common questions

Can this group of headers block all scenarios of cross-site request forgery?Cannot. It only handles the part that can be determined by the browser, the headers are never received at the plaintext address, and constraints other than the same-domain subdomain are needed. The permission judgment and confirmation before write operation still need to be done together in the business layer.

How should we judge if there is no such header in the request?First, check if the service address is trustworthy, the browser will not send it under plaintext address. When the client directly connects outside the browser, this header is naturally missing, and we can only return to the original authorization and confirmation mechanism, treating the missing as unavailable signal rather than as an approval.

Does a cross-site marked request must have a problem?It is not necessarily. Normal navigation caused by third-party embedding, page jump from partner pages, and external links all carry cross-site tags. It is a safe practice to use it only for rejecting write operations, and read requests and navigation should be judged again by mode and target type.

Related articles

After the user logs out, old data still remains in the browser, how to require the response header to be cleared.

When logging out, the cache and local storage left in the browser will not disappear automatically. The Clear-Site-Data response header is a clear signal for the client, which can clear cache, credentials, storage, and execution contexts item by item, and it only takes effect in encrypted connections: credentials are cleared for the entire registration domain, and storage is only cleared for the current source. The login status within the site is carried by JWT, and the local data at this client layer relies on it to complete the cleanup. It is especially worth adding on public devices.

2026-10-12

When embedding third-party videos on a page, what authorization is used for iframe's capability to pass through?

The page embeds third-party videos with two levels of restrictions: source domain names are allowed to pass based on the whitelist, and capabilities such as camera, location, and automatic playback are authorized in the minimum set item by item. In the update records of PbootCMS V3.2.18, the default source strategy for trusted video domains is retained, and the token whitelist is set for the allow attribute. This article explains why the embedded frame carries scripts and media capabilities at the same time, how to differentiate between precise domain and subdomain wildcard, and why the release and authorization should be configured separately.

2026-10-12

Why does the login lock and blacklist on the website behind the proxy recognize the source address incorrectly?

When a website is behind a reverse proxy, the program often reads the connection source as the proxy address, and the content of the forwarding header is controlled by the client. Confusing the two layers can lead to login locking and incorrect objects in the blacklist. PbootCMS has fixed the issue of unconditional trust in the source forwarding header in the update records of V3.2.25. This article discusses the origin of the two layers of addresses, the practice of taking the most right可信 value in the trusted link, and which layer to use for throttling and locking.

2026-10-12

How should the deletion range be verified for the batch deletion interface of background messages according to parameter concatenation?

If the batch deletion of background messages directly concatenates the number list sent from the front-end into the deletion conditions, it may delete out-of-range content in one request. PbootCMS has fixed this kind of parameter injection in the update records of V3.2.18, strictly checking the id list to be deleted. This article explains why the batch interface has expanded the impact range, how to verify the type and existence of the number, why the deletion range needs to be recalculated on the server side, and what the recycle bin can accommodate after accidental deletion.

2026-10-12

When the content does not change, the server only returns a status code, and conditional requests rely on which identifier to judge.

The cache expiration does not mean that you need to download the entire content again. ETag is the identifier of a version of the resource, and a new value must be generated when the resource content changes; the client uses If-None-Match to return the old value during a revisit, and if the server compares it and finds it consistent, it will only return a status code without the body. This article talks about what this identifier represents, the difference between strong verification and weak verification, why the weak identifier can affect segmented requests, and how sites with frequently changing content can use it to reduce duplicate transmission.

2026-10-12

Why does the server prefer to return an early status code when it receives a request before the connection is fully established?

The early data of TLS allows the client to send the request in the first round trip, saving the next handshake wait time, at the cost of this type of request being at risk of replay. 425 Too Early indicates that the server is unwilling to take the risk of processing a potentially replayed request and prefers to reject first. This article discusses what the early data saves, where the risk falls on what type of request, why idempotent and non-idempotent need to be treated separately, and what trade-offs a service with Go as the technology stack needs to make at this level.

2026-10-12

When your own image is directly referenced by other websites, which response header decides whether to allow or not.

When your own image is directly referenced by other websites, it is the resource party that decides whether to allow it, not the referencing party. The Cross-Origin-Resource-Policy response header is set by the referenced resource, indicating which sources can load it, with values divided into three levels: same-origin, same-site, and cross-origin. The default is to block cross-site requests without cors. This article discusses which level each tier allows, whether it is on the same end as the initiating party, and whether images and fonts should be released separately.

2026-10-12

The server defaults to writing the program version into the response header and error page. Should this level of fingerprint be removed?

Most web servers default to writing the program version into the Server response header and error pages, the Nginx server_tokens directive is set to on by default, after it is turned off, the two places no longer contain version information. Removing this fingerprint can reduce the convenience of version collision, but it only reduces information exposure and does not constitute a defense. This article discusses where the version number leaks out and what remains after it is turned off, as well as where to make changes at each layer for different deployment methods such as Baota and Docker.

2026-10-12