jquery ajax 调用.net 一般处理文件安全问题

最近在维护一个客户的积分网站的时候,发现了这样一个问题,有人通过.ashx的漏洞,往我们数据库里面插入短信发送数据,导致我们短信费用有了一定的损失

一般处理文件 也就是后缀名为 .ashx 的文件

一般处理文件 我们主要用于与前段jquery ajax 做异步调用,例如:

$.ajax({

                    sync: false,

                    dataType: "text",

                    url: "../Handler/HandlerVPhone.ashx",

                    data: { txtPhone: txtPhoneValue },

                    success: function (result) {

 

                    },

                    error: function (result) {

                        alert("验证手机号是否已注册出错!");

                    }

                });

 

 $.ajax({

                    sync: false,

                    dataType: "text",

                    url: "../Handler/HandlerSmsService.ashx",

                    data: { txtPhone: txtPhoneValue, type: "Get", prType: 1 },

                    success: function (result) {

                       

                       

                    },

                    error: function (result) {

                        alert("手机验证码发送出错!");

                        return false;

                    }

                });

以上是做手机号短信发送,调用短信接口,往数据库里面插入值

这些都可以被别人调用,别人只需要在这些一般处理文件的前面加上域名,然后在后面加上参数就可以在其他程序上访问了

例如:

http://www.xxx.com/Handler/HandlerVPhone.ashx?txtPhone=xxxxxxxxxxx 

http://www.xxx.com/Handler/HandlerSmsService.ashx?txtPhone=xxxxxxxxxxx&type=Get&prType=1 

 

解决的办法:

 

.net  页面后台,通过GUID 产生出唯一值,赋值给session,   前台一般处理文件参数传值到后台做验证

 Session["chkcode"] = Guid.NewGuid().ToString();

 hdnchkcode.Value = Session["chkcode"].ToString();

前台ajax 给参数

 $.ajax({

                    sync: false,

                    dataType: "text",

                    url: "../Handler/HandlerSmsService.ashx",

                    data: { txtPhone: txtPhoneValue, type: "Get", prType: 1, chkcode: hdnchkCode },

                    success: function (result) {

                       

                    },

                    error: function (result) {

                        alert("手机验证码发送出错!");

                    }

                });

一般处理文件里面内容做判断:

  if (context.Session["chkcode"] != null

                && context.Session["chkcode"].ToString() == context.Request.QueryString["chkcode"])

            {

            }

            else

            {

            }

这样就能避免别人通过调用你的一般处理文件,往你的数据库插入值啦,,

转载于:https://www.cnblogs.com/ashxSafety/p/4598300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值