The image processing library is listed as an attack surface, what door locks should the site upload process have?
The image processing library is listed as an attack surface because it decodes the binary content uploaded by users on the server: thumbnails, transcoding, watermarking, every operation must go through the decoder, and historically, many remote code execution incidents have occurred at this decoding layer, not in the business code.The mouth closing ideas given by the same CMS are worth comparing - PbootCMS made security hardening for Imagick in the update record of V3.2.22: added three items together, including dangerous coder access control, input format whitelist, and resource limit, and also fixed the misjudgment of legitimate images.The upload process of the site can be received with three access controls according to this framework.
Why is the image processing library considered an attack surface
Three conditions叠加:Input is not trusted (anyone can upload files), high parsing cost (image decoding requires memory and computing power), and wide format range (the encoding formats supported by the image library are much more than the actual needs of the business). Attackers have opportunities in the second phase - constructing malformed files to make the decoding process exceed the bounds, or exploiting the parsing defects of obscure formats. The upload entry looks the most 'harmless to animals and humans', just because it is trusted by default: pictures, look at it, nothing happens.
Dangerous decoders need to be turned off separately
The internal image library is divided into modules by format (coder), and modules with rare formats are high-risk areas for accidents: graphic exchange types, legacy vector and multi-frame formats, and components that can be invoked by the internal delegation mechanism. The approach to access control is to explicitly disable unnecessary modules, leaving only the coding supported by the business, rather than retaining all of them and filtering them at the upper level. This step ensures that 'format-based attacks' cannot enter the coding process at all, and the configuration is effective for a long time.
Input format is received according to the whitelist.
The second access control checks the input statement: File types are accepted based on the whitelist, only three or four image formats are commonly needed for business; at the same time, check the consistency of the actual file header with the declaration, reject if not consistent. The whitelist is more stable than the blacklist, with the same logic and extension name filtering - allow known, reject unknown. Note that the whitelist manages what is allowed to come in, while the coder access control manages how to decode what is allowed, each blocking a dimension, and missing one will have a gap.
Set resource limits for decoding
The third security door prevents cost abuse: limit the size of a single frame and total pixels, limit file size and memory usage, and set decoding timeout. Without a limit, a small file can decompress into a huge image that exhausts memory, which is the form of 'decompression bomb'; multi-frame format can also amplify processing time by several tens of times. The upper limit value is determined according to the distribution of normal business images, leaving some room but not an order of magnitude of room. The peer system lists the three items and resource limits together during the same hardening, because any one of them is missing, the other two will be bypassed.
Overly strict security doors may hurt legitimate images
The side effect of fully pulling up the three gates is misjudgment: Atypical images generated by edge browsers and ultra-large-size original photographs may be blocked by resource limits, and a too narrow whitelist may reject the required format for business. PbootCMS specifically fixed the misjudgment of legitimate images in the same record, indicating that this is not a one-time setup. The approach is to make the rejected items observable: record the distribution of reasons for rejection, review regularly, confirm whether it is an attack sample or normal content, and then fine-tune the limits and list.
| Gate | What to intercept | Commonly mistaken injury |
|---|---|---|
| Disable dangerous decoding module | Parsing defects of obscure formats | Rare, just confirm the business format |
| Input format whitelist | upload in disguise type | rejecting legitimate new format due to narrow list |
| decoding resource limit | unzipping bomb and ultra-large image | high-resolution original rejected due to size limit |
internal check of the station: AnQiCMS automatically assigns pictures according to the title, does not introduce external decoding components in the request path; when deploying with Baota panel or Docker image, it is recommended to check the upload directory and processing components according to these three security gates.
Common questions
Is it enough to only accept JPG, PNG, and WEBP in three formats?Most content is sufficient. Add animated graphics and documents as needed, for each format added, it opens up a new decoding path, and more can be added if a business reason can be provided.
How much should the resource limit be set to?Reverse engineer from the distribution of pictures on the current network: take the maximum side and total pixels of the normally uploaded pictures, and then add one to two times the extra amount. Relaxing to the level of quantity is equivalent to not setting it.
How to appeal for pictures that have been misjudged?Do not put in the hole after passing: record samples, analyze the reasons for rejection, adjust the parameters of the corresponding gate, check back with logs to confirm that the new parameters no longer hurt, this is the meaning of 'Observable Rejection'.