假设你有一个网站 包含一个单按钮。
当按下此按钮时, 向服务器发送 ajax 请求 - 服务器接收请求, 并在数据库的内部柜台中添加 1 个 。
用户可以复制整个请求( 及其信头) 并创建一个脚本, 发送无限请求, 以超载服务器( 并破坏计数器) 。
我试图避免:
- Recording the user IP
- Using Captcha
我在后端使用php 。 是否有办法防止这种情况? 是否有办法发送“ 看不见” 请求?
假设你有一个网站 包含一个单按钮。
当按下此按钮时, 向服务器发送 ajax 请求 - 服务器接收请求, 并在数据库的内部柜台中添加 1 个 。
用户可以复制整个请求( 及其信头) 并创建一个脚本, 发送无限请求, 以超载服务器( 并破坏计数器) 。
我试图避免:
我在后端使用php 。 是否有办法防止这种情况? 是否有办法发送“ 看不见” 请求?
你的问题叫做"跨站点请求伪造"
解决这一问题的好办法就是在调用有按钮的页面时生成随机字符串,将其写入用户会话和生成的页面,并连同按钮按键发送(例如,在 Get 请求中)。
在后端侧,您检查提交的字符串是否与用户会话中的字符串匹配, 然后从会话中删除字符串。 只有两个字符串匹配且不空时才继续。
这样, 每一个请求的 URL 都只有一次有效, 只有最初用按钮打开页面的用户才有效 。
您可以创建一个指定给按钮的独特标记,该标记只能与按钮按键一起提交一次。
这将意味着用户需要刷新页面以获得新按钮, 如果有问题, 则将标记与用户而不是按钮连接
以上方法意味着您需要添加服务器侧边代码。 您也许可以使用 < a href=> http:// samy. pl/evercookie/" rel=" no follow">> evercookie a > 这样的工具来记录客户端上的按钮按键, 并试图阻止用户发送另一个请求并回复用户的另一项请求 - 我建议不要在查询中这样做, 但可能会很有趣 ;
使用 ic 来尝试更清楚一点 :
生成按钮,以便它提交包含一个名为 uuid 的隐藏字段的表格,该字段包含该按钮预生成的 uuid 。 此 uuid 需要保存在数据库或记忆中。 如果您使用好的 uuid lib, 用户生成已有的 uuid 的机会是无限的 。
现在,用户点击了按钮, 动作将到 / my- button/? uuid= 3394b0e0- a3bb- 11e1- b3dd- 0800200c9a66
服务器现在检查 uid 是否是先前生成的 。 如果是的话, 它会从它存储的地方删除 uid, 并让该动作做任何事情 。 uid 不存在, 它返回一个 404 。
你不可能知道请求是如何启动的,你所能做的只是让伪造更加困难。但如果这与安全有关,那么就是那些能够成功伪造你最需要了解的请求的人。因此,尝试将此作为某种安全措施可能毫无用处(甚至误导 ) 。
您可以尝试一个加密的密钥, 服务器在特定时间里只接受一次, 但您仍然不知道请求是如何启动的( 您真的不应该依赖这个 ) 。 按钮是一个界面特性, 可以根据用户代理器配置后向用户提供的( 如果用户被注入了), 将其转换成其他的 UI 手工艺品 。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.