xss_input_types
The xss_input_types 指令指定要在 NGINX 中为跨站脚本支持处理哪些 MIME 类型。
Native cross-site scripting support in NGINX
·
httpserverlocationif in location
语法xss_input_types mime-type ...;
默认值application/json
上下文http, server, location, if in location
参数1+
说明
xss_input_types 指令用于配置 NGINX 服务器,在处理跨站 AJAX 请求时仅处理指定 MIME 类型的响应。该指令接受一个或多个 MIME 类型参数,并可在 http、server、location 和 if in location 上下文中使用。它是跨站 AJAX 支持的关键功能之一,通过确保只有特定的内容类型会被用于脚本修改,从而启用 JSONP 功能。默认情况下,模块将 application/json 作为被识别的输入类型,这使得它可以处理专为 JSONP 定制的响应,而忽略其他可能不适合用于此目的的类型。
配置示例
server {
location /foo {
xss_get on;
xss_input_types application/json text/plain;
}
}⚠
确保提供有效的 MIME types;拼写错误会导致该指令无法按预期工作。
⚠
记得包含所有必需的 MIME types;如果省略了某个必要的类型,有效的响应可能会被忽略。