当比较HTTP GET和HTTP POST时,从安全角度看有什么不同?其中一个选择是否天生就比另一个更安全?如果有,为什么?

我意识到POST没有公开URL上的信息,但其中有任何真正的价值吗?或者它只是通过隐匿性来实现安全?当安全性是一个问题时,我是否有理由更喜欢POST ?

编辑: 通过HTTPS, POST数据被编码,但url会被第三方嗅探吗?此外,我正在处理JSP;当使用JSP或类似的框架时,是否可以公平地说,最佳实践是避免将敏感数据完全放在POST或GET中,而是使用服务器端代码来处理敏感信息?


当前回答

Neither one of GET and POST is inherently "more secure" than the other, just like neither one of fax and phone is "more secure" than the other. The various HTTP methods are provided so that you can choose the one which is most appropiate for the problem you're trying to solve. GET is more appropiate for idempotent queries while POST is more appropiate for "action" queries, but you can shoot yourself in the foot just as easily with any of them if you don't understand the security architecture for the application you're maintaining.

最好是阅读第9章:HTTP/1.1 RFC的方法定义,以全面了解get和POST最初的含义。

其他回答

Neither one of GET and POST is inherently "more secure" than the other, just like neither one of fax and phone is "more secure" than the other. The various HTTP methods are provided so that you can choose the one which is most appropiate for the problem you're trying to solve. GET is more appropiate for idempotent queries while POST is more appropiate for "action" queries, but you can shoot yourself in the foot just as easily with any of them if you don't understand the security architecture for the application you're maintaining.

最好是阅读第9章:HTTP/1.1 RFC的方法定义,以全面了解get和POST最初的含义。

我通常的选择方法是:

GET用于稍后将通过URL检索的项 例如,搜索应该是GET,所以你可以做Search .php?s=XXX POST将被发送的项目 与GET相比,这是相对不可见的,并且更难发送,但数据仍然可以通过cURL发送。

区别在于GET发送数据是开放的,而POST是隐藏的(在http-header中)。

所以get更适合于不安全的数据,比如谷歌中的查询字符串。Auth-data永远不会通过GET发送,所以在这里使用POST。当然,整个主题有点复杂。如果你想阅读更多,请阅读这篇文章(德语)。

许多人采用一种约定(Ross提到过),即GET请求只检索数据,不修改服务器上的任何数据,而POST请求用于所有数据修改。虽然其中一种并不比另一种更安全,但如果你遵循这个约定,你可以应用横切安全逻辑(例如,只有拥有帐户的人才可以修改数据,因此未经身份验证的post将被拒绝)。

GET对任何人都是可见的(甚至是你肩膀上的人),并且保存在缓存中,所以使用post不太安全,顺便说一句,没有一些加密程序的post是不确定的,为了一点安全性,你必须使用SSL (https)