How should the deletion range be verified for the batch deletion interface of background messages according to parameter concatenation?
How to verify the deletion range when the interface for deleting batch comments is parameterized, where is the answer not in the front-end transmitted numbers, but whether the range is recalculated on the server. Many background systems will submit multiple records selected on the list page along with their IDs. After the interface receives the list of IDs, it is directly added to the deletion conditions, which seems convenient, but in fact shifts the responsibility of determining what to delete to the caller. What is transmitted by the front-end can be changed, and if the server accepts it as is, the deletion range loses its constraint.
Why does the batch interface amplify the scope of impact
The single delete interface processes only one record at a time, the consequences of boundary crossing are usually limited to a single data record. The batch interface packs the IDs of multiple records into the same request, and one misjudgment can amplify it to a large area.The interaction of checking, selecting all, and deleting by filtering criteria on the list page naturally causes a request to carry a string of numbers. The more numbers, the greater the space for parameters to be tampered with or misunderstood: as long as there are no constraints on the concatenation of a segment, the statement to delete the current category may inadvertently hit other categories, other status ranges, or even data under other people's names.PbootCMS has already fixed this type of issue in the update logs of V3.2.18 - there is a parameter injection risk in the batch deletion of background messages, the fix is to strictly verify the list of ids to be deleted instead of trusting the numbers sent from the front end.This id refers to the primary key number in the database.
What kind of validation should the ID list undergo
Verify in two layers. First, verify the individual number itself: is the type correct, is it an integer primary key expected, or is it a string mixed with symbols; is the format clean, or has it been inserted with additional condition fragments?Is the amount within a reasonable range? The core of the repair in PbootCMS is also at this level, checking the id list item by item according to type and existence, and directly rejecting the illegal ones.Recheck the batch number: Each one must be confirmed to fall within the data range accessible to the current operator, belong to the same category, and be within the same status range, rather than mixed in with cross-category or cross-permission numbers.Check existence as well, if the number cannot be found in the database, it means that the request and data do not match, and the batch should be refused or removed before reporting an error, rather than concatenated and handed over to the delete statement.
Why does the deletion range need to be recalculated on the server side
The number transmitted from the front-end is just an intention, not an authorization. The server cannot take the number as a range, but should take the current session's identity, permissions, and column ownership to recalculate the set allowed to be deleted, and then intersect it with the number.The number outside the intersection, either reject it or fail the whole batch. Even if someone puts an out-of-bounds number in the parameters, this step of recalculating on the server will block it.Range validation also requires that the deletion condition not rely solely on the concatenation of the ID list, but should also include the attribution condition, so that the filtering conditions at the database level naturally enclose the rows that can be deleted.This WHERE clause refers to the filtering subclause in the delete statement.
After deleting what will you rely on?
Even if the verification is done properly, the risk of accidental deletion cannot be said to be zero: mistakes in checking, understanding bias, and script exceptions may lead to the deletion of records outside the scope. Therefore, the deletion interface needs a safety net. A common practice is not to perform physical deletion, but to move the records to a recoverable position first, and then completely clean up after confirming that there are no errors. In terms of internal practices, AnQiCMS does not perform physical deletion of formal documents, but moves them to the
Common questions
Ask: If the front-end has limited the selection range, does the server still need to check again for batch deletion?
Answer: Yes. The front-end limit is just a constraint at the experience level, the parameters can be rewritten during transmission, and the server must treat it as untrusted input and recalculate the range allowed for deletion again.
Ask: If an illegal value is mixed into the number, should the whole batch fail or skip it and continue to delete?
It is more reliable to reject the whole batch and report an error, to avoid the inconsistency of deleting half and skipping the other half; the premise of actually skipping is to clearly inform the caller which numbers have been excluded.
Ask: Can the recycle bin replace the range check?
Answer: No. The recycle bin deals with the reversibility of deleting incorrectly, and the check stops the deletion from going out of bounds, both of which play different roles at different stages and are indispensable.