How can the old data stored in the export file become a new injection point?
Exported data stored in the file may become a new injection entry when reimported, because double injection naturally takes two steps: malicious instructions are not executed when written for the first time, but are simply stored in the data as is; it is only triggered when a subsequent action reads it out and combines it into a query statement. Exporting and reimporting exactly creates such a
What is the difference between first-order injection and second-order injection
First-order injection is where the input is directly entered into the query: the content filled in the form is immediately spliced into the statement, so parameter binding and validation can prevent it at the moment of writing. Second-order injection moves the danger to the other end of the time axis: the content looks harmless and smoothly stored when it first comes in, but the actual splicing occurs at the moment it is used - generating export files, rendering pages, or re-importing. The difference lies in the 'time of validation' and the 'time of danger' not being in the same step.
Why is the export replay path easily overlooked
Export is treated as 'read' instead of 'write', but it is actually a reassembly: combining the fields from the library into a structured file. If the fields are not escaped during assembly, the suspicious content that was侥幸存进来的 would be written as executable segments in the file. When this file is imported into another instance, the import logic treats it as external input and directly stores it in the database, even as template parsing - with two layers of trust叠加, no one checked the path and it leaked out like this.
Where to place the validation, at the write layer or the read layer?
It is not enough to only place it in the write layer because the danger of secondary injection is in the read/replay step. The reasonable approach is to place both layers and use the same set of rules:
| Link | What to do | Is it enough to place it only in this layer? |
|---|---|---|
| Page write | Parameter binding + sensitive word filtering | No, it cannot reach old data |
| Generate export | Field escaping before writing to the file | No, it cannot reach it after import |
| Batch import | Treat it as external input for validation | Critical, re-entry point |
| Interface write | Same rules as page write | No, it cannot reach export |
Three types of field risks at batch import
The site supports batch import using ZIP compression packages and Excel spreadsheets, the three types of fields on this path should be watched most: one is the fragments that may be parsed as templates in the title and body, the other is the custom field name - if the field name is imported as a structure rather than data, it may be spliced into the statement, the third is the link and identification field, which is easy to carry cross-site scripting. The characteristics of batch import are large in number, often triggered by scripts, and once the verification is bypassed, the problem will be magnified into a batch once.
How to close the import interface within the site
The document content import interface (including path with import and archive) is used for batch import and can also query whether it exists by title. The bottleneck lies in: the interface writing and page writing must use the same set of input verification, not that the page has and the interface bypasses without——otherwise, the attacker will deliberately choose the interface that has less verification.Before importing, use the ability to check for duplicates by title to block obvious repetitions, bind and escape field names and text fragments during import, and ensure that the step of 'reading out and writing into the file' is also escaped during export.Consider SQL injection and XSS protection as a layer贯穿reading and writing, not just a check at the time of release.
Self-check list
First ask whether the field is escaped when the export file is generated; then ask whether the file field is treated as data or structure during batch import; thirdly, ask whether the interface writing and page writing are the same validation code; fourthly, ask whether the old data in the historical database will trigger if it is replayed today. If either of the first two steps is 'no', it is necessary to add escaping or binding.
Common questions
Question: Was the old data entered normally back then, and will it be dangerous?Answer: Yes. The second injection looks at how the content is concatenated during replay, not how it came in back then; the fragments侥幸存入的片段, when replayed, may become executable content.
Question: If the interface has already been authenticated, is there still a need for verification?Answer: Yes. The authentication manages who can call, the verification manages how content is pieced into the statement, both are different layers, this path of the interface cannot rely solely on authentication.
Question: Can duplicate checking by title prevent injection?No, it can only prevent duplicate entries; injection protection relies on parameter binding and escaping, duplicate checking is just an additional way to reduce noise.