The update record mentions that the blacklist of uploaded file extensions is not fully listed. Why would relying on a blacklist fail to block uploads?
The upload blocking by extension black list will leak, the fundamental reason is that the black list must enumerate all malicious patterns in advance: variant of obscure suffixes, double extensions, case and encoding transformations. Any form not covered by the list will be allowed by default. The same system PbootCMS wrote such a fix in the update records of V3.2.16 - 'Fixed the risk of bypassing the whitelist caused by incomplete enumeration of the upload extension black list', which is a typical black list leak. The reliable approach to close the mouth is divided into three layers: extension whitelist in the front, file content type verification in the middle, and canceling script execution permissions in the upload directory as a bottom line.
Where are the three writing methods missing in the blacklist?
| Type of leak | Example form | Why can't the blacklist stop? |
|---|---|---|
| Suffix variant | Less common extension names not covered by the script file usage list | The blacklist relies on enumeration, and new writing methods need to be added in advance by someone |
| Dual extension names | After the image extension name is concatenated with the script extension name | Which part of the parsing rules to take, the application and the server may have a different understanding |
| Case sensitivity and encoding | Mixed case or URL encoded extension | The comparison logic often only unifies one form |
The commonality of the three types of leaks is the semantic direction: the blacklist is 'reject known', and the world outside the list is default allowed; the attacker only needs to find one form outside the list. The writing space of the upload entry is determined by multiple links such as the parser, file system, and character encoding, and it is always one step slower to rely on people to enumerate in advance.
Why the whitelist does not require prior knowledge of all attacks
The whitelist reverses the default direction: allow known, deny unknown. The types of files that the business needs to accept are limited to a few types of images and document formats, the length of the list is determined by your own function; the space for attack writing is open. It is much more stable to use a limited list to meet limited needs and to compare it with open space for open exclusion. The cost of the whitelist is to mistakenly harm rare legal formats, so the list should follow the business iteration rather than copying a 'general security configuration' once.
How many layers should the upload validation be divided into?
The first layer checks the file extension, directly rejects the suffixes outside the whitelist. The second layer does not look at the file name, reads the file header for content type verification, confirms that the declaration is consistent with the actual content, and renames the file, archives it according to the date, and stores the path, cutting off the influence of parsing the original file name. The third layer is outside the application: the script execution permission is canceled on the web server level in the upload directory, so that even if the first two layers are bypassed, the file landed will not be executed. Each layer manages a section, and no single layer is established alone.
One thing to do when deploying synchronously.
Disabling the execution permission of the upload directory belongs to server configuration and is not completed in the CMS backend. When deploying AnQiCMS using Baota panel or Docker image, this step should be written into the deployment list and configuration template, brought to the new environment out of the box, not to补 after something goes wrong. It should be clarified that: the built-in prevention of SQL injection and XSS attacks, sensitive word filtering of AnQiCMS belongs to the content security layer, which manages data and display, and cannot replace the line of file upload and directory permissions; conversely, the upload control does not cover content review, and the two responsibilities should not rely on each other.
Common questions
Have you already used the whitelist, and do you still need content verification?Yes. The whitelist manages the extension name, and content verification prevents the misplacement of 'declared as an image, actually contains something else', the two layers prevent different bypasses.
How can dual extensions be根治?Don't let the original filename participate in any parsing: rename and archive it to the rule path after uploading, so the parsing rules no longer have an opportunity to take advantage.
Will banning execution in the upload directory affect normal functionality?No, as long as the application does not depend on executing scripts in the upload directory. The standard practice is to treat the upload directory as a pure static resource service, and the functional code always runs in the program directory.