html_sanitize_iframe_url_protocol
The `html_sanitize_iframe_url_protocol` directive specifies allowable URL protocols for iframe `src` attributes in sanitized HTML.
Description
The html_sanitize_iframe_url_protocol directive is part of the NGINX HTML Sanitization module designed to enforce security by limiting which protocols are permitted in <iframe> tags. This directive accepts one or more protocol arguments, enabling configuration of the safety standards for external content embedded via iframes. When a request with HTML content is processed, the directive ensures that the specified protocols are checked against the source of any iframe URLs. If the protocol of a provided iframe source doesn't match the ones specified by this directive, the iframe is either altered to remove the URL or blocked entirely based on the configuration.
The context of this directive is limited to location, which means it can be defined inside a location block in the NGINX configuration. This capability makes it versatile for securing specific routes while allowing for different security settings across different areas of an application. By specifying protocols like https or data, administrators can control which types of external content users can access in a browser environment, thereby protecting against malicious content injection or mixed-content issues during secure browsing.
When configuring the directive, it is important to consider user experience alongside security. A strict policy requiring the use of only https may protect users from mixed-content issues but could hinder the functionality of some services that do not support HTTPS. Therefore, balancing security with usability is crucial when setting protocol requirements.
Config Example
location /example {
html_sanitize_iframe_url_protocol https;
}Make sure to list all protocols you want to allow, as any omitted will be rejected.
Combining this directive with html_sanitize_iframe_url_domain requires careful management to avoid conflicts.