×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

这是一个authorization的例子,第一部分是http request, 而后是response.

GET http://192.168.0.2/MainPage?id=19 HTTP/1.0

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*

Accept-Language: zh-cn

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

Host: 192.168.0.2

Proxy-Connection: Keep-Alive

------------------------------------------------------------------------------------------------
HTTP/1.1 401 Unauthorized

WWW-Authenticate: Basic Realm="Viking"

Content-type: text/html

Content-length: 0
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 用。NET做网站的时候, 比如看用户的信息, URL就会类似 localhost/web/userdetails.aspx?userid = 1, 如果用户自己把URL改成USERID=2, 就会看到别人的信息, 怎样用技术手段防止或者是探测URL的人工改动呢?thanks
    • 第一,不要用这么明显的url; 第二,在页的开头要有个验证过程,比如,登陆名是否和看得一致?如果不一致,是否有权限(比如管理员)等等。
      • 多谢, 看来数据库认证逃不掉了。
        • 不一定是数据库。可以用session
          • 是, 但是有个界面比较麻烦
            • 在HTTP response返回 Status code 401和必要的要求用户输入用户名/密码信息就可以了。
              The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information. HTTP access authentication is explained in "HTTP Authentication: Basic and Digest Access Authentication"
              • 没看懂的说, 有相关的连接吗?
                • 这是一个authorization的例子,第一部分是http request, 而后是response.
                  GET http://192.168.0.2/MainPage?id=19 HTTP/1.0

                  Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*

                  Accept-Language: zh-cn

                  User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

                  Host: 192.168.0.2

                  Proxy-Connection: Keep-Alive

                  ------------------------------------------------------------------------------------------------
                  HTTP/1.1 401 Unauthorized

                  WWW-Authenticate: Basic Realm="Viking"

                  Content-type: text/html

                  Content-length: 0
                  • 这个程序是方式未经授权的拥护访问相关页面, 我的CASE是用户已经成功LOG IN了, 忽然自己想改URL,然后再PRESS GO或者REFRESH, 这样就可以看到别的用户的信息了。 这个程序好象不适用? 或者我没理解对?
                    • well, in this special page , u'd better compare his login id in the session with the user id
                      • 4242, 加上还有别的信息, 我必须写个四到破塞着了
                    • 你需要使用cookie
                      一种cookie是session id的cookie, 用户登录后,http server 把这个session id给用户,以后当用户再访问任何页面,都要带着这个cookie,否则就拒绝访问。这就是萝卜秧说的session control.
                      一种简单一些的方法就是要求用户每次访问你的页面都要把用户名/密码放在cookie里面传给server。server 每次都去验证,没有或不对就返回401。
                      • cookie =/= session
                        • 同意,我举的例子一个是用cookie控制session,一个是用cookie不用session。其实也可以有不用cookie控制的session. 个人经验觉得用cookie一般编程简单。
                      • 没办法用session的时候才用Cookie, Cookie的值存放在用户方,用户可以随便修改。session变量一般是存放在server的。Cookie适合存放用户的访问次数,用户界面配置之类的无关紧要的东西。
              • 这个方法对付盗链时候常用。归根结底,还是要用户认证。
    • create a random stuff, something like GUID
      • 替代USERID?
        • hoho, yes.
          • 有些ID是从DATABASE里直接提取放到DATAGRID上做连接, 所以难点
            • I normally generate GUID as user ID. It looks pro...hohoho
              • 关键是用了这个加密的ID,也不能保证用户神奇的一小手正好蒙对另一个用户的ID的说。
                • If u do not wanna use authentication, risk is there. BTW, if they can 蒙对 GUID, they should be able to 蒙对 username and pwd.
                  • 那俩俺都在数据库里加密了
                    • use post instead of get, att server side, only requestform. or when the user first login, store the userid in session and every other page, compare the userid.
    • 用POST方法。在SERVER端,不接受用GET方法传的变量。这样要想该URL,就必需应该。htmlfile,更麻烦。而且URL上也看不出来。
      • 同时要检查是从哪里post过来的。
      • POST 变量也是从用户端传来的,所以也不安全。实际上用FireFox就可以轻易的修改POST的值。
    • 简单啊。把userid放到session变量里面。然后写一小段code,判断当前ie的地址栏里面的id是否相符,然后把这段代码引用到你所有需要保密的页面中
      • 这不是想找个捷径嘛, 这方法正用着那
    • 其实不光是asp.net, php, jsp,如果用get来传递username的话都会有这个问题,用post也不安全.这些流行的网页语言大都是用session变量来传递user name的,
      而且不是这样简单地传递username,你应该增加个session变量看这个用户是不是已经通过了密码验证,如果是的话显示,不是的话就不显示.相对来说,.net实现起来最方便
    • 这是偷懒啊。你想要做的是Authorization, 可能你还有其他的资源需要检查。Solution: 1. use httpmodule(prefered) 2. Create a base page and check authorization in that page and inheritate from that page.
    • 我这是这样干的。
      首先,当用户Login 成功的时候,把用户的一些信息(如userid )存到session,同时根据用户的http header的信息以及sessionID等东东生成一个key传回客户端。在后续的交互中,客户端必须提供该key,同时检测所有的信息是否正确。
      其次,尽量采用POST,如果一定要用GET(有时候还是GET方便),把所有的数据加密(包括Field Name),在地址栏看到的是a.aspx?sadfkjeijf03298r23rojw9jfwldf9sjpd, 到了server端再处理,一般来讲用户是没办法自由修改数据的,就算是碰巧,也会导致验证失败。

      而对于敏感信息,在function里同样要再次验证用户。

      这样,基本上是够用了,当然,很多时候,这些都是防君子不防小人的。