Injections can also be hidden in exported files, where can the prevention of second-order SQL injection be found?

📅 October 12, 2026 👁️ 14

Second-order injection should be prevented at the consumption step, not the submission step. Its characteristic is delayed execution: when malicious content is first written, it is just ordinary data, passes the validation, enters the database, and appears harmless; it is only when it is taken out in the next process and executed as part of a statement that the injection actually occurs. The reason why exporting files is worth discussing separately is because it turns 'next consumption' into the most common action on the site.

The recent WordPress 7.1.3 security announcement listed this fix: There is a second-order SQL injection in the WXR export of WordPress. Among the batch of fixes, there is also an item that allows unauthorized reading of comments on private and unpublished articles, and when taken together, they cover both paths of 'data being taken out' and 'data being read out.'

Difference between first-order and second-order.

First-order injection is immediate execution upon request: parameters directly enter the query construction, with inputs and consequences in the same request. Detection is relatively easy, and protection is mature - parameterized queries separate data from statement structure, and inputs are always treated as values regardless of how they are constructed.

Second-order injection is divided into two stages: the first time it is data when written, and the second time it becomes structure when read. The problem lies in the different assumptions made in these two stages. The first time it is verified as 'this is the user's input content', and the second time it is concatenated as 'this is the trusted data in the library'. 'Trusted' is the entire basis for second-order injection.

Therefore, "Filtered before entry" cannot be used as a reason for exemption. The filtering rules are aimed at the dangerous forms in the submission scenario, while the second consumption often occurs in a completely different context: exporting to a file, importing into another library, rebuilding the search index, generating statistical reports. The ways of splicing in these processes are different, and the first filtering cannot foresee all downstream uses.

Why has exporting become a delivery channel

The exported file has three characteristics that exactly match the conditions for the second-order injection.

It is persistent. The file is used repeatedly once generated, and content that does not show any problems today may be executed in another environment six months later. It is structured. WXR and such export formats come with titles, content, categories, custom fields, and various slots, each of which may be spliced into different sentences on the import side. It crosses boundaries. Export and import often occur on different sites, different versions, and different database types, and the validation on the import side is often more lenient than that on the writing side, for the reason that 'This is the file I exported myself'.

The batch import is the most typical entry point. When importing documents in bulk using ZIP compression packages or Excel spreadsheets, the system needs to read and write fields one by one and store them in the database. It is possible that the same file may contain both normal content and fields that may cause problems in other contexts. Therefore, the import entry needs to be checked separately, and 'coming from in-site export' cannot be taken as a reliable basis. When importing external images, it is also necessary to block internal network addresses and large files to avoid the import process being mistaken for an entry point.

Where should the protection be placed?

The protection position is arranged in three steps: verify when writing, keep the original when storing, and do not combine statements when consuming.

Write this step according to the field type to tighten constraints, use whitelist for enumerative values, and use format verification for length and character set limitations, rather than relying on blacklist to pick dangerous words. The key point of this step is not to make a second interpretation: keep the data in its original value, and do not store assembled statement fragments in the database. The consumption of this step is decisive - wherever values in the library are used as part of a statement structure, they should be changed to parameterized methods, including report queries, index input, and batch updates, which are easily overlooked paths.

Within the security design of AnQiCMS, built-in JWT authentication and sensitive word filtering, and anti-interference code for collection prevention are part of the same chain, the official defense targets include SQL injection and XSS categories. In terms of data flow, there are also two complementary capabilities available: document status is divided into formal, draft, pending release, and recycling bin, deleting a formal document is moved to the recycling bin instead of physical deletion; backup and recovery support data and static files to be processed together. These two capabilities determine the radius of impact of a misoperation - as long as the original data is still in a recoverable state, the issues on the import side are not likely to become permanent losses.

The checklist for backup and recovery process

The recovery process is the most easily overlooked scenario in second-order injection: the recovery itself is to 'consume historical data again'. The items are listed in order: before recovery, make a backup of the current state to avoid being unable to retreat after overwriting; confirm that the recovery source comes from a controlled location, not from an external file specified by the address parameters; after recovery, check that the database version and structure are consistent, and then check each content field for any abnormal prefixes or extra escape characters; finally, check whether the import entry validation is effective for new data.

