<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>{&#124;ihower.tw&#124; blog } &#187; Security</title>
	<atom:link href="http://ihower.tw/blog/archives/category/security/feed" rel="self" type="application/rss+xml" />
	<link>http://ihower.tw/blog</link>
	<description>Ruby, Ruby on Rails, Mac and Agile development</description>
	<lastBuildDate>Tue, 27 Jul 2010 06:48:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby on Rails Security 最佳實務</title>
		<link>http://ihower.tw/blog/archives/4096</link>
		<comments>http://ihower.tw/blog/archives/4096#comments</comments>
		<pubDate>Mon, 22 Mar 2010 16:36:39 +0000</pubDate>
		<dc:creator>ihower</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://ihower.tw/blog/?p=4096</guid>
		<description><![CDATA[這是我 2/26 在中研院 OSSF 工作坊和 3/23  在 Ruby Tuesday 所演講的題目之一。
Ruby on Rails 要談的 Security 網站安全，主要在 Web application layer 的範圍(這也是最容易被攻擊的部分)，像是 XSS、CSRF、Session Hijacking 跟 Fixation、SQL Injection 等等都是所有 Web 應用程式必須處理的問題。也有一些是 Rails 為了程式方便性而製造出來的問題，像是 Mass assignment、Unscoped finds、Controller Exposing methods 等等。
Rails Security
View more presentations from Wen-Tien Chang.

會講的內容看投影片就可以了，這裡我想特別提一下我的開場跟一個觀念:
我的開場引用了 PHP Security Guide: Overview 介紹什麼是 Security，我很喜歡：
1. 安全性是相對的，不是一個功能。碰過太多客戶要求 &#8220;網站要絕對安全，不能被 HACK&#8221;，這實在太強人所難了。安全性就跟溫度一樣，相對熱、相對冷。安全性也是相對安全、相對不安全的，而不是像功能說有或沒有。
2. 承上，要越安全，就給花越多成本去做。不過呢，不需要多花什麼錢，就可以很簡單做到足夠地安全。如果要非常非常安全，就會非常非常貴了。所以請考量你的預算。
3. 必須要與使用性(usability)做平衡。很多時候，安全性跟使用性會是衝突的，想要越多安全性，就給犧牲掉一些使用上的方便性。
4. 安全性必須是網站程式設計過程中的一部分，而不是最後才加上去。
而想提的寫程式觀念是我看 Security [...]]]></description>
			<content:encoded><![CDATA[<p>這是我 2/26 在中研院 OSSF 工作坊和 3/23  在 Ruby Tuesday 所演講的題目之一。</p>
<p>Ruby on Rails 要談的 Security 網站安全，主要在 Web application layer 的範圍(這也是最容易被攻擊的部分)，像是 XSS、CSRF、Session Hijacking 跟 Fixation、SQL Injection 等等都是所有 Web 應用程式必須處理的問題。也有一些是 Rails 為了程式方便性而製造出來的問題，像是 Mass assignment、Unscoped finds、Controller Exposing methods 等等。</p>
<div style="width:425px" id="__ss_3299368"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/ihower/rails-security-3299368" title="Rails Security">Rails Security</a></strong><object width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-security-2010226-100228083927-phpapp01&#038;stripped_title=rails-security-3299368" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-security-2010226-100228083927-phpapp01&#038;stripped_title=rails-security-3299368" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/ihower">Wen-Tien Chang</a>.</div>
</div>
<p>會講的內容看投影片就可以了，這裡我想特別提一下我的開場跟一個觀念:</p>
<p>我的開場引用了 <a href="http://phpsec.org/projects/guide/1.html#1.1">PHP Security Guide: Overview</a> 介紹什麼是 Security，我很喜歡：</p>
<p>1. 安全性是相對的，不是一個功能。碰過太多客戶要求 &#8220;網站要絕對安全，不能被 HACK&#8221;，這實在太強人所難了。安全性就跟溫度一樣，相對熱、相對冷。安全性也是相對安全、相對不安全的，而不是像功能說有或沒有。<br />
2. 承上，要越安全，就給花越多成本去做。不過呢，不需要多花什麼錢，就可以很簡單做到足夠地安全。如果要非常非常安全，就會非常非常貴了。所以請考量你的預算。<br />
3. 必須要與使用性(usability)做平衡。很多時候，安全性跟使用性會是衝突的，想要越多安全性，就給犧牲掉一些使用上的方便性。<br />
4. 安全性必須是網站程式設計過程中的一部分，而不是最後才加上去。</p>
<p>而想提的寫程式觀念是我看 <a href="http://www.pragprog.com/titles/fr_secure/security-on-rails">Security on Rails</a> 一書裡面介紹的 Fail Close，底下第一段是用 Fail open 觀念寫的程式，第二段是用 Fail close。</p>
<pre>
<code>
# fail open way, it’s bad
def show
  @invoice = Invoice.find(params[:id])
  unless @user.validate_code( @invoice.code )
    redirect_to :action => 'not_authorized'
  end
end
</code>
</pre>
<pre>
<code>
# fail close way
def show
  @invoice = Invoice.find(params[:id])
  if @user.validate_code( @invoice.code )
    redirect_to :action => 'authorized
  else
    redirect_to :action => 'not_authorized'
   end
end
</code>
</pre>
<p>其中的端倪就是，在撰寫驗證安全性程式碼的時候，請用 Fail close 的觀念：&#8221;如果條件成功，才允許進行，不然就不允許&#8221;。而不是 Fail open：&#8221;如果條件不成功，才不允許，不然就允許。&#8221;。這個簡單的撰碼觀念，可以減少我們寫出漏洞程式碼的機會。</p>
]]></content:encoded>
			<wfw:commentRss>http://ihower.tw/blog/archives/4096/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why &#8220;Not use default route&#8221;?</title>
		<link>http://ihower.tw/blog/archives/3265</link>
		<comments>http://ihower.tw/blog/archives/3265#comments</comments>
		<pubDate>Fri, 20 Nov 2009 17:14:41 +0000</pubDate>
		<dc:creator>ihower</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://ihower.tw/blog/?p=3265</guid>
		<description><![CDATA[In my Rails Best Practices slides, I only give simple code without any description (unless you heard my talk :p), so let me explain here.
my point is: &#8220;If you use RESTful design, you should NOT use default route.&#8221; Why?
For example:

   map.resources :users
   map.connect ':controller/:action/:id'
   map.connect ':controller/:action/:id.:format'

You expect only &#8220;PUT [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://ihower.tw/blog/archives/3075">Rails Best Practices</a> slides, I only give simple code without any description (unless you heard my talk :p), so let me explain here.</p>
<p>my point is: &#8220;If you use RESTful design, you should NOT use default route.&#8221; Why?</p>
<p>For example:</p>
<p><code><br />
   map.resources :users<br />
   map.connect ':controller/:action/:id'<br />
   map.connect ':controller/:action/:id.:format'<br />
</code></p>
<p>You expect only &#8220;PUT /users/1&#8243; will update user data,  but because you keep default route, so &#8220;GET /users/update/1?user[email]=foobar@example.org&#8221; still works!!  </p>
<p>In the same way, &#8220;GET /users/create&#8221; and &#8220;GET /users/destroy/1&#8243; works too!! Even worse, the latter can create/update/destroy data without Request Forgery Protection :/ Rails does not  check <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CRSF</a> for HTTP GET.</p>
<p>Conclusion: Remove default route, use purely resource-based routes and named routes for special purpose.</p>
]]></content:encoded>
			<wfw:commentRss>http://ihower.tw/blog/archives/3265/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Security Guide</title>
		<link>http://ihower.tw/blog/archives/1254</link>
		<comments>http://ihower.tw/blog/archives/1254#comments</comments>
		<pubDate>Sun, 22 Jan 2006 15:35:39 +0000</pubDate>
		<dc:creator>ihower</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://ihower.idv.tw/blog/archives/1254</guid>
		<description><![CDATA[這禮拜把 PHP Security Guide ( http://phpsec.org/projects/ ) 看完了，還蠻不錯的一份文件。
最基本步驟 1.考量壞心的使用者 2.要自我教育安全知識 3.過濾所有來自外部的資料。以下小記幾個重點:
1.Register Globals 造成的影響，建議開發時打開 E_ALL，初始所有變數。
2.介紹XSS攻擊。一定要過濾資料，並使用現成的PHP function來處理( htmlentities(),strip_tags(), utf8_decode() 等)，使用白名單而不用黑名單過濾。建議使用 naming convention 來幫忙區分資料，如 $clean 表示所有處理好的資料。
3.介紹CSRF攻擊。建議使用 post 方法而少用 get。使用 $_POSt 而非 $_REQUEST。接收表單時檢查來自正確的表單頁面(使用token技巧)
4.建議讓一些 library file 放在網站外，或是設定apache 讓 library 目錄不可讀取。而 database access 帳號密碼則建議用 root 另存文字檔，然後在 httpd.conf 中去讀取(還是要小心phpinfo會洩漏)。
5.介紹SQL Injection，用 mysql_escape_string() 來處理，不要用 addslashed() 。
6.介紹 Session Fixation ，建議在重要時刻(更改使用者權限的時候)隨時使用 session_regenerate_id() 換 SESSION ID。
7.預防 Session Hijacking ，使用能consistent的資料(如  HTTP_USER_AGENT)來確定使用者是同一人。
8.介紹Shared [...]]]></description>
			<content:encoded><![CDATA[<p>這禮拜把 PHP Security Guide ( <a href="http://phpsec.org/projects/">http://phpsec.org/projects/</a> ) 看完了，還蠻不錯的一份文件。</p>
<p>最基本步驟 1.考量壞心的使用者 2.要自我教育安全知識 3.<strong>過濾所有來自外部的資料</strong>。以下小記幾個重點:<span id="more-1254"></span></p>
<p>1.Register Globals 造成的影響，建議開發時打開 E_ALL，初始所有變數。</p>
<p>2.介紹<a href="http://ha.ckers.org/xss.html">XSS</a>攻擊。一定要過濾資料，並使用現成的PHP function來處理( htmlentities(),strip_tags(), utf8_decode() 等)，使用白名單而不用黑名單過濾。建議使用 naming convention 來幫忙區分資料，如 $clean 表示所有處理好的資料。</p>
<p>3.介紹CSRF攻擊。建議使用 post 方法而少用 get。使用 $_POSt 而非 $_REQUEST。接收表單時檢查來自正確的表單頁面(使用token技巧)</p>
<p>4.建議讓一些 library file 放在網站外，或是設定apache 讓 library 目錄不可讀取。而 database access 帳號密碼則建議用 root 另存文字檔，然後在 httpd.conf 中去讀取(還是要小心phpinfo會洩漏)。</p>
<p>5.介紹SQL Injection，用 mysql_escape_string() 來處理，<a href="http://shiflett.org/archive/184">不要用 addslashed()</a> 。</p>
<p>6.介紹 Session Fixation ，建議在重要時刻(更改使用者權限的時候)隨時使用 session_regenerate_id() 換 SESSION ID。</p>
<p>7.預防 Session Hijacking ，使用能consistent的資料(如  HTTP_USER_AGENT)來確定使用者是同一人。</p>
<p>8.介紹Shared Hosts的危險。建議 session data可以放到資料庫而不要放 /tmp。使用 safe_mode來限制 PHP。</p>
]]></content:encoded>
			<wfw:commentRss>http://ihower.tw/blog/archives/1254/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MD5 資料庫</title>
		<link>http://ihower.tw/blog/archives/1171</link>
		<comments>http://ihower.tw/blog/archives/1171#comments</comments>
		<pubDate>Tue, 23 Aug 2005 23:18:25 +0000</pubDate>
		<dc:creator>ihower</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[WWW]]></category>

		<guid isPermaLink="false">http://ihower.idv.tw/blog/?p=1184</guid>
		<description><![CDATA[http://gdataonline.com/seekhash.php
太恐怖了&#8230; 你可以試著把MD5丟進去&#8230;
如果可以被找出來反譯&#8230; 趕快換密碼吧!!~~
]]></description>
			<content:encoded><![CDATA[<p>http://gdataonline.com/seekhash.php</p>
<p>太恐怖了&#8230; 你可以試著把MD5丟進去&#8230;<br />
如果可以被找出來反譯&#8230; 趕快換密碼吧!!~~</p>
]]></content:encoded>
			<wfw:commentRss>http://ihower.tw/blog/archives/1171/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
