开门见山,考虑下面的代码(原文连接有详细的解释)
<html> <body> <?php if (isset($_REQUEST['submitted']) && $_REQUEST['submitted'] == '1') { echo "Form submitted!"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="submitted" value="1" /> <input type="submit" value="Submit!" /> </form> </body> </html>
看似准确无误的代码,但是暗藏着危险。让我们将其保存为 foo.php ,然后放到 PHP 环境中使用
foo.php/%22%3E%3Cscript%3Ealert('xss')%3C/script%3E%3Cfoo
访问,会发现弹出个 Javascript 的 alert -- 这很明显又是个 XSS 的注入漏洞。究其原因,发现是在
echo $_SERVER['PHP_SELF'];
这条语句上直接输出了未过滤的值。追根数源,我们看下 PHP 手册的描述
'PHP_SELF' The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.
原因很明确了,原来是 $_SERVER['PHP_SELF'] 虽然“看起来”是服务器提供的环境变量,但这的确和 $_POST 与 $_GET 一样,是可以被用户更改的。
其它类似的变量有很多,比如 $_COOKIE 等(如果用户想“把玩”他们的 cookie,那我们也是没有办法)。解决方案很简单,使用 strip_tags、htmlentities 等此类函数过滤或者转义。
echo htmlentities($_SERVER['PHP_SELF']);
-- Split --
上述的例子让我们需要时刻保持谨慎 coding 的心态。Chris Shiflett 在他的 Blog 总结的相当直白,防止 XSS 的两个基本的安全思想就是
Filter input Escape output
我将上面翻译成 “过滤输入,转义输出”。详细的内容,可以参考他 Blog 的这篇文章,此处略。
Gracecode.com | Permalink | Trackback | Wap | Rss | 2 comments
11月话题: 音乐功能和音乐网站
广州,广州市天河区科韵路16号广州信息港E栋 网易大厦一楼,请注意地点变更,
16号(周日)、下午、两点半。
参与嘉宾:白鸦、彭毅、Fenng
成都,天府大道北段1480号高新区软件孵化园十一号楼天府软件工作室2301,请注意地点变更,
16号(周日)、下午14:30。
杭州,淘咖啡,上城区南山路186号(柳浪闻莺对面) (地图),请注意地点变更,
16号(周日)、下午14:30。
北京,西直门附近奇遇花园(地图),
16号(周日)、下午14:30。
上海,龙华路2577号,5号楼,BlogBus办公室(地图),
16号(周日)、下午14:30。
南京,洪武北路55号新街口置地广场8层江苏都市网,请注意地点变更,
16号(周日)、下午14:30。
深圳,问道旅行馆南山店(详情),
16号(周日)、下午14:30。
书友会详细信息:http://ucdchina.com/
特别感谢江苏都市网,赞助南京书友会的场地。
转载请注明出自UCDChina.com,谢谢。
For normal Innodb “hot” backups we use LVM or other snapshot based technologies with pretty good success. However having incremental backups remain the problem.
First why do you need incremental backups at all ? Why not just take the full backups daily. The answer is space - if you want to keep several generations to be able to restore to, having huge amount of full copies of large database is not efficient. Especially if it only changes couple of percents per day.
The solution MySQL offers - using binary log works in theory but it is not overly useful in practice because it may take way too long to catch up using binary log. Even if you have very light updates and can execute updates for a full day within an hour it will take over 24 hours to cover month worth of binary logs… and quite typically you would have much higher update traffic.
Another solution is rdiff which is a great general purpose tool. Though you can do much better with Innodb in Particular.
The Innodb pages have great deal of information helpful for their incremental backup in their internal. There is basically page version allowing to quickly check if the page is newer. There is page checksum and finally there is an offset of page (where it should be in the data file) stored in the page.
Using this data it should be easy to implement very efficient and yet simple for Incremental backup for Innodb.
In a way similar to rdiff the tool could both update the backup and store the rollback changes or if dealing with read-only compressed backup create the roll-forward recovery log, which also can be easily compressed.
What tool would need to do is to go through the pages for each Innodb file and simply write all the new pages to the separate file. Because pages already have position information in them there is no need to have complex “diff” meta data.
For recovery we can simply read this new pages file and put the pages back to their original places.
Of course this means .frm files and Innodb logs and MyISAM system tables need to be copied fully but they typically do not have any considerable portion of Innodb database
Entry posted by peter | 6 comments
今天在GReader上看到Fenng推荐了一篇“2008年中文网志年会叽歪“,瞄了一眼,汗,再瞄一眼,囧,赶紧留了言。回头想想,也许该多说些,正好,这周末年会就开始了,回头看看今年的blog几近荒芜,趁着就Young的这篇文字做一些解释的机会,临时抱佛脚补一点是一点吧。
中文网志年会的英文全称是 Chinese Blogger Conference,简称就是cnbloggercon,域名是cnbloggercon.org;
cnbloggercon也是年会专用的标签(Tag),几乎可以在各个支持tagging的网站上用这个tag搜索和聚合,比如又拍,delicious,flickr,technorati,twitter等 ……
第一次网志年会是在2005年,地点是上海,年会blog上写得没错,当时用的是cnblog.org/bloggercon,其实,用网络工具可以回溯很多历史 :-)
至于为什么用“网志”,可以看看维基百科上的“网志”词条。
虽然域名注册人是我,但不表明年会是我号召和组织的,更不是所谓的“创办人”或者“一把手”。每年的年会都是由一群在各地的志愿者以松散的结构使用各种网络工具协调和组织起来的(简单且应景地说,是一种分布式的社会网络应用)。我也仅仅是他们中普通的一员(注册域名碰巧是当时我的一项任务)。而且这一届在广州的年会的组织工作,我并未参与。
年会不仅仅局限于blog本身,每年的年会都会在与blog和网络相关的新事物,新应用和新技术上做介绍,讨论甚至争论,比如2005年的标签,创作共用与版权的关系,Feed的烧制和聚合,2006年的OpenID,mashup,博客实名制,2007年的微blogging,互联网时代的NGO等,开放、协作,共享是年会最重要的主题。
所以,参会者是否用中文写blog还是blogger是否华人都不重要;把年会当作blogger们年度面对面交流沟通也好,网友间鹊桥会般的见面(Hi~ Bachus~~)也罢,创业者们炫自己的大作的机会(去年叽歪的大屏幕)也行,Geeks们秀新玩意的展台(嘿,我还记得某次会场上一水的MacBook)也可以,甚至一帮人扎堆凑热闹而找的借口(周Zola曙光喊着“杀人啦”奔向广州)都成……
哦,已经 D-Day - 4了……
P.S. 俺是男的,有证明的 :-D
十一月 2008 | ||||||
一 | 二 | 三 | 四 | 五 | 六 | 日 |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |