The announcement is about the assisted injection, what is the difference between parameter splicing into the query segment and string splicing?
Announcement is about the amplified injection, what is the difference between parameter splicing into the query segment and string splicing: The difference is in the position of responsibility. String splicing treats the content that should be data as an executable statement, and escaping can barely hold it; while splicing the query segment is that the program gives the decision of the structure to the request - escaping is only responsible for data boundaries, and cannot control the splicing at the structural level
Responsibility boundaries of two writing methods
| Writing style | Who decides the structure | Escape can hold | Typical parameter position |
|---|---|---|---|
| String is directly concatenated | Request content | Can barely, relying on the character whitelist | Search keywords, path parameters |
| Parameters participate in the query fragment | Request content | Can not, the structure is not data | Sort field, sort direction, exclude list based on conditions |
| Placeholder binding | Program | Not involved | All value positions |
The key is in the third column. Escaping solves the problem of whether quotes in the content will destroy boundaries, while 'this content is taken as a sorting clause and spliced in' itself is the structure being determined by the outside, no matter how complete the escaping is, it will not make it safe.
Why is it most likely to have problems excluding class and sorting class parameters
The list interface usually provides two types of capabilities: sorting by field and excluding certain authors or categories. For flexibility, these two parameters are often written to pass an expression, which is then pieced together by the program in the query. The parameter names look like values, but their actual semantics are structural. For example, the parameter used to exclude authors by name, the public notice directly writes the cause of the defect on the parameter, rather than in some function, for this reason.
The sorting parameter is similar: field names and directions cannot be bound with placeholders, they must be拼进语句, so it must be done on the server side to enumerate convergence, limit the sortable fields to a whitelist, and directly reject illegal values instead of allowing them after escaping.
Three-level self-check order
- Check if the parameter is involved in the structure: Find the position in the code where the request value is拼进 query segment, and judge whether each piece of content is part of the statement one by one;
- Check if convergence is done by type: bind with placeholders if possible, go with enumeration whitelist if not, and treat both as defects rather than just style issues if neither is done;
- Check if error information echoes the structure: Printing the segment content into the response or log will greatly reduce the difficulty of judgment, and such echo should be closed in the production environment.
The entry that should be monitored in the content system
The sorting parameters, filtering conditions, and batch operation entry of the article list all belong to the position of 'parameters determine the shape of the result set', which is the most need to review category.Content management system has had actual repair records at this level: v3.6.6 addressed the issue of list sorting parameter injection, and the配套 also fixed the defect that login credentials could be forged during site switching.When upgrading this type of system, in addition to installing the repair version, you also need to review the list parameters exposed to the outside——the defense capabilities (including JWT authentication, sensitive word filtering, and handling of SQL injection and XSS) solve the default path, while the custom extensions and manually written queries in the templates are still under your control.
Common questions
Is it safe to use only the query constructor provided by the framework?Not necessarily. There are also interfaces in the constructor that allow the input of original segments, and once these interfaces receive the request value, the structure is handed over again.
Can escaping and parameter binding be used at the same time?Yes, but the effects are different. Binding handles data, whitelist handles structure; treating escaping as structural protection is a common misunderstanding.
Is the injection facilitated by it a high-risk issue?To view the reachable path and authentication prerequisites. If the parameter is directly concatenated on the list interface that does not require login, it should be handled as a high-risk matter.