At which layer should the site clean the cross-site scripting brought by the third-party embedded card
The cross-site scripting brought by third-party video and image card insertion in the article should be cleaned before publishing or blocked during frontend rendering? The answer is both layers are needed, because embedded cards and author-written text are not the same type of risk, and cannot be cleaned only at one layer.The WordPress of the peer system was released on October 6, 2026, in the security maintenance version, listing a fix for the 'Imgur embed exists cross-site scripting (XSS)' vulnerability.The conclusion can be as follows: The content embedded is generated by an external service, which bypasses the normal field filtering, so simply doing front-end escaping is not enough; and only reviewing before publication cannot prevent the external service from changing the returned content later.A reasonable approach is to divide into three layers - collecting and storing time limits, pre-release review marks, and releasing to the front-end according to the whitelist when outputting.
From which step does the script in the embedded card come in
The input of ordinary rich text is the author of the site itself, while the input of embedded content is from external services. There are three nodes on the chain where scripts may be introduced:
The first step is to retrieve the stage. The site uses the address to request the embedding interface of the other party (such as oEmbed mechanism), and get back a segment of content mark decided by the other party. The character string typed by the author is no longer written into the database.
The second step is the rendering stage. The returned mark often contains scripts, event attributes, and cross-domain resource references; when the browser executes it, the context is the current site, so it can read the page status and submit requests. This is the execution surface of cross-site scripts.
The third step is change. The return of external services today is clean, but it does not mean it will still be so after half a year; the characteristic of the risk of embedded classes is that the content is not under the control of the site, and the review has only been done at the moment of entry, which is equivalent to giving others long-term validity**.
These three steps explain why 'the author did not write the script' does not constitute a security basis: the script does not come from the author, but from the return outside the subject.
Why is it not enough to rely solely on front-end escaping?
The escaping resolves the issue of 'displaying tags as text'. If the entire embedded content is escaped, the card cannot be rendered as a video or image, and the function directly disappears; if embedded tags are allowed, it is equivalent to opening an exception hole in the output layer, and the size of this hole depends on which tags and attributes are allowed.
Common two invalid writing methods: First, make exceptions as 'the entire rich text is not escaped', causing both the author's text and embedded tags to lose protection; second, allow the entire domain, ignoring that the allowed domain may also be misused or return tags with scripts. The correct posture at the output layer is to fall on tags and attributes rather than on the 'this is embedded content' category of source.
What to look at for content review and sensitive word filtering before publishing
Two levels of responsibility are different and easy to mix. Sensitive word filtering and keyword replacement deal with textual violations, which belong to the dimension of content and compliance; content review deals with whether this content can be published, and it can include safety checks such as whether it contains scripts or if the source is controlled.
AnQiCMS has backend capabilities on these two layers: content security settings support sensitive word filtering and keyword replacement, content review; on the security mechanism, built-in JWT authentication, content sensitive word filtering and anti-crawling interference code are integrated to prevent SQL injection and XSS attacks. When embedded content is landed into this mechanism, it is recommended to add a check item for marking in the content review rules (whether there are script tags, event attributes, and cross-domain resources), and maintain it separately from 'sensitive words' because the judgment objects are different.
How to implement the three layers of internal protection, and what is the self-inspection sequence?
Arrange according to the data stream from top to bottom:
Collection and storage layer. AnQiCMS supports content collection and can automatically collect content from other websites; the intake point of this layer is the source and field range - the part with script tags in the collected text should be cleaned according to the whitelist instead of being stored as is. Bulk collection is more likely to bring in external tags in whole segments than manual pasting, and the risk is greater.
Pre-publication layer. Use content review to block content containing uncontrolled tags, sensitive word filtering and keyword replacement to handle text violations. This layer is suitable for 'reject and give a reason' because it does not interrupt the front-end access in the manual process.
Front-end output layer. Allow embedded tags based on the whitelist of tags and attributes, and escape the rest. At the same time, keep the anti-crawling mechanism: AnQiCMS's anti-crawling interference code is used to protect content from being bulk-crawled, which handles another type of problem (content being taken in bulk), and cannot replace script cleaning, but can be configured together with the output layer.
Suggested four-step self-inspection sequence:
- Take an old article with an embedded card, check the original tags stored in the database, and confirm whether the script comes from the stored content or the current external request.
- Use a segment of tags with event attributes for a release test to see if review and filtering block it, as well as at which layer the interception occurs.
- Check the release range of the output layer, confirm that the exception only covers controlled embedded tags, not the entire rich text.
- Check the inventory results of the collection function, confirm that the content collected in bulk has also been cleaned.
Common questions
Can embedded content be banned directly?Yes, this is the most hassle-free option: only allow images and videos to use the site's own material library. The cost is that external videos in articles will have to be replaced with screenshots and link descriptions.
Is it enough to upgrade to the latest version only?The version fixes a specific embedded implementation issue, and the overall risk surface brought by the embedded content is still there: changes in external service returns, new source domains, are all outside the patch coverage range. Layered control still needs to be done.
What layer does adding content security policy (CSP) count as?It is a bottom-line measure outside the output layer, used to limit the source and execution capabilities of scripts. It can reduce the success rate of exploitation, but does not change the fact that 'uncleaned tags have already been stored in the database', and still needs to be cleaned at the entry and publishing layers.
How do you determine that something has already happened?Look for two types of traces: external script addresses that do not belong to any embedded syntax appearing in the main text, and unexpected jumps or pop-ups appearing on the front-end page. After finding them, check back in sequence from collection to storage, before publication, and to the output layer.