There is one thing often ignored: the habit of using exported files as logs. Some websites regularly export content for statistics or archiving, and these files are often left in directories that can be directly downloaded, both as a data leak surface and as a potential for unreviewed execution when imported next time. The archives should either be placed in a location that cannot be read externally or a structural check should be performed before import. The same reason also applies to the content in the recycle bin, as long-term retained deleted data will also enter the consumption path when restored and imported.

Common questions

Question: Can parameterized queries prevent second-order injection?
Answer: It can prevent the execution link. The parameterization solves the problem of data being treated as a statement structure, which is a key step in the second-order injection.

Question: Should the export file be escaped?
Answer: The export should keep the data unchanged, placing the protection on the consumption method on the import side. Rewriting the content during export will cause data distortion.

Question: How to judge whether there is such a hidden danger in your site?
Answer: Check all the positions where the fields in the database are spliced into the statement, focusing on the three paths of reports, index import, and batch update, rather than just looking at the form submission entry.

Related articles

The XSS triggered when the comment is opened in the background, where should the content system prevent it?

Some cross-site scripting attacks are not triggered on the front end, but are executed when administrators open pending comments on the backend. This type of vulnerability has a completely different protection location than the front end. This article takes the recently fixed WordPress 7.1.3 comment management page stored XSS as an example, explaining why the secondary context is an independent attack surface, why input filtering is not enough, and the three layers of protection that need to be done on the backend: output escaping, permission boundaries, and content review.

2026-10-12

When old versions only patch security vulnerabilities, should we wait for the main branch to upgrade features?

The security patch and feature upgrade follow two timelines. Taking the recent WordPress 7.1.3 as an example, the official has patched the security fixes back to the old branches that still qualify, while reminding that only the latest version is actively supported. This article explains the difference between active support and security support levels, why feature improvements have to wait for the main branch, and what order to judge when arranging the upgrade timeline for the site.

2026-10-12

After the crawling behavior is divided into several categories, how should the site's release rules be adjusted accordingly.

Divide the automated capture into three layers according to behavior - for subsequent answer collection and indexing, for model training capture, and for replacing users to fetch pages in real time, the benefits and costs of the three types are completely different. This article explains why domain-based access is not enough, how the access rules should be layered, and why the robots only expressing intention determines that it must be used in conjunction with content-side protection.

2026-10-12

Is llms.txt a mandatory standard? What will sites lose if they do not perform this step?

llms.txt is not a mandatory standard, but a community proposal still under discussion: the file is written in Markdown for site descriptions and resource lists, with top-level headings being mandatory paragraphs. Not including this file will not trigger any crawling penalties, the cost being that the model will have one less level of navigation when extracting content. This article describes which formats are fixed in the proposal, what can be achieved, and where the automatically generated file is connected in the site.

2026-10-12

What can unlogged-in users read, where are the permission boundaries of the content system likely to leak?

What can unlogged users read depends on where the permission boundary is drawn. Most unauthorized access is not in the main article itself, but in附属 data, interface lists, and preview entries: comments, attachments, and draft previews all have their own visibility. This article explains the three most easily overlooked positions and the methods of closing with in-station user group permissions, document status, and default closure of high-risk interfaces.

2026-10-12

Where do the differences in costs lie between self-built content systems and pay-as-you-go cloud services?

Self-built content system and pay-as-you-go Headless cloud services, the main cost difference lies in the four items of servers, request volume, integration expansion, and operation and maintenance personnel. Self-building on a small scale is usually more cost-effective, while maintenance and personnel become the main expenses as the scale increases; Headless deploys the front-end to the edge, retrieves content by interface, eliminates server-side rendering for each request, but introduces interface call billing. This article compares the four items and provides a comparison with self-hosting.

2026-10-12

The content management system released several security versions in a month, indicating what operation and maintenance should change.

The content management system released security maintenance versions consecutively within a month, indicating that the operation and maintenance judgment criteria should shift from version numbers to the content of the fixes. This article takes recent *** information as an example: WordPress released three security maintenance versions consecutively in September and October, Joomla released security fixes for both 5.x and 6.x versions at the same time, and three operation and maintenance adjustments can be extracted from them - decide according to the content of the fixes, leave a rollback point for upgrades, and rotate keys and passwords after upgrades.

2026-10-12

Why does the wildcard or regular expression for crawling exclusion files not work according to path prefix matching?

This protocol only recognizes User-agent and Disallow, and explicitly does not support wildcards and regular expressions. This article explains why rules are only followed by prefix, what happens when wildcard and regular expression writing occurs, and the order in which directory paths and slashes should be written within the site to match real needs.

2026-10-12