Vector icons can carry scripts, and when uploading images, it is necessary to filter out what content should be blocked.
Vector icons can have scripts, which refers to the inherent capabilities of the file type, not a specific vulnerability. It has the extension .svg and is often uploaded with images as icons, but it is a document written in a markup language: the official documentation directly describes the script element as 'allows you to add scripts to an SVG document', meaning that scripts can become part of the document, and external scripts can also decide the execution timing through asynchronous or delayed attributes. Therefore, the premise that 'the uploaded is an image' does not apply to this format.
Risk changes with the opening method
The consequences of opening the same file in two different ways are different. Asthe script is generally not executed when loaded from the reference source, the risk is low; but if the user or link directly opens it in the browser tab, it becomes an executable document, and the script runs in the source under which the file is loaded. If it is under the domain and path of the site itself, the running environment is the context of the site, and Cookie and login status are within the scope.
Therefore, it cannot be determined by the extension and MIME type alone. The determination should be based on the content, and the processing should fall before storage.
What content should be blocked during purification
| Category | Specific object | Processing suggestions |
|---|---|---|
| Script class | Script elements, inline event attributes (such as onclick and the like) | Remove directly |
| External reference | Reference elements of embedded external documents, pointing to remote addresses | Remove or rewrite as an in-site resource |
| Jump wrapping | Clickable link wrapping element | Reserved as needed by business, limited to in-site addresses when reserved |
| Deformed writing | Entity encoding, concatenation of comments, mixed case | Normalize first then judge |
| Volume class | Unzipping volume and nesting level of compressed variants | Limit the size and level after unzipping |
| Identification class | Identify duplicate elements within the document | Rename or deduplicate to avoid conflicts with the page itself |
The problem of compressed variants is often ignored: a small volume archive may contain content of a larger magnitude after unzipping, and it will also consume far more resources than expected during the parsing phase. PbootCMS recorded the expansion of upload types in V3.2.22, and at the same time, it was common practice to process both 'Force cleaning SVG and limiting SVGZ unzipping' together.
How to choose blacklist and whitelist
The blacklist is 'list what needs to be deleted', and the whitelist is 'list what can be kept'. The blacklist is convenient, it can preserve the original display effect, but the coverage depends on whether the list keeps up with the new style; the whitelist has a clear security boundary, but the cost is that it may delete unrecognized legitimate elements all at once, resulting in incomplete icon display.
In practice, both are often used together: first retain the elements needed for drawing and structure according to the whitelist, and then explicitly clear the script, event attributes, and external references with the blacklist, and re-serialize the output after purification to avoid transmitting it in its original form.
Where does the in-site processing fall?
The upload purification process deals with the file content layer, which is not the same as the content review within the site. AnQiCMS's content security settings include sensitive word filtering, keyword replacement, and content review, which are for the main text; for the file layer, we need to check the upload verification, type restriction, and purification rules. If the attachment field is only stored as a string in the custom content model, purification will not take effect, and the field definition should align with the actual processing chain.
Common questions
Why not just allow bitmaps?Bitmaps also have historical parsing issues, and vector formats are indeed more efficient in icon scenarios. If you really need to tighten up, you can limit the type by field, but when the business needs to upload icons, cleaning up is more maintainable than banning.
Is storage isolation required after cleaning up?Suggestion. Store files by object or in separate directories, access paths do not accept script execution, which can reduce the consequences of missed cleaning.
Will remote screenshotting bring in similar content?Yes. Remote capture and backend upload go through the same format judgment, any place that is allowed must be synchronized cleaned, otherwise the capture channel becomes a bypass.