由于通过HTTP POST发送的变量比通过HTTP GET发送的变量更安全,因此没有提供更高的安全性。
HTTP/1.1为我们提供了一系列发送请求的方法:
选项
得到
头
帖子
把
删除
跟踪
连接
让我们假设你有以下HTML文档使用GET:
<html>
<body>
<form action="http://example.com" method="get">
User: <input type="text" name="username" /><br/>
Password: <input type="password" name="password" /><br/>
<input type="hidden" name="extra" value="lolcatz" />
<input type="submit"/>
</form>
</body>
</html>
你的浏览器会问什么?它问的是:
GET /?username=swordfish&password=hunter2&extra=lolcatz HTTP/1.1
Host: example.com
Connection: keep-alive
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/ [...truncated]
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) [...truncated]
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
现在让我们假设我们将请求方法更改为POST:
POST / HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: 49
Cache-Control: max-age=0
Origin: null
Content-Type: application/x-www-form-urlencoded
Accept: application/xml,application/xhtml+xml,text/ [...truncated]
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; [...truncated]
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
username=swordfish&password=hunter2&extra=lolcatz
这两个HTTP请求都是:
不加密的
包括在两个例子中
可以被偷取,并受到MITM攻击。
很容易被第三方复制,和脚本机器人。
许多浏览器不支持POST/GET以外的HTTP方法。
许多浏览器行为存储页面地址,但这并不意味着您可以忽略任何其他问题。
具体来说:
一种天生就比另一种更安全吗?我意识到POST不会暴露URL上的信息,但其中是否有任何真正的价值,或者它只是通过隐匿性来安全?这里的最佳实践是什么?
This is correct, because the software you're using to speak HTTP tends to store the request variables with one method but not another only prevents someone from looking at your browser history or some other naive attack from a 10 year old who thinks they understand h4x0r1ng, or scripts that check your history store. If you have a script that can check your history store, you could just as easily have one that checks your network traffic, so this entire security through obscurity is only providing obscurity to script kiddies and jealous girlfriends.
在https上,POST数据被编码,但url可能被第三方嗅探?
下面是SSL的工作原理。还记得我上面发送的两个请求吗?下面是它们在SSL中的样子:
(我将页面更改为https://encrypted.google.com/,因为example.com在SSL上没有响应)。
通过SSL POST
q5XQP%RWCd2u#o/T9oiOyR2_YO?yo/3#tR_G7 2_RO8w?FoaObi)
oXpB_y?oO4q?`2o?O4G5D12Aovo?C@?/P/oOEQC5v?vai /%0Odo
QVw#6eoGXBF_o?/u0_F!_1a0A?Q b%TFyS@Or1SR/O/o/_@5o&_o
9q1/?q$7yOAXOD5sc$H`BECo1w/`4?)f!%geOOF/!/#Of_f&AEI#
yvv/wu_b5?/o d9O?VOVOFHwRO/pO/OSv_/8/9o6b0FGOH61O?ti
/i7b?!_o8u%RS/Doai%/Be/d4$0sv_%YD2_/EOAO/C?vv/%X!T?R
_o_2yoBP)orw7H_yQsXOhoVUo49itare#cA?/c)I7R?YCsg ??c'
(_!(0u)o4eIis/S8Oo8_BDueC?1uUO%ooOI_o8WaoO/ x?B?oO@&
Pw?os9Od!c?/$3bWWeIrd_?( `P_C?7_g5O(ob(go?&/ooRxR'u/
T/yO3dS&??hIOB/?/OI?$oH2_?c_?OsD//0/_s%r
通过SSL
rV/O8ow1pc`?058/8OS_Qy/$7oSsU'qoo#vCbOO`vt?yFo_?EYif)
43`I/WOP_8oH0%3OqP_h/cBO&24?'?o_4`scooPSOVWYSV?H?pV!i
?78cU!_b5h'/b2coWD?/43Tu?153pI/9?R8!_Od"(//O_a#t8x?__
bb3D?05Dh/PrS6_/&5p@V f $)/xvxfgO'q@y&e&S0rB3D/Y_/fO?
_'woRbOV?_!yxSOdwo1G1?8d_p?4fo81VS3sAOvO/Db/br)f4fOxt
_Qs3EO/?2O/TOo_8p82FOt/hO?X_P3o"OVQO_?Ww_dr"'DxHwo//P
oEfGtt/_o)5RgoGqui&AXEq/oXv&//?%/6_?/x_OTgOEE%v (u(?/
t7DX1O8oD?fVObiooi'8)so?o??`o"FyVOByY_ Supo? /'i?Oi"4
tr'9/o_7too7q?c2Pv
(注意:我将HEX转换为ASCII,其中一些显然是不可显示的)
整个HTTP会话都是加密的,通信的唯一可见部分是在TCP/IP层(即IP地址和连接端口信息)。
让我在这里做一个大胆的声明。你的网站并没有通过一种HTTP方法提供比另一种更大的安全性,世界各地的黑客和新手都确切地知道如何做我刚才在这里演示的事情。如果需要安全性,请使用SSL。浏览器倾向于存储历史,RFC2616 9.1.1建议不要使用GET来执行操作,但认为POST提供了安全性是完全错误的。
POST的唯一安全措施是什么?防止嫉妒的前任翻看你的浏览记录。就是这样。全世界的人都登录了你的账户嘲笑你。
为了进一步证明为什么POST不安全,Facebook到处都在使用POST请求,那么像FireSheep这样的软件是如何存在的呢?
Note that you may be attacked with CSRF even if you use HTTPS and your site does not contain XSS vulnerabilities. In short, this attack scenario assumes that the victim (the user of your site or service) is already logged in and has a proper cookie and then the victim's browser is requested to do something with your (supposedly secure) site. If you do not have protection against CSRF the attacker can still execute actions with the victims credentials. The attacker cannot see the server response because it will be transferred to the victim's browser but the damage is usually already done at that point.