@@ -40,67 +40,72 @@ Level 0 is the normal program environment and the security system is not
40
40
running. Level 2 handles dangerous values. Level 4 handles dangerous code.
41
41
We can skip 0 and move on to explain in detail levels 2 and 4.
42
42
43
- h4. レベル2
43
+ h4. Level 2
44
44
45
- 危険な値に対処するためのレベル。通常のCGIなど。
45
+ This level is for dangerous data, for example, in normal CGI
46
+ applications, etc.
46
47
47
- レベル2の基礎をなすのはオブジェクト単位で記憶されている汚染マークであ
48
- る。外部から読み込んだオブジェクト全部に汚染マークを付けておき、汚染さ
49
- れたオブジェクトを `eval`しようとしたり `File.open`しようとしたら例外を発生
50
- させて止める。
48
+ A per-object "dirty mark" serves as the basis for the Level 2
49
+ implementation. All objects read in externally are marked dirty, and
50
+ any attempt to `eval` or `File.open` with a dirty object will cause an
51
+ exception to be raised and the attempt will be stopped.
51
52
52
- それと汚染マークは「感染」する。例えば汚染した文字列の
53
- 一部を取ると、それもやはり汚染されている。
53
+ This dirty mark is "infectious". For example, when taking a part of a
54
+ dirty string, that part is also dirty.
54
55
55
- h4. レベル4
56
+ h4. Level 4
56
57
57
- 危険なプログラムに対処するためのレベル。
58
- 外部から持ってきた(素性の知れない)プログラムの実行など。
58
+ This level is for dangerous programs, for example, running external
59
+ (unknown) programs, etc.
59
60
60
- レベル2では操作とそれに使う値の両方でチェックしていたわけだが、
61
- レベル4に
62
- なると操作だけで禁止対象になる。例えば`exit`、ファイルI/O、スレッド
63
- 操作、メソッド定義の変更、などなど。もちろん汚染情報も多少は使うのだが、
64
- 基本的には操作が基準になる。
61
+ At level 2, operations and the data it uses are checked, but at level
62
+ 4, operations themselves are restricted. For example, `exit`, file
63
+ I/O, thread manipulation, redefining methods, etc. Of course, the
64
+ dirty mark information is used, but basically the operations are the
65
+ criteria.
65
66
66
- h4. セキュリティ単位
67
+ h4. Unit of Security
67
68
68
- `$SAFE`は見ためはグローバル変数だが実はスレッドローカルである。つまり
69
- Rubyのセキュリティシステムはスレッド単位で働く。Javaや.NETだとコンポー
70
- ネント(オブジェクト)単位で権限が設定できるが、Rubyはそこまではやって
71
- いない。想定するメインターゲットがCGIだからだろう。
69
+ `$SAFE` looks like a global variable but is in actuality a thread
70
+ local variable. In other words, Ruby's security system works on units
71
+ of thread. In Java and .NET, rights can be set per component (object),
72
+ but Ruby does not implement that. The assumed main target was probably
73
+ CGI.
72
74
73
- だからプログラムの一部分だけセキュリティレベルを上げたい、
74
- という場合は別スレッドにしてレ
75
- ベルを分離する。スレッドの作りかたなんてまだ説明していないわけだが、と
76
- りあえず以下の例だけで我慢しておいてほしい。
75
+ Therefore, if one wants to raise the security level of one part of the
76
+ program, then it should be made into a different thread and have its
77
+ security level raised. I haven't yet explained how to create a thread,
78
+ but I will show an example here:
77
79
78
80
<pre class="emlist">
79
- # 別スレッドでセキュリティレベルを上げる
80
- p($SAFE) # デフォルトは0
81
- Thread.fork { # 別スレッドを起動して
82
- $SAFE = 4 # レベルを上げて
83
- eval(str) # 危険なプログラムを実行
81
+ # Raise the security level in a different thread
82
+ p($SAFE) # 0 is the default
83
+ Thread.fork { # Start a different thread
84
+ $SAFE = 4 # Raise the level
85
+ eval(str) # Run the dangerous program
84
86
}
85
- p($SAFE) # ブロックの外ではレベル0のまま
87
+ p($SAFE) # Outside of the block, the level is still 0
86
88
</pre>
87
89
88
- h4. `$SAFE`の信頼性
89
-
90
- 汚染マークの感染にしても操作の禁止にしても最終的には全て手作業で行われ
91
- ている。つまり使っている全ての組み込みライブラリと拡張ライブラリが抜け
92
- なく対処しないと途中で汚染が途切れ、安全ではなくなる。そして実際にそう
93
- いう穴はよく報告されている。だからとりあえず、筆者はあまり信用していな
94
- い。
95
-
96
- もっとも、だからと言って全てのRubyプログラムが危険であるわけでは、もち
97
- ろんない。`$SAFE=0`でも安全なプログラムは書けるし、`$SAFE=4`でも好き放
98
- 題できるプログラムは書ける。ただ`$SAFE`は(まだ)過信できないというだ
99
- けだ。
100
-
101
- そもそも「活発な機能追加」と「セキュリティ」が両立するわけがない。どん
102
- どん新機能が付け加わっているのならそれに比例して穴も開きやすくなるとい
103
- うのは常識である。ならば当然`ruby`も危険だろうと考えるべきだ。
90
+ h4. Reliability of `$SAFE`
91
+
92
+ Even with implementing the spreading of dirty marks, or restricting
93
+ operations, ultimately it is still handled manually. In other words,
94
+ internal libraries and external libraries must be completely
95
+ compatible and if they don't, then the partway the "dirty" operations
96
+ will not spread and the security will be lost. And actually this kind
97
+ of hole is often reported. For this reason, this writer does not
98
+ wholly trust it.
99
+
100
+ That is not to say, of course, that all Ruby programs are dangerous.
101
+ Even at `$SAFE=0` it is possible to write a secure program, and even
102
+ at `$SAFE=4` it is possible to write a program that fits your whim.
103
+ However, one cannot put too much confidence on `$SAFE` (yet).
104
+
105
+ In the first place, functionality and security do not go together. It
106
+ is common sense that adding new features can make holes easier to
107
+ open. Therefore it is prudent to think that `ruby` can probably be
108
+ dangerous.
104
109
105
110
h3. 実装
106
111
0 commit comments