In a multi-site operation environment, ensuring the content security and display consistency of all sites is one of the core tasks.Especially the filtering rules for HTML content, which are directly related to user experience, information security, and even search engine optimization.The Anqi CMS is a feature-rich system that provides us with flexible tools to manage these rules.To implement a unified configuration of HTML content filtering rules across multiple sites, we need to combine the built-in functions of the system and operational strategies to achieve the goal.

First, understand the basic settings of Anqi CMS in content processing is crucial.Each independent Anqi CMS site has its own "Content Settings" module, you can find it under the "Backend Settings" menu in the backend.This module provides some important options that can preliminarily define the HTML processing method of the site content.For example, the option 'Automatically filter external links' can help you control whether external links are allowed in the content and whether to add linksrel="nofollow"Property, this is very useful for SEO and preventing bad link introductions.At the same time, the setting of whether to download remote images also indirectly affects the embedded HTML image tags in the content. If you choose to download, the external images will be localized, reducing dependence on third-party resources and improving loading speed and security.In addition, settings such as automatic image compression, Webp format conversion, and thumbnail processing methods also constitute the basic filtering and optimization rules for content display.

However, it should be noted that these "content settings" are independently configured for each site.There is no central switch for 'one-click global application' in a multi-site environment to manage these rules across all sites.Therefore, to achieve 'unified configuration', we need to adopt a systematic strategy.

A high-efficiency strategy is to clearly define a set of standard 'content settings' specifications when planning a new security CMS site.When creating a new site or auditing an existing site, always configure its 'Content Settings' module strictly according to this specification.This requires us to invest some effort in the initial setup to ensure that all sites maintain consistent basic content filtering rules.For example, you can decide to automatically filter external links, download remote images, and unify the compression size and thumbnail processing method of images for all sites to ensure consistency in brand image and user experience.

In addition to the site-level "Content Settings", the powerful template engine of AnQi CMS also provides us with fine control over HTML filtering at the content output level.During the template creation process, we can use built-in filters to further purify and standardize HTML content. For example,striptagsThe filter can remove all HTML tags from HTML content, leaving only plain text, which is very useful for certain scenarios where only abstracts or plain text content is needed.removetagsThe filter is more flexible, you can specify which HTML tags to remove from the content, such as removing<script>/<iframe>Tags that may pose potential security risks, or remove redundant style tags to keep the content HTML concise.

For example, in your template file (such asdetail.htmlorlist.htmlIn the case of displaying document content, you can use these filters:

{# 假设archiveContent变量包含了HTML内容 #}
{# 移除所有HTML标签,只保留纯文本 #}
<div>{{ archiveContent|striptags }}</div>

{# 移除内容中的<script>和<iframe>标签,同时确保其余HTML内容被安全地解析 #}
<div>{{ archiveContent|removetags:"script,iframe"|safe }}</div>

{# 结合使用,先移除不需要的标签,再确保剩余HTML的安全显示 #}
<div>{{ archiveContent|removetags:"font,span"|safe }}</div>

Please pay special attention.safeThe use of filters. The Anqi CMS template engine defaults to escaping HTML content to prevent XSS attacks. If you useremovetagsAfter the filter is processed, in order for the remaining HTML tags to be normally parsed by the browser, it must be used|safeExplicitly inform the system that this content is safe and does not require escaping. If the content is used directly without proper filtering,|safeit may pose a security risk. Therefore, it is recommended that youremovetagsUse or after cleaning up the content|safe.

To unify this level of template filtering across multiple site environments, **the practice is to establish a set of shared basic templates or template components. For example, you can define apartial/content_display.htmlA segment that contains the universal filtering logic of all HTML content output. All specific templates of all sites are used to display article content when{% include "partial/content_display.html" with content=archive.Content %}In this way, once you need to adjust the HTML filtering rules, you only need to modify this centralized template fragment, and all sites that refer to it can take effect immediately, thereby realizing the unified management of filtering rules.

Finally, regular audits and content review mechanisms are also indispensable.Even with unified configurations and templates, human errors or new security vulnerabilities may still occur.Establish a content review process, conduct spot checks on published content, and regularly review the "content settings" and template usage of each site, providing multiple safeguards for a multi-site environment.

By implementing the above strategy, that is, unifying the initial configuration of 'Content Settings' at the site level, and achieving unified output control through standardized filters and template components at the template level, you can effectively and flexibly manage and unify the HTML content filtering rules in the multi-site environment of Anqi CMS, ensuring that each site maintains a high degree of consistency in terms of security and content presentation.


Frequently Asked Questions (FAQ)

Q1: Can the "Content Settings" "Automatic Link Filtering" feature in AnQi CMS completely block all malicious HTML code?

A1: The "Auto-filter External Links" feature is mainly aimed at processing external links that appear in the content (for example, blocking display or addingnofollowProperties), to control the direction of the link and SEO impact. It cannot completely prevent all types of malicious HTML code, such as embedded<script>tags,<iframe>Or other suspicious HTML structures. To comprehensively prevent such risks, you also need to use the templates in conjunction withstriptagsorremovetagsfilters and use them cautiouslysafefilters to ensure the safety of the content output.

Q2: If my site template does not use any HTML filtering or escaping tags when displaying article content, how will the content be displayed?

A2: The template engine of Anqicms defaults to escaping HTML content output to the page. This means that if your article content contains<p>Hello</p>Such HTML tags can be directly passed through in the template{{ archive.Content }}They will be escaped when output&lt;p&gt;Hello&lt;/p&gt;The user sees the literal HTML code, not the effect after it is parsed by the browser. If you want the HTML content to be normally parsed, you need to explicitly