The template tag outputs the opening tag of the script, how can the content be executed as code?

📅 2026-10-11 👁️ 16

The site content is executed as code in just one step: The template engine interprets a segment of opening tags in the received text as code. PbootCMS has fixed such an issue in its update records - a risk related to the output script tag of the site, while also enhancing the filtering of tag page parameters. The two fixes correspond to two levels of closure: the output position needs to be filtered, and the parameters entering the tag also need to be verified. Any content allowed to flow into the template or script engine system from the backend editor faces the same boundary.

The step where data becomes code

The template file already contains code: tags, conditions, and loops are instructions for the engine. Danger occurs when 'data output' is treated as 'code input'——the engine directly pastes user可控 text into the source code to be interpreted. Once this text contains starting tags recognized by the engine, the content enters the instruction stream. From this moment on, it is no longer displayed data but part of the execution logic; the same string is just text at the plain text output and behavior at the interpreter's entry. Therefore, the answer to 'how content can be executed' is: it is placed in a position where it can be interpreted.

Why do we need to filter the tag position

The output position of the site tag is very special: it often appears at the outermost layer of template assembly. Some implementations even compile the tag parameters directly into the template source code. Three entrances continuously supply content: background editor input, form and comment submission, and externally collected articles. If any content is marked with a start tag and the exit is not filtered, the problem will explode during rendering. Therefore, both 'enhancing the tag page parameter filtering' and 'the output position no longer generates open tags' must be done at the same time in the repair plan: narrow the shape of controllable input on the parameter side, and ensure that even if it leaks in, it will not be interpreted on the output side.

Escape should be separated by output context

The same text goes in different directions, the dangerous characters are different, and escaping cannot be replaced by a universal cleaning set:

Output context Form of dangerous characters The correct method
HTML body Tag start symbol and entity Escape according to HTML entity
Property value Quotation mark separators and angle brackets Special escape for attribute context and add quotes
Script string Quotation marks, backslashes, and end markers Escape according to script syntax or go through the data interface
URL parameters Reserved characters and encoding injection Percent encoding and verify protocol header

The principle is that the consumer's interpretation of the syntax determines the escaping method; the practice of 'first deleting all special characters globally and then everywhere' will delete legitimate content and also miss cultural attacks.

The earlier the filtering, the more convenient it is

When layering the mouth, the priority is from front to back: during the entry and import stage, sensitive word filtering and keyword replacement are performed to block obvious anomalies before they are stored; the content security settings of AnQiCMS are responsible for this section.Contextual escaping in the rendering phase is the right solution to prevent cross-site scripting; the interface and authentication layer contain the attack surface of injection attacks, and the protection against SQL injection and XSS attacks built into AnQiCMS belongs to this layer.The earlier it is, the more you can keep the problem in the form of data, not letting it get close to the interpreter; the later it is, the more you have to rely on the self-awareness at every exit. AnQiCMS's visual template editing allows direct modification of template code, and the person modifying the template also needs to adhere to this boundary: when entering content into the template, keep it in the position of 'it is data'.

Common questions

I am the only one who can log in to the background, do I still need to worry about template injection?Yes.可控内容 not only comes from the login user: collected articles, user-uploaded filenames, comments may all be sources, and the permission model cannot stop the 'markers in the data'.

Why not remove the angle brackets globally for convenience?It may harm valid text and cannot prevent injection at non-HTML interpretation locations. Escaping according to the output context will not please both ends.

Is the automatic escaping built into the template engine sufficient?The default scenario is sufficient, but automatic escaping usually only processes the HTML body. Explicitly check the attributes, scripts, and URL locations, and the 'non-HTML context' in the mixed template is exactly the point to bypass.

Related articles

The image processing library is listed as an attack surface, what door locks should the site upload process have?

The image processing library decodes the binary content uploaded by users on the server, and remote code execution often occurs at the decoder layer rather than the business code. PbootCMS added the dangerous coder gate, input format whitelist, and resource limit to the security hardening in the V3.2.22 version record, and fixed the misjudgment of legal images. This article explains the three gates of entry for the site upload link, as well as why it would hurt normal images if it is too tight.

2026-10-11

The announcement removes the example function section to fix the resource allocation problem. Should the production site keep the demonstration code?

The rating of Drupal announcement SA-CONTRIB-2026-215 is only Less critical, but the handling method has completely removed the email example function, because the example has an issue with unbounded resource allocation. Should the demonstration code be retained on the production site, the criterion should be the exposure surface rather than the risk rating. This article analyzes the three types of risks brought out by the example code, the cleanup checklist at the deployment stage, and the restrictions when retaining the demonstration entry.

2026-10-11

After the cache expires, the old content is provided first, and then the update is performed in the background. What does this cache instruction solve?

Cache-Control's stale-while-revalidate allows the reuse of old content responses within the window period after expiration, while also revalidating with the origin server in the background, hiding the validation delay from the user's response. This article explains its division of labor with request directives max-stale, no-cache, and must-revalidate according to the MDN documentation, and provides suggestions for separating page documents and static resources for separate settings.

2026-10-11

What are the differences in the capabilities of the government portal and marketing website content management system?

The government portal content management system prioritizes content review, sensitive word filtering, and user group permissions, while the marketing website pays more attention to keyword libraries, anchor text, and form human verification; robots configuration and site map generation are the common foundations for both types of sites. This article breaks down the capabilities according to constraints and provides two configuration orientations within the same system to help choose based on the nature of the site rather than the length of the function list.

2026-10-11

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

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

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

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