background preloader

Ruby

Facebook Twitter

Magazine - Rubyist のための他言語探訪 【第 3 回】 Io. ScRUBYt! - a Simple to Learn and Use, yet Powerful Web Scraping Toolkit Written in Ruby. REXMLのDoS脆弱性. Rubyの標準ライブラリに含まれているREXMLに、DoS脆弱性が発見されました。 XML entity explosion attackと呼ばれる攻撃手法により、ユーザから与えられ たXMLを解析するようなアプリケーションをサービス不能(DoS)状態にすること ができます。 Railsはデフォルトの状態でユーザから与えられたXMLを解析するため、大部分の Railsアプリケーションはこの攻撃に対して脆弱です。

影響 攻撃者は、以下のように再帰的にネストした実体参照を含むXML文書をREXMLに 解析させることにより、サービス不能(DoS)状態を引き起こすことができます。 <? 脆弱性の存在するバージョン 1.8系 1.8.6-p287以前のすべてのバージョン 1.8.7-p72以前のすべてのバージョン 1.9系 すべてのバージョン 対処方法 問題を修正するためのモンキーパッチ(実行時にライブラリを修正するパッチ)をダウンロードしてください。 REXMLを使用する前にrexml-expansion-fix2.rbをロードするように、あなたのアプリケーションを修正してください。 Require "rexml-expansion-fix2" ... doc = REXML::Document.new(str) ... Railsアプリケーションを利用している場合、rexml-expansion-fix2.rbをロード パス上のディレクトリ(たとえばRAILS_ROOT/lib/)にコピーし、次のような行を config/environment.rbに追加してください。 Require "rexml-expansion-fix2" Rails 2.1以降の場合、rexml-expansion-fix2.rbを RAILS_ROOT/config/initializersにコピーするだけで自動的にロードされます。 デフォルトでは、XML実体参照の展開は10000回に制限されます。 REXML::Document.entity_expansion_limit = 1000 この修正はgemパッケージとして提供され、Railsの将来のバージョンで利用さ れるようになる予定ですが、ただちに対策されることを推奨します。

クレジット 変更履歴. The Ruby Toolbox - Know your options! Replacing methods. Let's say we want to replace a method instead of just throwing it away. But we want the new method to be able to call the old implementation. The standard way of doing this is by aliasing the old method and making the new one call the aliased version: class Foo def method ... end class Foo alias :method :old_method def method ... old_method endend This solution works perfectly for most situations, but what if we want to remove all traces of the old method? Here's a simple trick to do exactly that: class Foo old_method = instance_method(:method) define_method(:method) { |*args| # do something here ... old_method.bind(self).call(*args) }end It shouldn't take much to understand how it works, but let's analyze it in more detail.

Next, we redefine method and pass it a block with the new implementation. After doing whatever it has to do, the new method calls the old one after binding the UnboundMethod to the current object (i.e., the object on which method was invoked). Labels: ruby. Mr. Neighborly&#039;s Humble Little Ruby Book by Jeremy McAnally (Book) in. Try ruby! (in your browser) Rolling with Ruby on Rails. By Curt Hibbs 01/20/2005 Editor's note: Curt Hibbs and Bill Walton have updated this tutorial for Rails 1.2 in Rolling with Ruby on Rails Revisited and Rolling with Ruby on Rails Revisited, Part Two.

We recommend those tutorials for all new Rails development. Also check out Bill Walton's monthly series, Cookin' With Ruby on Rails. Maybe you've heard about Ruby on Rails, the super productive new way to develop web applications, and you'd like to give it a try, but you don't know anything about Ruby or Rails. This article steps through the development of a web application using Rails. It won't teach you how to program in Ruby, but if you already know another object-oriented programming language, you should have no problem following along (and at the end you can find links on learning Ruby). Let's answer a couple of burning questions before rolling up our sleeves to build a web application! What is Ruby? What is Rails? Part of the answer is in the Ruby programming language. Seeing is Believing. Programming Ruby.