openresty / xss-nginx-module

Native support for cross-site scripting (XSS) in an nginx
147 stars 42 forks source link

xss-nginx-module does not work with Tengine 1.4.x #5

Closed thislancorp closed 11 years ago

thislancorp commented 11 years ago

Tengine 1.4.2 (http://tengine.taobao.org/download/tengine-1.4.2.tar.gz) conf: location /test { default_type text/html; echo '{"errcode":400,"errstr":"Bad Request"}'; xss_get on; xss_callback_arg 'callback'; }

curl: curl http://127.0.0.1/test?callback=test {"errcode":400,"errstr":"Bad Request"}

it seems the xss does not work.

zhuzhaoyuan commented 11 years ago

@thislancorp Does xss-nginx-module work with standard Nginx-1.2.x? We'll look into Tengine on our side if so. Thanks a lot!

agentzh commented 11 years ago

Hello!

On Fri, Dec 21, 2012 at 5:00 AM, thislancorp notifications@github.com wrote:

location /test { default_type text/html; echo '{"errcode":400,"errstr":"Bad Request"}'; xss_get on; xss_callback_arg 'callback'; }

你这个用例中 ngx_xss 不会起作用是因为 Content-Type 响应头不匹配,细节可以参见 xss_input_types 指令的文档:

https://github.com/agentzh/xss-nginx-module

有两种改法:

  1. 把你这个用例中的

    default_type text/html;

这一行修改为

default_type application/json;
  1. 或者其他不同,在 location 中再加上一行配置:

    xss_input_types text/html;

Best regards, -agentzh

thislancorp commented 11 years ago

@zhuzhaoyuan Host:42.96.141.104 Port 80 -----Tengine Port 88 -----Nginx

[root@AY121226035003e1d0562 tengine-1.4.2]# curl http://42.96.141.104/test {"errcode":400,"errstr":"Bad Request"}

[root@AY121226035003e1d0562 tengine-1.4.2]# curl http://42.96.141.104:88/test {"errcode":400,"errstr":"Bad Request"}

It seems it's the promblem about xss module,not Nginx core.

thislancorp commented 11 years ago

@agentzh 首先谢谢您的回应, 试过了您给出的方法,还是不行。 location /test {

default_type text/html;

            echo '{"errcode":400,"errstr":"Bad Request"}';
            xss_get on;
            xss_callback_arg 'callback';

}

然后试了您的openresty项目,完美解决(即便是您之前所判断的那个xss_input_types冲突错误的配置也能正常xss)。 而在其它1.2.x核心的NGINX伺服中,始终未跑成功过

: (

agentzh commented 11 years ago

Hello!

On Wed, Dec 26, 2012 at 12:16 AM, thislancorp notifications@github.comwrote:

@agentzh https://github.com/agentzh 首先谢谢您的回应, 试过了您给出的方法,还是不行。 location /test {

default_type text/html;

echo '{"errcode":400,"errstr":"Bad Request"}'; xss_get on; xss_callback_arg 'callback'; }

然后试了您的openresty项目,完美解决(即便是您之前所判断的那个xss_input_types冲突错误的配置也能正常xss)。 而在其它1.2.x核心的NGINX伺服中,始终未跑成功过

我刚刚从 nginx.org 网站下载了最新的 Nginx 1.2.6 核心,并仅添加了 ngx_echo 0.41 和 ngx_xss 0.03 这两个第三方 nginx 模块:

wget http://nginx.org/download/nginx-1.2.6.tar.gz
tar -xzvf nginx-1.2.6.tar.gz
cd nginx-1.2.6/
./configure --add-module=/path/to/xss-nginx-module \
       --add-module=/path/to/echo-nginx-module
make -j8
sudo make install

1 我首先尝试你最初的有配置错误的例子:

location /test {
    default_type text/html;
    echo '{"errcode":400,"errstr":"Bad Request"}';
    xss_get on;
    xss_callback_arg 'callback';
}

重启 nginx 之后测试结果是:

$ curl localhost/test?callback=test
{"errcode":400,"errstr":"Bad Request"}

2 然后按照我先前的建议,对 default_type 进行修正:

location /test {
    default_type application/json;
    echo '{"errcode":400,"errstr":"Bad Request"}';
    xss_get on;
    xss_callback_arg 'callback';
}

重启 nginx 后,再进行测试就得到期望结果了:

$ curl localhost/test?callback=test
test({"errcode":400,"errstr":"Bad Request"}
);

3 最后,我又尝试了我的另一条建议,即配置 xss_input_types 指令:

location /test {
    default_type text/html;
    echo '{"errcode":400,"errstr":"Bad Request"}';
    xss_input_types text/html;
    xss_get on;
    xss_callback_arg 'callback';
}

重启 nginx 之后再进行测试,同样得到期望的结果:

$ curl localhost/test?callback=test
test({"errcode":400,"errstr":"Bad Request"}
);

上述测试都是在 Linux x86_64 上完成。

我同时还尝试了 ngx_openresty 1.2.4.14 对上述三个示例进行了测试,结果也是完全相同的。请确认你的操作步骤正确。

如果问题依旧,请提供你完整的配置示例、操作步骤和你使用的各个组件的版本,以帮助我重现你看到的问题。

值得一提是,我并不对 Tengine 进行支持。请在向我报告问题时使用标准的 Nginx 发布或者 OpenResty :)

谢谢合作!

-agentzh

thislancorp commented 11 years ago

@agentzh @zhuzhaoyuan

已解决~测试Tengine和Nginx均正常了。

[root@thislancorp ~]# curl http://42.96.141.104:88/test?callback=test test({"errcode":400,"errstr":"Bad Request"} );

[root@thislancorp ~]# curl http://42.96.141.104/test?callback=test test({"errcode":400,"errstr":"Bad Request"} );

原因说来很搞笑,我测试时忘记了get附带参数。。。不好意思~