html_sanitize_hash_max_size
Defines the maximum size of the hash table used for storing sanitized HTML elements.
Description
The html_sanitize_hash_max_size directive configures the maximum size of the hash table used by the HTML sanitization module in NGINX. This directive is particularly useful for controlling memory consumption when handling the sanitization of HTML content. By setting this directive, users can limit the number of unique elements and attributes that can be stored in the hash table during sanitization, thereby optimizing resource usage.
When the number of unique elements or attributes exceeds the specified size, older entries may be discarded. This can lead to scenarios where previously encountered elements or attributes may need to be re-evaluated during the sanitization process. Therefore, it's important to set an appropriate value based on expected workloads and content complexity. The directive accepts a flag as its argument, which must denote the maximum count of entries in the hash table.
In essence, this directive plays a critical role in balancing performance and resource management during the request processing phase, especially when dealing with potentially large or complex HTML content structures.
Config Example
location /sanitize {
html_sanitize on;
html_sanitize_hash_max_size 1024;
}Setting this value too low may lead to increased processing time as hashed entries are recalculated.
If you set html_sanitize_hash_max_size to a very high number without adequate resources, it may result in increased memory usage.