perlsec > 5.10.0 との差分

perlsec 5.10.0 と 5.36.0 の差分

11
2=encoding euc-jp
2=encoding utf8
33
44=head1 NAME
55
66=begin original
77
88perlsec - Perl security
99
1010=end original
1111
1212perlsec - Perl のセキュリティ
1313
1414=head1 DESCRIPTION
1515
1616=begin original
1717
1818Perl is designed to make it easy to program securely even when running
1919with extra privileges, like setuid or setgid programs. Unlike most
2020command line shells, which are based on multiple substitution passes on
2121each line of the script, Perl uses a more conventional evaluation scheme
2222with fewer hidden snags. Additionally, because the language has more
2323builtin functionality, it can rely less upon external (and possibly
2424untrustworthy) programs to accomplish its purposes.
2525
2626=end original
2727
28Perlは、プログラムが setuid や setgid されるような特別な権限を付加されて
29Perl は、プログラムが setuid や setgid されるような特別な権限を付加されて
2930実行されたときでもセキュリティ保持が容易になるように設計されています。
3031スクリプトの一行ごとの多重置換を行うことに基づいているような大部分の
3132コマンドラインシェルとは違って、Perl は隠れた障害が少ないような、
3233より便利な評価手法を用いています。
3334それに加えて Perl はより多くの組み込み関数を持っているので、
3435ある目的を達成するために(信頼できないかもしれないような)
3536外部プログラムを使うことが少なくてすむのです。
3637
38=head1 SECURITY VULNERABILITY CONTACT INFORMATION
39
40(セキュリティ脆弱性連絡窓口)
41
3742=begin original
3843
44If you believe you have found a security vulnerability in the Perl
45interpreter or modules maintained in the core Perl codebase,
46email the details to
47L<perl-security@perl.org|mailto:perl-security@perl.org>.
48This address is a closed membership mailing list monitored by the Perl
49security team.
50
51=end original
52
53Perl インタプリタや、コア Perl コードベースで管理しているモジュールの
54セキュリティ脆弱性を発見したと確信したときには、詳細を
55L<perl-security@perl.org|mailto:perl-security@perl.org> に
56メールしてください。
57このアドレスは Perl セキュリティチームによって監視されている、
58閉じられたメンバーのメーリングリストです。
59
60=begin original
61
62See L<perlsecpolicy> for additional information.
63
64=end original
65
66追加の情報については L<perlsecpolicy> を参照してください。
67
68=head1 SECURITY MECHANISMS AND CONCERNS
69
70=head2 Taint mode
71
72(汚染モード)
73
74=begin original
75
76By default,
3977Perl automatically enables a set of special security checks, called I<taint
4078mode>, when it detects its program running with differing real and effective
4179user or group IDs. The setuid bit in Unix permissions is mode 04000, the
4280setgid bit mode 02000; either or both may be set. You can also enable taint
43mode explicitly by using the B<-T> command line flag. This flag is
81mode explicitly by using the B<-T> command line flag. This flag is
4482I<strongly> suggested for server programs and any program run on behalf of
45someone else, such as a CGI script. Once taint mode is on, it's on for
83someone else, such as a CGI script. Once taint mode is on, it's on for
4684the remainder of your script.
4785
4886=end original
4987
50Perl は、そのプログラムが異なる実ユーザー ID、実効ユーザー ID、実グープ ID
88Perl はデフォトでは
89そのプログラムが異なる実ユーザー ID、実効ユーザー ID、実グループ ID、
5190実効グループ ID を使って実行されることを検出したときに、
5291自動的に I<汚染モード> (taint mode) と呼ばれる特別なセキュリティチェックの
5392セットを有効にします。
5493UNIX パーミッションにおける setuid ビットはモード 04000 で、
5594setgid ビットはモード 02000 です。
5695これらは重複してセットすることもできます。
5796汚染モードは、コマンドラインフラグ B<-T> を使って陽に有効にすることもできます。
5897このフラグはサーバープログラムであるとか、
5998CGI スクリプトのような、他の誰かにすりかわって実行されるプログラムに
6099使うことを B<強く> 勧めます。
61100
62101=begin original
63102
64103While in this mode, Perl takes special precautions called I<taint
65104checks> to prevent both obvious and subtle traps. Some of these checks
66105are reasonably simple, such as verifying that path directories aren't
67106writable by others; careful programmers have always used checks like
68107these. Other checks, however, are best supported by the language itself,
69108and it is these checks especially that contribute to making a set-id Perl
70109program more secure than the corresponding C program.
71110
72111=end original
73112
74113このモードで動作しているとき、Perl は明白な罠と隠れた罠の両方に対処するために
75114I<汚染検査> (taint check) と呼ばれる特別な警戒を行います。
76これらのチェックの幾つかは、単純です
115これらのチェックの幾つかは、単純です; path ディレクトリが他から書き込み
77path ディレクトリが他から書き込み可能でないことを検査するといったことがそうです
116可能でないことを検査するといったことがそうです; 注意深いプログラマーは常に
78注意深いプログラマーは常にこれらのことはチェックしています。
117これらのことはチェックしています。
79このほかのチェックはしかしながら、言語自身によって最も良くサポートされます
118このほかのチェックはしかしながら、言語自身によって最も良くサポートされます;
80そして、これらのチェックは特に set-id された Perl プログラムを
119そして、これらのチェックは特に set-id された Perl プログラムを対応する
81対応する C プログラムよりも安全にするのに貢献するのです。
120C プログラムよりも安全にするのに貢献するのです。
82121
83122=begin original
84123
85124You may not use data derived from outside your program to affect
86125something else outside your program--at least, not by accident. All
87126command line arguments, environment variables, locale information (see
88127L<perllocale>), results of certain system calls (C<readdir()>,
89128C<readlink()>, the variable of C<shmread()>, the messages returned by
90129C<msgrcv()>, the password, gcos and shell fields returned by the
91130C<getpwxxx()> calls), and all file input are marked as "tainted".
92131Tainted data may not be used directly or indirectly in any command
93132that invokes a sub-shell, nor in any command that modifies files,
94133directories, or processes, B<with the following exceptions>:
95134
96135=end original
97136
98137自分のプログラムの外側から来たデータをプログラムの外の何かに影響を
99138及ぼすために使うことは、少なくともアクシデントででもなければ、できません。
100139すべてのコマンドライン引数、環境変数、ロケール情報(L<perllocale> を参照)、
101140幾つかのシステムコールの結果(C<readdir()>, C<readlink()>, C<shmread()> の変数、
102141C<msgrcv()> が返したメッセージ、パスワード、C<getpwxxx()> 呼び出しが返した
103142gecos フィールドとシェルフィールド)、すべてのファイル入力といったものは
104143“汚染された”(tainted) と目印が付けられます。
105144汚染されたデータは直接、間接を問わずサブシェルを起動するコマンドに使うことも、
106145ファイルやディレクトリ、プロセスに変更を加えるようなコマンドに
107使うこともできません。
146使うこともできません; 但し B<以下の例外> があります
108但し B<以下の例外> があります。
109147
148=begin original
149
150Support for taint checks adds an overhead to all Perl programs,
151whether or not you're using the taint features.
152Perl 5.18 introduced C preprocessor symbols that can
153be used to disable the taint features.
154
155=end original
156
157汚染チェック対応は、汚染チェック機能をを使うかどうかに関わらず、
158全ての Perl プログラムにオーバーヘッドを追加します。
159Perl 5.18 では、汚染チェック機能を無効にするために使える
160C プリプロセッサシンボルが導入されました。
161
110162=over 4
111163
112164=item *
113165
114166=begin original
115167
116168Arguments to C<print> and C<syswrite> are B<not> checked for taintedness.
117169
118170=end original
119171
120172C<print> と C<syswrite> の引数に対する汚染検査は B<行われません>。
121173
122174=item *
123175
124176=begin original
125177
126178Symbolic methods
127179
128180=end original
129181
130182シンボリックメソッド
131183
132184 $obj->$method(@args);
133185
134186=begin original
135187
136188and symbolic sub references
137189
138190=end original
139191
140192とシンボリックサブルーチンリファレンス
141193
142194 &{$foo}(@args);
143195 $foo->(@args);
144196
145197=begin original
146198
147199are not checked for taintedness. This requires extra carefulness
148200unless you want external data to affect your control flow. Unless
149201you carefully limit what these symbolic values are, people are able
150202to call functions B<outside> your Perl code, such as POSIX::system,
151203in which case they are able to run arbitrary external code.
152204
153205=end original
154206
155207は汚染性がチェックされません。
156208これは、あなたの制御フローが外部データに影響されたいと思わないなら、
157209さらなる慎重さを要求します。
158210これらのシンボリックな値が何かを注意深く制限しないと、POSIX::system のような
159211あなたの Perl コードの B<外側> の関数を呼び出すことを可能にし、この場合
160212任意の外部コードを実行できるようになります。
161213
162214=item *
163215
164216=begin original
165217
166218Hash keys are B<never> tainted.
167219
168220=end original
169221
170222ハッシュのキーは B<決して> 汚染されません。
171223
172224=back
173225
174226=begin original
175227
176228For efficiency reasons, Perl takes a conservative view of
177229whether data is tainted. If an expression contains tainted data,
178230any subexpression may be considered tainted, even if the value
179231of the subexpression is not itself affected by the tainted data.
180232
181233=end original
182234
183235効率上の理由から、Perl はデータが汚染されているかどうかについて保守的な
184236見方をします。
185237汚染されているデータが式に含まれている場合、たとえ副式の値自身は汚染された
186238データに影響を受けない場合でも、全ての副式も汚染されたものとして
187239扱います。
188240
189241=begin original
190242
191243Because taintedness is associated with each scalar value, some
192244elements of an array or hash can be tainted and others not.
193245The keys of a hash are B<never> tainted.
194246
195247=end original
196248
197249汚染は各スカラ値に結び付けられるので、配列の幾つかの要素が汚染されていて、
198250そのほかの要素はそうではないということもありえます。
199251ハッシュのキーは B<決して> 汚染されません。
200252
201253=begin original
202254
203255For example:
204256
205257=end original
206258
207259例を示します:
208260
209261=begin original
210262
211263 $arg = shift; # $arg is tainted
212 $hid = $arg, 'bar'; # $hid is also tainted
264 $hid = $arg . 'bar'; # $hid is also tainted
213265 $line = <>; # Tainted
214266 $line = <STDIN>; # Also tainted
215267 open FOO, "/home/me/bar" or die $!;
216268 $line = <FOO>; # Still tainted
217269 $path = $ENV{'PATH'}; # Tainted, but see below
218270 $data = 'abc'; # Not tainted
219271
220272=end original
221273
222274 $arg = shift; # $arg は汚染された
223 $hid = $arg, 'bar'; # $hid も汚染された
275 $hid = $arg . 'bar'; # $hid も汚染された
224276 $line = <>; # 汚染された
225277 $line = <STDIN>; # これも汚染された
226278 open FOO, "/home/me/bar" or die $!;
227279 $line = <FOO>; # まだ汚染されている
228280 $path = $ENV{'PATH'}; # 汚染されているが、下記を参照のこと
229281 $data = 'abc'; # 汚染されていない
230282
231283=begin original
232284
233285 system "echo $arg"; # Insecure
234286 system "/bin/echo", $arg; # Considered insecure
235287 # (Perl doesn't know about /bin/echo)
236288 system "echo $hid"; # Insecure
237289 system "echo $data"; # Insecure until PATH set
238290
239291=end original
240292
241293 system "echo $arg"; # 安全ではない
242294 system "/bin/echo", $arg; # 安全ではないと考えられる
243295 # (Perl は /bin/echo について知らない)
244296 system "echo $hid"; # 安全ではない
245297 system "echo $data"; # PATHを設定するまでは安全ではない
246298
247299=begin original
248300
249301 $path = $ENV{'PATH'}; # $path now tainted
250302
251303=end original
252304
253305 $path = $ENV{'PATH'}; # $path が汚染された
254306
255307 $ENV{'PATH'} = '/bin:/usr/bin';
256308 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
257309
258310=begin original
259311
260312 $path = $ENV{'PATH'}; # $path now NOT tainted
261313 system "echo $data"; # Is secure now!
262314
263315=end original
264316
265317 $path = $ENV{'PATH'}; # $path は汚染されていない
266318 system "echo $data"; # これで安全!
267319
268320=begin original
269321
270322 open(FOO, "< $arg"); # OK - read-only file
271323 open(FOO, "> $arg"); # Not OK - trying to write
272324
273325=end original
274326
275327 open(FOO, "< $arg"); # OK - 読み込みのみのファイル
276328 open(FOO, "> $arg"); # Not OK - 書き込みしようとしている
277329
278330 open(FOO,"echo $arg|"); # Not OK
279331 open(FOO,"-|")
280332 or exec 'echo', $arg; # Also not OK
281333
282334=begin original
283335
284336 $shout = `echo $arg`; # Insecure, $shout now tainted
285337
286338=end original
287339
288 $shout = `echo $arg`; # 安全でない$shoutは汚染された
340 $shout = `echo $arg`; # 安全でない; $shoutは汚染された
289341
290342=begin original
291343
292344 unlink $data, $arg; # Insecure
293345 umask $arg; # Insecure
294346
295347=end original
296348
297349 unlink $data, $arg; # 安全でない
298350 umask $arg; # 安全でない
299351
300352=begin original
301353
302354 exec "echo $arg"; # Insecure
303355 exec "echo", $arg; # Insecure
304356 exec "sh", '-c', $arg; # Very insecure!
305357
306358=end original
307359
308360 exec "echo $arg"; # 安全でない
309361 exec "echo", $arg; # 安全でない
310362 exec "sh", '-c', $arg; # とても安全ではない!
311363
312364=begin original
313365
314366 @files = <*.c>; # insecure (uses readdir() or similar)
315367 @files = glob('*.c'); # insecure (uses readdir() or similar)
316368
317369=end original
318370
319371 @files = <*.c>; # 安全でない (readdir() のようなものを使う)
320372 @files = glob('*.c'); # 安全でない (readdir() のようなものを使う)
321373
322 # In Perl releases older than 5.6.0 the <*.c> and glob('*.c') would
374=begin original
323 # have used an external program to do the filename expansion; but in
324 # either case the result is tainted since the list of filenames comes
325 # from outside of the program.
326375
376 # In either case, the results of glob are tainted, since the list of
377 # filenames comes from outside of the program.
378
379=end original
380
381 # どちらの場合でも、glob の結果は汚染されています; ファイル名の一覧は
382 # プログラムの外部から来るからです。
383
327384=begin original
328385
329386 $bad = ($arg, 23); # $bad will be tainted
330387 $arg, `true`; # Insecure (although it isn't really)
331388
332389=end original
333390
334391 $bad = ($arg, 23); # $bad は汚染されているかも
335392 $arg, `true`; # 安全でない (実際はそうでなくても)
336393
337394=begin original
338395
339396If you try to do something insecure, you will get a fatal error saying
340397something like "Insecure dependency" or "Insecure $ENV{PATH}".
341398
342399=end original
343400
344401安全でないことをやろうとすると、"Insecure dependency" や
345402"Insecure $ENV{PATH}" のような致命的エラーとなるでしょう。
346403
347404=begin original
348405
349406The exception to the principle of "one tainted value taints the whole
350407expression" is with the ternary conditional operator C<?:>. Since code
351408with a ternary conditional
352409
353410=end original
354411
355The exception to the principle of "one tainted value taints the whole
412「一つの汚染された値が式全体を汚染する」の原則の例外は、3 項条件演算子
356expression" is with the ternary conditional operator C<?:>.
413C<?:> です。
3574143 項条件を使ったコード
358415
359416 $result = $tainted_value ? "Untainted" : "Also untainted";
360417
361418=begin original
362419
363420is effectively
364421
365422=end original
366423
367424というのは事実上
368425
369426 if ( $tainted_value ) {
370427 $result = "Untainted";
371428 } else {
372429 $result = "Also untainted";
373430 }
374431
375432=begin original
376433
377434it doesn't make sense for C<$result> to be tainted.
378435
379436=end original
380437
381438なので、C<$result> が汚染されたと考えるのは意味がありません。
382439
383440=head2 Laundering and Detecting Tainted Data
384441
385442(汚染されたデータの検出と洗浄)
386443
387444=begin original
388445
389446To test whether a variable contains tainted data, and whose use would
390447thus trigger an "Insecure dependency" message, you can use the
391448C<tainted()> function of the Scalar::Util module, available in your
392449nearby CPAN mirror, and included in Perl starting from the release 5.8.0.
393450Or you may be able to use the following C<is_tainted()> function.
394451
395452=end original
396453
397454ある変数が汚染されたデータを保持しているかどうかを検査するため、そして、
398455"Insecure dependency" メッセージの引き金になる可能性があるかどうかを
399456検査するために、CPAN にあり、5.8.0 からは Perl に含まれている
400457Scalar::Util モジュールの C<tainted()> 関数を使えます。
401458あるいは、以下のような関数 C<is_tainted()> を使うことができます。
402459
403460 sub is_tainted {
461 local $@; # Don't pollute caller's value.
404462 return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
405463 }
406464
407465=begin original
408466
409467This function makes use of the fact that the presence of tainted data
410468anywhere within an expression renders the entire expression tainted. It
411469would be inefficient for every operator to test every argument for
412470taintedness. Instead, the slightly more efficient and conservative
413471approach is used that if any tainted value has been accessed within the
414472same expression, the whole expression is considered tainted.
415473
416474=end original
417475
418476この関数はある式のどこかにある汚染されたデータが式全体を汚染してしまうことを
419477利用しています。
420478これはすべての演算子に対して、そのすべての引数が汚染されているかどうかの
421479検査をするので効率は良くないでしょう。
422480その代わりに、一部の式において汚染された値にアクセスして式全体が
423481汚染されたとみなされるような場合には、もっと効率が良くて
424482保守的な方法が使われます。
425483
426484=begin original
427485
428486But testing for taintedness gets you only so far. Sometimes you have just
429487to clear your data's taintedness. Values may be untainted by using them
430488as keys in a hash; otherwise the only way to bypass the tainting
431489mechanism is by referencing subpatterns from a regular expression match.
432Perl presumes that if you reference a substring using $1, $2, etc., that
490Perl presumes that if you reference a substring using $1, $2, etc. in a
433you knew what you were doing when you wrote the pattern. That means using
491non-tainting pattern, that
492you knew what you were doing when you wrote that pattern. That means using
434493a bit of thought--don't just blindly untaint anything, or you defeat the
435494entire mechanism. It's better to verify that the variable has only good
436495characters (for certain values of "good") rather than checking whether it
437496has any bad characters. That's because it's far too easy to miss bad
438497characters that you never thought of.
439498
440499=end original
441500
442501しかし、汚染の検査は面倒です。
443502あなたのデータの汚染を取り除くだけということもあるでしょう。
444503値はハッシュのキーとして使うことで浄化されます; さもなければ、
445504汚染検査機構をバイパスするためのただ一つの方法は、
446505マッチした正規表現のサブパターンを参照することです。
447Perl は、あなたが $1、$2 などを使って部分文字列を参照したときに、
506Perl は、あなたが $1、$2 などを使って汚染されていないパターンで部分文字列を
448あなたがパターンを記述したときに何を行うのかを知っていたと仮定します。
507参照したときに、あなたがパターンを記述したときに何を行うのかを知っていたと
449つまり、汚染されていないものを束縛ないか、機構全体を無効にするということです。
508仮定す。
509つまり、汚染されていないものを束縛しないか、機構全体を
510無効にするということです。
450511これは、変数がなんらかの悪い文字を持っているかどうかを
451検査するというのではなく、変数が良い文字のみを持っていることの
512検査するというのではなく、変数が良い文字のみを持っていることの検査には
452検査には都合が良いです。
513都合が良いです。
453514これは(あなたが考えもしないような)悪い文字を見失うことがあまりにも
454515簡単であるからです。
455516
456517=begin original
457518
458519Here's a test to make sure that the data contains nothing but "word"
459520characters (alphabetics, numerics, and underscores), a hyphen, an at sign,
460521or a dot.
461522
462523=end original
463524
464525以下に示す例は、データに“語”(アルファベット、数字、アンダースコア)の
465526文字、ハイフン、アットマーク、ドット以外のものが入っていないことを
466527検査するものです。
467528
468529 if ($data =~ /^([-\@\w.]+)$/) {
469530 $data = $1; # $data now untainted
470531 } else {
471532 die "Bad data in '$data'"; # log this somewhere
472533 }
473534
474535=begin original
475536
476537This is fairly secure because C</\w+/> doesn't normally match shell
477538metacharacters, nor are dot, dash, or at going to mean something special
478539to the shell. Use of C</.+/> would have been insecure in theory because
479540it lets everything through, but Perl doesn't check for that. The lesson
480541is that when untainting, you must be exceedingly careful with your patterns.
481542Laundering data using regular expression is the I<only> mechanism for
482543untainting dirty data, unless you use the strategy detailed below to fork
483544a child of lesser privilege.
484545
485546=end original
486547
487これはかなり安全です
548これはかなり安全です; なぜなら C<\w+> は通常シェルのメタ文字には
488なぜなら C<\w+> は通常シェルのメタ文字には
489549マッチしませんし、ドットやダッシュなどのシェルにとって特別な意味を
490550持つようなものにもマッチしないからです。
491551C</.+/> を使うのは、これはすべてを通してしまうのに Perl はそれを
492552チェックしませんから、理論的には安全ではありません。
493553汚染を取り除くときには、自分のパターンについて十二分に注意せねばなりません。
494554正規表現を使ったデータの洗浄は、先に説明したより低い特権度の子プロセスを
495555fork するための戦略を使うまでは汚れたデータの汚染除去 B<のみ> の機構です。
496556
497557=begin original
498558
499559The example does not untaint C<$data> if C<use locale> is in effect,
500560because the characters matched by C<\w> are determined by the locale.
501561Perl considers that locale definitions are untrustworthy because they
502562contain data from outside the program. If you are writing a
503563locale-aware program, and want to launder data with a regular expression
504564containing C<\w>, put C<no locale> ahead of the expression in the same
505565block. See L<perllocale/SECURITY> for further discussion and examples.
506566
507567=end original
508568
509先の例では、C<use locale> が有効であるときには C<$data> の
569先の例では、C<use locale> が有効であるときには C<$data> の汚染除去を
510汚染除去を行いません
570行いません; なぜなら、C<\w> にマッチする文字はロケールによって
511なぜなら、C<\w> にマッチする文字はロケールによって決定されるからです。
571決定されるからです。
512572Perl は、ロケールで決まることを、それがプログラムの外から来たデータから
513573構成されているという理由によって信用できないものとみなします。
514574もしロケールを考慮したプログラムを書いていて、C<\w> を含んだ正規表現で
515575データの洗浄を行いたいというのなら、式の置かれたのと同じブロックの前の部分に
516576C<no locale>を置きます。
517577L<perllocale/SECURITY> に詳しい説明と例があります。
518578
519579=head2 Switches On the "#!" Line
520580
521581("#!" 行のスイッチ)
522582
523583=begin original
524584
525585When you make a script executable, in order to make it usable as a
526586command, the system will pass switches to perl from the script's #!
527587line. Perl checks that any command line switches given to a setuid
528588(or setgid) script actually match the ones set on the #! line. Some
529589Unix and Unix-like environments impose a one-switch limit on the #!
530590line, so you may need to use something like C<-wU> instead of C<-w -U>
531591under such systems. (This issue should arise only in Unix or
532592Unix-like environments that support #! and setuid or setgid scripts.)
533593
534594=end original
535595
536596自分の作ったスクリプトをコマンドのように使えるようにしたとき、システムは
537597perl に対して、スクリプトの #! の行からコマンドラインスイッチを渡します。
538598Perl は、setuid(あるいは setgid) されたスクリプトに与えられた
539599コマンドラインスイッチが #! 行にあるものと本当に一致するかどうかを検査します。
540600一部の UNIX や UNIX 風の環境では #! 行には一つのスイッチしか置けないので、
541601そういったシステムでは C<-w -U> といった形式ではなく
542C<-wU> のようにする必要があるでしょう(これは #! をサポートしていて、
602C<-wU> のようにする必要があるでしょう
543setuid や setgid スクリプトが使える UNIX 環境や UNIX に似た環境でのみ
603(これは #! をサポートしていて、setuid や setgid スクリプトが使える
544行なわれることです)
604UNIX 環境や UNIX に似た環境でのみ行なわれることです。)
545605
546606=head2 Taint mode and @INC
547607
548608(汚染検査モードと @INC)
549609
550610=begin original
551611
552When the taint mode (C<-T>) is in effect, the "." directory is removed
612+When the taint mode (C<-T>) is in effect, the environment variables
553from C<@INC>, and the environment variables C<PERL5LIB> and C<PERLLIB>
613+C<PERL5LIB>, C<PERLLIB>, and C<PERL_USE_UNSAFE_INC>
554are ignored by Perl. You can still adjust C<@INC> from outside the
614are ignored by Perl. You can still adjust C<@INC> from outside the
555615program by using the C<-I> command line option as explained in
556L<perlrun>. The two environment variables are ignored because
616L<perlrun|perlrun/-Idirectory>. The two environment variables are
557they are obscured, and a user running a program could be unaware that
617ignored because they are obscured, and a user running a program could
558they are set, whereas the C<-I> option is clearly visible and
618be unaware that they are set, whereas the C<-I> option is clearly
559therefore permitted.
619visible and therefore permitted.
560620
561621=end original
562622
563汚染検査モード(C<-T>) が有効のとき、"." ディレクトリは C<@INC> から
623汚染検査モード(C<-T>) が有効のとき、
564取り除かれ、環境変数 C<PERL5LIB> C<PERLLIB> Perl から無視されます。
624環境変数 C<PERL5LIB>, C<PERLLIB>, C<PERL_USE_UNSAFE_INC>
565それでも、L<perlrun> で説明されている C<-I> コマンドラインオプションを
625Perl から無視されます。
566使うことで、プログラムの外部から C<@INC> を調整出来ます。
626それL<perlrun|perlrun/-Idirectory> で説明されている
627C<-I> コマンドラインオプションを使うことで、
628プログラムの外部から C<@INC> を調整出来ます。
567629二つの環境変数は不明確で、プログラムを実行している
568630ユーザーはこの変数が設定されていることに気付かないかもしれないので
569631無視されますが、一方 C<-I> オプションは明確に見えるので許可されます。
570632
571633=begin original
572634
573635Another way to modify C<@INC> without modifying the program, is to use
574636the C<lib> pragma, e.g.:
575637
576638=end original
577639
578640プログラムを修正することなく C<@INC> を修正するもう一つの方法は、
579C<lib> プラグマを使うことですつまり:
641C<lib> プラグマを使うことです; つまり:
580642
581643 perl -Mlib=/foo program
582644
583645=begin original
584646
585647The benefit of using C<-Mlib=/foo> over C<-I/foo>, is that the former
586will automagically remove any duplicated directories, while the later
648will automagically remove any duplicated directories, while the latter
587649will not.
588650
589651=end original
590652
591653C<-I/foo> ではなく C<-Mlib=/foo> を使う利点は、後者だけが自動的に重複した
592654ディレクトリを自動的に除去することです。
593655
594656=begin original
595657
596658Note that if a tainted string is added to C<@INC>, the following
597659problem will be reported:
598660
599661=end original
600662
601663もし汚染された文字列が C<@INC> に追加されると、以下の問題が報告されることに
602664注意してください:
603665
604666 Insecure dependency in require while running with -T switch
605667
668=begin original
669
670On versions of Perl before 5.26, activating taint mode will also remove
671the current directory (".") from the default value of C<@INC>. Since
672version 5.26, the current directory isn't included in C<@INC> by
673default.
674
675=end original
676
6775.26 より前のバージョンの Perl では、汚染モードを有効にすると、
678C<@INC> のデフォルト値からカレントディレクトリ (".") を削除します。
679バージョン 5.26 からは、デフォルトではカレントディレクトリは C<@INC> に
680含まれていません。
681
606682=head2 Cleaning Up Your Path
607683
608684(実行パスを洗浄する)
609685
610686=begin original
611687
612688For "Insecure C<$ENV{PATH}>" messages, you need to set C<$ENV{'PATH'}> to
613689a known value, and each directory in the path must be absolute and
614690non-writable by others than its owner and group. You may be surprised to
615691get this message even if the pathname to your executable is fully
616692qualified. This is I<not> generated because you didn't supply a full path
617693to the program; instead, it's generated because you never set your PATH
618694environment variable, or you didn't set it to something that was safe.
619695Because Perl can't guarantee that the executable in question isn't itself
620696going to turn around and execute some other program that is dependent on
621697your PATH, it makes sure you set the PATH.
622698
623699=end original
624700
625701"Insecure C<$ENV{PATH}>" メッセージに対処するために、C<$ENV{'PATH'}> に
626既知の値を設定する必要があります
702既知の値を設定する必要があります; そして path に含まれている各ディレクトリは、
627して path に含まれている各ディレクトリは、絶対パスで、
703絶対パスで、ディレクトリの所有者やグループ以外からの書き込みを
628そのディレクトリの所有者やグループ以外からの書き込みを
629704禁じていなければなりません。
630実行しようとしているファイルをフルパスで
705実行しようとしているファイルをフルパスで書いたとしてもこのメッセージが
631書いたとしてもこのメッセージがでるので、びっくりすることがあるかもしれません。
706るので、びっくりすることがあるかもしれません。
632707このメッセージはプログラムのフルパスを書かなかったから出力されるではなく、
633708環境変数 PATH を設定しなかったり安全でない値を
634709設定したりしたために出力されるのです。
635710Perl は対象となっている実行ファイルが自分自身を方向転換したり、
636711PATH を参照して別のプログラムを起動したりするかどうかを知ることができないので、
637712確実に自分で PATH を設定するようにします。
638713
639714=begin original
640715
641716The PATH isn't the only environment variable which can cause problems.
642717Because some shells may use the variables IFS, CDPATH, ENV, and
643718BASH_ENV, Perl checks that those are either empty or untainted when
644starting subprocesses. You may wish to add something like this to your
719starting subprocesses. You may wish to add something like this to your
645720setid and taint-checking scripts.
646721
647722=end original
648723
649724この問題を引き起こす環境変数は PATH だけではありません。
650725一部のシェルでは、IFS、CDPATH、ENV、BASH_ENV のような環境変数を
651726使っていますから、Perl はこれらの変数がからであるかあるいは
652727サブプロセスが起動したときに汚染されていないかどうかチェックします。
653728setid していたり、汚染検査をするスクリプトに
654729以下のような行を付け加えたくなるかしれません。
655730
656731 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
657732
658733=begin original
659734
660735It's also possible to get into trouble with other operations that don't
661736care whether they use tainted values. Make judicious use of the file
662737tests in dealing with any user-supplied filenames. When possible, do
663738opens and such B<after> properly dropping any special user (or group!)
664privileges. Perl doesn't prevent you from opening tainted filenames for reading,
739privileges. Perl doesn't prevent you from
740opening tainted filenames for reading,
665741so be careful what you print out. The tainting mechanism is intended to
666742prevent stupid mistakes, not to remove the need for thought.
667743
668744=end original
669745
670746このほかの、汚染された値を使っているかどうかに注意を払わないような
671747操作によってトラブルに巻込まれる可能性もあります。
672748ユーザーが使うようなファイル名を扱うファイル検査の使用を賢明なものにします。
673749可能であれば、ファイルをオープンした B<その後で> 適切にスペシャルユーザー
674750(グループも!)の特権を落とします。
675751Perl はあなたが読み出しのために汚染されたファイル名を使ってファイルを
676752オープンすることを妨げませんから、出力の際には注意しましょう。
677753汚染検査機構はばかばかしいミスに対応するためのものであって、
678754必要なことを取り除くものではありません。
679755
680756=begin original
681757
682758Perl does not call the shell to expand wild cards when you pass C<system>
683759and C<exec> explicit parameter lists instead of strings with possible shell
684760wildcards in them. Unfortunately, the C<open>, C<glob>, and
685761backtick functions provide no such alternate calling convention, so more
686762subterfuge will be required.
687763
688764=end original
689765
690766Perl は、C<system> や C<exec> に対してシェルのワイルドカードが
691767あるかもしれないような文字列ではなく陽にパラメータリストを渡した場合には、
692768ワイルドカードの展開のためにシェルを呼び出したりしません。
693769残念なことに、C<open>、C<glob>、逆クォートといったものはそういった別の
694770呼び出し手順を提供していないので、より多くのごまかしが必要とされます。
695771
696772=begin original
697773
698774Perl provides a reasonably safe way to open a file or pipe from a setuid
699775or setgid program: just create a child process with reduced privilege who
700776does the dirty work for you. First, fork a child using the special
701777C<open> syntax that connects the parent and child by a pipe. Now the
702778child resets its ID set and any other per-process attributes, like
703779environment variables, umasks, current working directories, back to the
704780originals or known safe values. Then the child process, which no longer
705781has any special permissions, does the C<open> or other system call.
706782Finally, the child passes the data it managed to access back to the
707783parent. Because the file or pipe was opened in the child while running
708784under less privilege than the parent, it's not apt to be tricked into
709785doing something it shouldn't.
710786
711787=end original
712788
713789Perl は、setuid や setgid されたプログラムから安全にファイルやパイプを
714790オープンする方法を提供しています。
715791これは単に、汚れ仕事をするための制限された権利を持った子プロセスを
716792生成するというものです。
717793まず最初に、パイプによって親プロセスと子プロセスとを繋ぐ構文の
718794特別な C<open> を使って子プロセスを fork します。
719795このとき、子プロセスはその ID セットをリセットしさらにその他の
720796プロセス毎の属性をリセットして、オリジナルの、
721797もしくは安全な既知の値へと戻します。
722798それからもはや何の特別のパーミッションも持っていない子プロセスが
723799C<open> などのシステムコールを実行します。
724800ファイルやパイプは親プロセスよりも低い特権の元で実行されている
725801子プロセスでオープンされたので、すべきではないようなことを
726802ごまかしておこなうことはできません。
727803
728804=begin original
729805
730806Here's a way to do backticks reasonably safely. Notice how the C<exec> is
731807not called with a string that the shell could expand. This is by far the
732808best way to call something that might be subjected to shell escapes: just
733809never call the shell at all.
734810
735811=end original
736812
737813以下に示すのは、安全に逆クォートを行う方法です。
738814どのようにして C<exec> はシェルが展開するかもしれない文字列を伴って
739815呼び出されないようになっているかに注目してください。
740これはシェルをエスケープする目的には最善の方法というわけではありません
816これはシェルをエスケープする目的には最善の方法というわけではありません;
741817これは単に、シェルを呼び出さないというだけです。
742818
743 use English '-no_match_vars';
819 use English;
744820 die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
745821 if ($pid) { # parent
746822 while (<KID>) {
747823 # do something
748824 }
749825 close KID;
750826 } else {
751827 my @temp = ($EUID, $EGID);
752828 my $orig_uid = $UID;
753829 my $orig_gid = $GID;
754830 $EUID = $UID;
755831 $EGID = $GID;
756832 # Drop privileges
757833 $UID = $orig_uid;
758834 $GID = $orig_gid;
759835 # Make sure privs are really gone
760836 ($EUID, $EGID) = @temp;
761837 die "Can't drop privileges"
762838 unless $UID == $EUID && $GID eq $EGID;
763839 $ENV{PATH} = "/bin:/usr/bin"; # Minimal PATH.
764840 # Consider sanitizing the environment even more.
765841 exec 'myprog', 'arg1', 'arg2'
766842 or die "can't exec myprog: $!";
767843 }
768844
769845=begin original
770846
771847A similar strategy would work for wildcard expansion via C<glob>, although
772848you can use C<readdir> instead.
773849
774850=end original
775851
776852C<readdir> を代わりに使うことができるにしても、同様の戦略が C<glob> を
777853通じたワイルドカードの展開でも有効です。
778854
779855=begin original
780856
781857Taint checking is most useful when although you trust yourself not to have
782858written a program to give away the farm, you don't necessarily trust those
783859who end up using it not to try to trick it into doing something bad. This
784860is the kind of security checking that's useful for set-id programs and
785861programs launched on someone else's behalf, like CGI programs.
786862
787863=end original
788864
789865汚染検査は、農場をくれてやる (give away the farm) ためのプログラムを
790866記述することを自分自身に任せないということではなくて、
791867最終的にそれをつかって良からぬなにかを行おうとしているだれかを
792868信頼する必要がないというときに最も便利なものです。
793869これは、set-id プログラムや、CGI プログラムのように誰かに
794870すり変わって起動されるようなプログラムに便利なセキュリティチェックです。
795871
796872=begin original
797873
798874This is quite different, however, from not even trusting the writer of the
799875code not to try to do something evil. That's the kind of trust needed
800876when someone hands you a program you've never seen before and says, "Here,
801run this." For that kind of safety, check out the Safe module,
877run this." For that kind of safety, you might want to check out the Safe
802included standard in the Perl distribution. This module allows the
878module, included standard in the Perl distribution. This module allows the
803879programmer to set up special compartments in which all system operations
804are trapped and namespace access is carefully controlled.
880are trapped and namespace access is carefully controlled. Safe should
881not be considered bullet-proof, though: it will not prevent the foreign
882code to set up infinite loops, allocate gigabytes of memory, or even
883abusing perl bugs to make the host interpreter crash or behave in
884unpredictable ways. In any case it's better avoided completely if you're
885really concerned about security.
805886
806887=end original
807888
808889しかしながら、これは良からぬなにかを行おうはしないコードの作者を
809890信用しないということとは明らかに違います。
810891これは誰かが、プログラムをあなたが今まで見たことのないようにいじって
811892「ほら、これを実行して」と言わせるようなときに必要な種類の信用です。
812893この種の安全性のために、Perl の配布パッケージに標準で含まれている
813Safe モジュールをチェックしてみてください。
894Safe モジュールをチェックしたほうがいかもしれません
814895このモジュールはプログラマーがすべてのシステム操作をトラップし、
815896名前空間のアクセスが注意深く制御されるような
816897特別な仕切り(compartment)をセットアップすることを許します。
898しかし Safe は防弾であると考えるべきではありません: 無限ループ、
899何ギガバイトものメモリ割り当て、ホストインタプリタをクラッシュや予測不能な
900振る舞いをさせるための perl のバグの悪用をする外部コードすら防げません。
901本当にセキュリティのことを考えるならどの場合も完全に防いだ方が良いです。
817902
818=head2 Security Bugs
903=head2 Shebang Race Condition
819904
820(セキュリティバグ)
905(Shebang の競合条件)
821906
822907=begin original
823908
824909Beyond the obvious problems that stem from giving special privileges to
825910systems as flexible as scripts, on many versions of Unix, set-id scripts
826911are inherently insecure right from the start. The problem is a race
827912condition in the kernel. Between the time the kernel opens the file to
828913see which interpreter to run and when the (now-set-id) interpreter turns
829914around and reopens the file to interpret it, the file in question may have
830915changed, especially if you have symbolic links on your system.
831916
832917=end original
833918
834919スクリプトと同じくらい柔軟に特別な権限をシステムに与えて
835920しまう類の明白な問題の他に、多くの UNIX では、set-id されたスクリプトは
836921本質的に安全でない権利を最初から持っています。
837922その問題とは、カーネルにおける競合条件です。
838923インタープリターを実行するためにカーネルがファイルをオープンするのと、
839924(set-id された)インタープリターが起動してファイルを解釈するために
840再度オープンするその間に、問題のファイルが変更されるかもしれません
925再度オープンするその間に、問題のファイルが変更されるかもしれません;
841926特に、使っているシステムがシンボリックリンクをサポートしている場合には。
842927
843928=begin original
844929
845Fortunately, sometimes this kernel "feature" can be disabled.
930Some Unixes, especially more recent ones, are free of this
846Unfortunately, there are two ways to disable it. The system can simply
931inherent security bug. On such systems, when the kernel passes the name
847outlaw scripts with any set-id bit set, which doesn't help much.
932of the set-id script to open to the interpreter, rather than using a
848Alternately, it can simply ignore the set-id bits on scripts. If the
933pathname subject to meddling, it instead passes I</dev/fd/3>. This is a
849latter is true, Perl can emulate the setuid and setgid mechanism when it
934special file already opened on the script, so that there can be no race
850notices the otherwise useless setuid/gid bits on Perl scripts. It does
935condition for evil scripts to exploit. On these systems, Perl should be
851this via a special executable called F<suidperl> that is automatically
936compiled with C<-DSETUID_SCRIPTS_ARE_SECURE_NOW>. The F<Configure>
852invoked for you if it's needed.
937program that builds Perl tries to figure this out for itself, so you
938should never have to specify this yourself. Most modern releases of
939SysVr4 and BSD 4.4 use this approach to avoid the kernel race condition.
853940
854941=end original
855942
856幸運なことに、このカーネル“仕様”は使用禁止できることもありま
943一部の Unix、特最近のものは、このようなセキュリティバグる耐性を
857残念なことに禁止には二つのやり方があります。
944備えています。
858システムは set-id ビットがセットされているスクリ単純に禁止することが
945そのようなシステム、インタリタ起動するためにカーネルに
859できます、このときはなもできせん。
946set-id スクリプト渡されたときにそのパス名をそのま使うのではなく、
860もう一つ、スクリプト付けられた set-id ビット単純に
947代わりI</dev/fd/3>渡します。
861無視してしまうとがきま
948れはスクリプトは、あらかじめオープンされている特別なファイルでから、
862後者の場合、Perl スクリプトにあ setuid/gid ビットが無用なものではない
949邪悪なスクリプトをこじ入れためにつかうこはできません。
863Perl が認識しときに、Perl は setuid や setgid の仕掛けを
950こういっシステムおいては、Perl は
864模倣(emulate)ることがでます
951C<-DSETUID_SCRIPTS_ARE_SECURE_NOW> を付加してコンパイルでしょう
865この機能は、必要とされときに自動的に起動される F<suidperl> と呼ば
952Perl を構築する F<Configure> プログラムは自分自身でこ
866特別な実行ファイル通じて行ます。
953見つけ出そうとするので、あなたが特別な何かばならない、
954ということはありあません。
955SysVr4 の最近のリリースのほとんどや BSD4.4 は
956このアプローチをカーネルの競合条件を避けるために使っています。
867957
868958=begin original
869959
870However, if the kernel set-id script feature isn't disabled, Perl will
960If you don't have the safe version of set-id scripts, all is not lost.
871complain loudly that your set-id script is insecure. You'll need to
961Sometimes this kernel "feature" can be disabled, so that the kernel
872either disable the kernel set-id script feature, or put a C wrapper around
962either doesn't run set-id scripts with the set-id or doesn't run them
963at all. Either way avoids the exploitability of the race condition,
964but doesn't help in actually running scripts set-id.
965
966=end original
967
968安全なバージョンの set-id スクリプトがない場合でも、他に手段が
969ないわけではありません。
970カーネルは set-id スクリプトを set-id で実行しないか、
971これらを全く実行しないことで、
972このカーネル「仕様」は使用禁止にできることもあります。
973どちらかの方法で競合条件の悪用可能性を避けることができますが、
974実際にスクリプトを set-id で実行する助けにはなりません。
975
976=begin original
977
978If the kernel set-id script feature isn't disabled, then any set-id
979script provides an exploitable vulnerability. Perl can't avoid being
980exploitable, but will point out vulnerable scripts where it can. If Perl
981detects that it is being applied to a set-id script then it will complain
982loudly that your set-id script is insecure, and won't run it. When Perl
983complains, you need to remove the set-id bit from the script to eliminate
984the vulnerability. Refusing to run the script doesn't in itself close
985the vulnerability; it is just Perl's way of encouraging you to do this.
986
987
988=end original
989
990kernel set-id スクリプト機能が禁止されていなければ、
991任意の set-id スクリプトは悪用可能な脆弱性を持ちます。
992Perl は悪用可能性を避けることはできませんが、
993可能性のある脆弱性のあるスクリプトを示すことはできます。
994Perl が set-id スクリプトが適用されていることを検出した場合、
995あなたの set-id スクリプトは安全ではないとやかましく主張し、
996実行しません。
997Perl が文句を言った場合、脆弱性を取り除くためにスクリプトから
998set-id ビットを取り除く必要があります。
999スクリプトの実行を拒否することは、それ自体で脆弱性を閉じることはありません;
1000これは単にそうするようにあなたを後押しする Perl の方法です。
1001
1002=begin original
1003
1004To actually run a script set-id, if you don't have the safe version of
1005set-id scripts, you'll need to put a C wrapper around
8731006the script. A C wrapper is just a compiled program that does nothing
8741007except call your Perl program. Compiled programs are not subject to the
8751008kernel bug that plagues set-id scripts. Here's a simple wrapper, written
8761009in C:
8771010
8781011=end original
8791012
880しかし、kernel set-id スクリプト機能が禁止されていなければPerl は
1013実際に set-id スクリプトを実行するために安全なバージョンの
881あなたの set-id スクリプトは安全ではないとやかましく主張することでしょう。
1014set-id スクリプトを持っていない場合は、
882このとき、あなたは kernel set-id スクリプト機能禁止るか、
1015スクリプトを C のラッパーで包む必要がありま
883スクリプトを C のラッパーで包んでしまうかのいずれかが必要です。
8841016C ラッパーは、Perl プログラムを呼び出すことを除いては
8851017何もしないプログラムです。
8861018コンパイルされたプログラムは set-id されたスクリプトに関する
8871019カーネルのバグには影響されません。
888次の例は、C で書いた単純なラッパーです
1020次の例は、C で書いた単純なラッパーです:
8891021
1022 #include <unistd.h>
1023 #include <stdio.h>
1024 #include <string.h>
1025 #include <errno.h>
1026
8901027 #define REAL_PATH "/path/to/script"
891 main(ac, av)
892 char **av;
1029 int main(int argc, char **argv)
8931030 {
894 execv(REAL_PATH, av);
1031 execv(REAL_PATH, argv);
1032 fprintf(stderr, "%s: %s: %s\n",
1033 argv[0], REAL_PATH, strerror(errno));
1034 return 127;
8951035 }
8961036
8971037=begin original
8981038
8991039Compile this wrapper into a binary executable and then make I<it> rather
900than your script setuid or setgid.
1040than your script setuid or setgid. Note that this wrapper isn't doing
1041anything to sanitise the execution environment other than ensuring
1042that a safe path to the script is used. It only avoids the shebang
1043race condition. It relies on Perl's own features, and on the script
1044itself being careful, to make it safe enough to run the script set-id.
9011045
9021046=end original
9031047
9041048このラッパーをコンパイルして実行ファイルにし、スクリプトではなく
9051049I<この実行ファイル> を setuid したり setgid します。
1050このラッパーは、スクリプトが使われる安全なパスであることを保証する以外に
1051実行環境をサニタイズしないことに注意してください。
1052これはシェバン競合条件のみを回避します。
1053スクリプトを set-id で実行するのに十分なぐらい安全であることは、
1054これは Perl 自身の機能と、スクリプト自身が注意深いことに依存しています。
9061055
907=begin original
908
909In recent years, vendors have begun to supply systems free of this
910inherent security bug. On such systems, when the kernel passes the name
911of the set-id script to open to the interpreter, rather than using a
912pathname subject to meddling, it instead passes I</dev/fd/3>. This is a
913special file already opened on the script, so that there can be no race
914condition for evil scripts to exploit. On these systems, Perl should be
915compiled with C<-DSETUID_SCRIPTS_ARE_SECURE_NOW>. The F<Configure>
916program that builds Perl tries to figure this out for itself, so you
917should never have to specify this yourself. Most modern releases of
918SysVr4 and BSD 4.4 use this approach to avoid the kernel race condition.
919
920=end original
921
922近年、ベンダーはこのようなセキュリティバグに対する耐性を備えたシステムを
923提供しはじめました。
924そのようなシステムでは、インタープリターを起動するためにカーネルに
925set-id スクリプトが渡されたときにそのパス名をそのまま使うのではなく、
926代わりに I</dev/fd/3> を渡します。
927これはスクリプトでは、あらかじめオープンされている特別なファイルですから、
928邪悪なスクリプトをこじ入れるためにつかうことはできません。
929こういったシステムにおいては、Perl は
930C<-DSETUID_SCRIPTS_ARE_SECURE_NOW> を付加してコンパイルすべきでしょう。
931Perl を構築する F<Configure> プログラムは自分自身でこれを
932見つけ出そうとするので、あなたが特別な何かをしなければならない、
933ということはありあません。
934SysVr4 の最近のリリースのほとんどや BSD4.4 は
935このアプローチをカーネルの競合条件を避けるために使っています。
936
937=begin original
938
939Prior to release 5.6.1 of Perl, bugs in the code of F<suidperl> could
940introduce a security hole.
941
942=end original
943
944リリース 5.6.1 以前の Perl では、F<suidperl> にあったバグによって、
945セキュリティホールが持ち込まれる可能性がありました。
946
9471056=head2 Protecting Your Programs
9481057
9491058(あなたのプログラムを守る)
9501059
9511060=begin original
9521061
9531062There are a number of ways to hide the source to your Perl programs,
9541063with varying levels of "security".
9551064
9561065=end original
9571066
9581067ここで挙げるのは、あなたの Perl プログラムのソースコードをさまざまな
9591068“セキュリティ”のレベルで隠す方法です。
9601069
9611070=begin original
9621071
9631072First of all, however, you I<can't> take away read permission, because
9641073the source code has to be readable in order to be compiled and
9651074interpreted. (That doesn't mean that a CGI script's source is
9661075readable by people on the web, though.) So you have to leave the
9671076permissions at the socially friendly 0755 level. This lets
9681077people on your local system only see your source.
9691078
9701079=end original
9711080
9721081しかしまず最初にいっておきますが、ソースコードの読み込み権限を
9731082落とすことは B<できません>。
9741083なぜなら、ソースコードは、コンパイルやインタープリットするために
9751084読めるようになっていなければならないからです(これは、CGI スクリプトのソースが
9761085web の利用者から見ることができないというのとは違います)。
9771086このため、パーミッションは 0755 レベルにしておかなければならないのです。
9781087これによってあなたのローカルシステム上のユーザーはあなたのソースを
9791088見ることだけになります。
9801089
9811090=begin original
9821091
9831092Some people mistakenly regard this as a security problem. If your program does
9841093insecure things, and relies on people not knowing how to exploit those
9851094insecurities, it is not secure. It is often possible for someone to
9861095determine the insecure things and exploit them without viewing the
9871096source. Security through obscurity, the name for hiding your bugs
9881097instead of fixing them, is little security indeed.
9891098
9901099=end original
9911100
9921101一部の人達はこれをセキュリティ上の問題であると考えています。
9931102あなたのプログラムが安全でないことを行っていて、
9941103他人がそういったセキュリティの隙間をこじ開ける方法を知らないことに
9951104頼っているのなら、それは安全ではないのです。
9961105これはある人が安全でないことがらを見つけだし、
9971106ソースを見ることなしにそれをこじ開けることの要因となります。
9981107明快さを通したセキュリティはバグを直すのではなく隠すことに比べれば、
9991108セキュリティをほんの少しだけしか傷つけません。
10001109
10011110=begin original
10021111
10031112You can try using encryption via source filters (Filter::* from CPAN,
10041113or Filter::Util::Call and Filter::Simple since Perl 5.8).
10051114But crackers might be able to decrypt it. You can try using the byte
10061115code compiler and interpreter described below, but crackers might be
10071116able to de-compile it. You can try using the native-code compiler
10081117described below, but crackers might be able to disassemble it. These
10091118pose varying degrees of difficulty to people wanting to get at your
10101119code, but none can definitively conceal it (this is true of every
10111120language, not just Perl).
10121121
10131122=end original
10141123
10151124ソースフィルター(CPAN にある Filter::*,
10161125or Filter::Util::Call and Filter::Simple since Perl 5.8)
1017を通して暗号化しようと
1126を通して暗号化しようとすることはできます。
1018することはできますが、クラッカーがそれを復号化することは可能でしょう。
1127しかしクラッカーがそれを復号化することは可能でしょう。
10191128先に説明したバイトコードコンパイラーとインタープリターを使うことも
10201129できますが、クラッカーはそれを逆コンパイルすることができるかもしれません。
10211130ネイティブコードコンパイラーを使おうとしても、クラッカーはそれを
10221131逆アセンブルできるかもしれません。
10231132こういったことは、他人があなたの
10241133プログラムを手に入れようとすることを難しくしたりしますが、
10251134プログラムを決定的に隠すことは誰にもできないのです(このことは、
10261135Perl に限らずすべての言語にあてはまります)。
10271136
10281137=begin original
10291138
10301139If you're concerned about people profiting from your code, then the
1031bottom line is that nothing but a restrictive licence will give you
1140bottom line is that nothing but a restrictive license will give you
10321141legal security. License your software and pepper it with threatening
10331142statements like "This is unpublished proprietary software of XYZ Corp.
10341143Your access to it does not give you permission to use it blah blah
1035blah." You should see a lawyer to be sure your licence's wording will
1144blah." You should see a lawyer to be sure your license's wording will
10361145stand up in court.
10371146
10381147=end original
10391148
10401149他人があなたのプログラムから受ける利益について気にしているのであれば、
10411150制限つきライセンスがあなたに法的な安全を与えるでしょう。
1042あなたのソフトウェアのライセンスに、本ソフトウェアは XYZ Corp.による、
1151あなたのソフトウェアのライセンスに、本ソフトウェアは XYZ Corp.による、
10431152公表されていない独占的ソフトウェアです。
1044あなたが使用するために
1153あなたが使用するためにこれにアクセスすることは許可されておらず云々」のような
1045これにアクセスすることは許可されておらず云々”のような脅し文句を
1154脅し文句を付けておきます。
1046付けておきます。
1155あなたのライセンスの文言が法廷で確実に有効なものとなるように、
1047あなたのライセンスが確実に有効なものとなるように、
10481156弁護士と相談したほうが良いでしょう。
10491157
10501158=head2 Unicode
10511159
10521160=begin original
10531161
10541162Unicode is a new and complex technology and one may easily overlook
10551163certain security pitfalls. See L<perluniintro> for an overview and
10561164L<perlunicode> for details, and L<perlunicode/"Security Implications
10571165of Unicode"> for security implications in particular.
10581166
10591167=end original
10601168
10611169Unicode は新しくて複雑な技術で、ある種のセキュリティの罠を簡単に
10621170見落としてしまいます。
10631171概要については L<perluniintro> を、詳細については L<perlunicode> を、
10641172そして特にセキュリティ実装については L<perlunicode/"Security Implications
10651173of Unicode"> を参照してください。
10661174
10671175=head2 Algorithmic Complexity Attacks
10681176
10691177(アルゴリズム的複雑性攻撃)
10701178
10711179=begin original
10721180
10731181Certain internal algorithms used in the implementation of Perl can
10741182be attacked by choosing the input carefully to consume large amounts
10751183of either time or space or both. This can lead into the so-called
10761184I<Denial of Service> (DoS) attacks.
10771185
10781186=end original
10791187
10801188Perl の実装で使われているある種の内部アルゴリズムは、多くの時間や
10811189空間を消費するように注意深く選択された入力によって攻撃可能です。
10821190これにより I<サービス拒否(Denial of Service)> (DoS) 攻撃と呼ばれている
10831191ものを引き起こすことができます。
10841192
10851193=over 4
10861194
10871195=item *
10881196
10891197=begin original
10901198
1091Hash Function - the algorithm used to "order" hash elements has been
1199Hash Algorithm - Hash algorithms like the one used in Perl are well
1092changed several times during the development of Perl, mainly to be
1200known to be vulnerable to collision attacks on their hash function.
1093reasonably fast. In Perl 5.8.1 also the security aspect was taken
1201Such attacks involve constructing a set of keys which collide into
1094into account.
1202the same bucket producing inefficient behavior. Such attacks often
1203depend on discovering the seed of the hash function used to map the
1204keys to buckets. That seed is then used to brute-force a key set which
1205can be used to mount a denial of service attack. In Perl 5.8.1 changes
1206were introduced to harden Perl to such attacks, and then later in
1207Perl 5.18.0 these features were enhanced and additional protections
1208added.
10951209
10961210=end original
10971211
1098ハッシュ関数 - ハッシュ要素を「並べる」ために使われるアルゴリズムは
1212ハッシュアルゴリズム - 以前 Perl で使われていたようなハッシュアルゴリズムは
1099Perl の開発中(主として高速化のために)数回変更されています。
1213ハッシュ関数対する衝突攻撃に対して脆弱であることでよく知られています。
1100Perl 5.8.1 でュリティ側面も考慮されています。
1214この攻撃、非効率的な振る舞いをさせるために同じバケツに入るような集合を
1215構築することで行われます。
1216このような攻撃はしばしばキーをバケツにマッピングするために使われる
1217ハッシュ関数の種の発見に依存します。
1218この種はそれからサービス拒否攻撃を起こせるブルートフォースキー集合に
1219使われます。
1220Perl 5.8.1 でこのような攻撃に対する Perl の強化が導入され、後に Perl 5.18.0 で
1221これらの機能は拡張され、追加の防御が追加されました。
11011222
11021223=begin original
11031224
1104In Perls before 5.8.1 one could rather easily generate data that as
1225At the time of this writing, Perl 5.18.0 is considered to be
1105hash keys would cause Perl to consume large amounts of time because
1226well-hardened against algorithmic complexity attacks on its hash
1106internal structure of hashes would badly degenerate. In Perl 5.8.1
1227implementation. This is largely owed to the following measures
1107the hash function is randomly perturbed by a pseudorandom seed which
1228mitigate attacks:
1108makes generating such naughty hash keys harder.
1109See L<perlrun/PERL_HASH_SEED> for more information.
11101229
11111230=end original
11121231
11135.8.1 以前の Perl ハッシュの内部構造が悪化するために Perl が
1232これを書いている時点では、Perl 5.18.0 はハッシュ実装に対するアルゴリズム的
1114大量の時間を消費することなるうなハッシュキーとなデータを
1233複雑性攻撃対してく防御されていと考えられています。
1115り簡単生成できした。
1234これは主に以下のよう要素が攻撃を緩和していること依りす:
1116Perl 5.8.1 で、そのようなよくないハッシュキーを生成するのをより難しく
1117するために、ハッシュ関数は擬似乱数の種によってランダムに攪拌されます。
1118さらなる情報については L<perlrun/PERL_HASH_SEED> を参照してください。
11191235
1236=over 4
1237
1238=item Hash Seed Randomization
1239
1240(ハッシュの種のランダム化)
1241
11201242=begin original
11211243
1122The random perturbation is done by default but if one wants for some
1244In order to make it impossible to know what seed to generate an attack
1123reason emulate the old behaviour one can set the environment variable
1245key set for, this seed is randomly initialized at process start. This
1124PERL_HASH_SEED to zero (or any other integer). One possible reason
1246may be overridden by using the PERL_HASH_SEED environment variable, see
1125for wanting to emulate the old behaviour is that in the new behaviour
1247L<perlrun/PERL_HASH_SEED>. This environment variable controls how
1126consecutive runs of Perl will order hash keys differently, which may
1248items are actually stored, not how they are presented via
1127confuse some applications (like Data::Dumper: the outputs of two
1249C<keys>, C<values> and C<each>.
1128different runs are no more identical).
11291250
11301251=end original
11311252
1132ランダムな攪拌はデフォルトで実行されますが、もしの理由で古い振舞い
1253攻撃キー集合を生成るための種が何かを知こと不可能にするために、この種は
1133エミュレートしたい場合は、PERL_HASH_SEED 環境変数 0 (あるいはその他の
1254プロセス開始時ランダムに初期化されます。
1134任意の整数)設定できます
1255これは PERL_HASH_SEED 環境変数使うこと上書できます;
1135古い振る舞いエミュレートたい理由の可能性の一つとしは、新し
1256L<perlrun/PERL_HASH_SEED> 参照してくださ
1136振る舞いで、Perl を何回も行するとハッシュキー順序が毎回異なるので、
1257この環境変数アイテムが際にどように保管されかを制御するもので、
1137これによって混乱するアプリケーションがあるからです (例えば Data::Dumper:
1258C<keys>, C<values>, C<each> 経由でどのように表現されるかを
11382 回実行した結果が同一になりません)
1259制御するものではありません。
11391260
1261=item Hash Traversal Randomization
1262
1263(ハッシュ探索のランダム化)
1264
11401265=begin original
11411266
1142B<Perl has never guaranteed any ordering of the hash keys>, and the
1267Independent of which seed is used in the hash function, C<keys>,
1143ordering has already changed several times during the lifetime of
1268C<values>, and C<each> return items in a per-hash randomized order.
1144Perl 5. Also, the ordering of hash keys has always been, and
1269Modifying a hash by insertion will change the iteration order of that hash.
1145continues to be, affected by the insertion order.
1270This behavior can be overridden by using C<hash_traversal_mask()> from
1271L<Hash::Util> or by using the PERL_PERTURB_KEYS environment variable,
1272see L<perlrun/PERL_PERTURB_KEYS>. Note that this feature controls the
1273"visible" order of the keys, and not the actual order they are stored in.
11461274
11471275=end original
11481276
1277ハッシュ関数でどの種が使われるかとは独立に、C<keys>, C<values>, C<each> は
1278ハッシュ毎にランダム化された順序で要素を返します。
1279挿入によってハッシュが変更されると、そのハッシュの反復順が変わります。
1280この振る舞いは、L<Hash::Util> の C<hash_traversal_mask()> を使うか、
1281PERL_PERTURB_KEYS 環境変数を使うことで上書きできます;
1282L<perlrun/PERL_PERTURB_KEYS> を参照してください。
1283この機能は keys の「見える」順序を制御するもので、実際に保管される順序を
1284制御するものではありません。
1285
1286=item Bucket Order Perturbance
1287
1288(バケツ順の撹乱)
1289
1290=begin original
1291
1292When items collide into a given hash bucket the order they are stored in
1293the chain is no longer predictable in Perl 5.18. This
1294has the intention to make it harder to observe a
1295collision. This behavior can be overridden by using
1296the PERL_PERTURB_KEYS environment variable, see L<perlrun/PERL_PERTURB_KEYS>.
1297
1298=end original
1299
1300あるハッシュバケツで要素が衝突したとき、Perl 5.18 ではチェーンに保管される順番は
1301もはや予測できなくなりました。
1302これは、衝突を観測するのをより困難にする意図があります。
1303この振る舞いは PERL_PERTURB_KEYS 環境変数を使うことで上書きできます;
1304L<perlrun/PERL_PERTURB_KEYS> を参照してください。
1305
1306=item New Default Hash Function
1307
1308(新しいデフォルトハッシュ関数)
1309
1310=begin original
1311
1312The default hash function has been modified with the intention of making
1313it harder to infer the hash seed.
1314
1315=end original
1316
1317デフォルトハッシュ関数は、ハッシュの種の推論をより難しくするために
1318修正されました。
1319
1320=item Alternative Hash Functions
1321
1322(代替ハッシュ関数)
1323
1324=begin original
1325
1326The source code includes multiple hash algorithms to choose from. While we
1327believe that the default perl hash is robust to attack, we have included the
1328hash function Siphash as a fall-back option. At the time of release of
1329Perl 5.18.0 Siphash is believed to be of cryptographic strength. This is
1330not the default as it is much slower than the default hash.
1331
1332=end original
1333
1334ソースコードには選択できる複数のハッシュアルゴリズムが含まれています。
1335デフォルトの perl ハッシュは攻撃に頑強であると信じていますが、
1336フォールバックオプションとして Siphash ハッシュ関数も含めています。
1337Perl 5.18.0 のリリースの時点で、Siphash は暗号学的強度を持つと
1338信じられています。
1339これはデフォルトのハッシュよりもはるかに遅いので、デフォルトではありません。
1340
1341=back
1342
1343=begin original
1344
1345Without compiling a special Perl, there is no way to get the exact same
1346behavior of any versions prior to Perl 5.18.0. The closest one can get
1347is by setting PERL_PERTURB_KEYS to 0 and setting the PERL_HASH_SEED
1348to a known value. We do not advise those settings for production use
1349due to the above security considerations.
1350
1351=end original
1352
1353特別な Perl をコンパイルしない限り、Perl 5.18.0 より前のバージョンと正確に
1354同じ振る舞いにする方法はありません。
1355最も近いのは、PERL_PERTURB_KEYS に 0 を設定し、PERL_HASH_SEED に既知の値を
1356設定することです。
1357上述のセキュリティ上の問題のため、製品にはこの設定をしないことを勧めます。
1358
1359=begin original
1360
1361B<Perl has never guaranteed any ordering of the hash keys>, and
1362the ordering has already changed several times during the lifetime of
1363Perl 5. Also, the ordering of hash keys has always been, and continues
1364to be, affected by the insertion order and the history of changes made
1365to the hash over its lifetime.
1366
1367=end original
1368
11491369B<Perl はハッシュキーの順序について何の保障もありません> し、Perl 5 の
11501370間でも既に何度か変更されています。
1151また、ハッシュキーの順序は、今までもこれからも、挿入順に影響を受けます。
1371また、ハッシュキーの順序は、今までもこれからも、挿入順と、ハッシュ対して
1372行われた変更の歴史の影響を受けます。
11521373
11531374=begin original
11541375
11551376Also note that while the order of the hash elements might be
1156randomised, this "pseudoordering" should B<not> be used for
1377randomized, this "pseudo-ordering" should B<not> be used for
1157applications like shuffling a list randomly (use List::Util::shuffle()
1378applications like shuffling a list randomly (use C<List::Util::shuffle()>
11581379for that, see L<List::Util>, a standard core module since Perl 5.8.0;
1159or the CPAN module Algorithm::Numerical::Shuffle), or for generating
1380or the CPAN module C<Algorithm::Numerical::Shuffle>), or for generating
1160permutations (use e.g. the CPAN modules Algorithm::Permute or
1381permutations (use e.g. the CPAN modules C<Algorithm::Permute> or
1161Algorithm::FastPermute), or for any cryptographic applications.
1382C<Algorithm::FastPermute>), or for any cryptographic applications.
11621383
11631384=end original
11641385
11651386また、ハッシュ要素の順序はランダム化されますが、この「擬似整列」は
11661387以下のことに B<使うべきではありません>: リストをランダムに
1167シャッフルするようなアプリケーション
1388シャッフルするようなアプリケーション (Perl 5.8.0 から標準モジュールと
1168(Perl 5.8.0 から標準モジュールとなっている L<List::Util> の
1389なっている L<List::Util> の C<List::Util::shuffle()> や、CPAN モジュールである
1169List::Util::shuffle() CPAN モジュールである
1390C<Algorithm::Numerical::Shuffle> を使ってください)順列の生成
1170Algorithm::Numerical::Shuffle を使ってください)、 順列の生成
1391(CPAN モジュールである C<Algorithm::Permute> や C<Algorithm::FastPermute>
1171(CPAN モジュールである Algorithm::Permute や Algorithm::FastPermute を
11721392使ってください)、あらゆる暗号アプリケーション。
11731393
1394=begin original
1395
1396Tied hashes may have their own ordering and algorithmic complexity
1397attacks.
1398
1399=end original
1400
1401tie されたハッシュは独自の順序とアルゴリズム的複雑性攻撃があるかもしれません。
1402
11741403=item *
11751404
11761405=begin original
11771406
11781407Regular expressions - Perl's regular expression engine is so called NFA
11791408(Non-deterministic Finite Automaton), which among other things means that
11801409it can rather easily consume large amounts of both time and space if the
11811410regular expression may match in several ways. Careful crafting of the
11821411regular expressions can help but quite often there really isn't much
11831412one can do (the book "Mastering Regular Expressions" is required
11841413reading, see L<perlfaq2>). Running out of space manifests itself by
11851414Perl running out of memory.
11861415
11871416=end original
11881417
11891418正規表現 - Perl の正規表現エンジンは NFA (Non-deterministic Finite Automaton:
11901419非決定性有限オートマトン)と呼ばれ、これは他のものに比べて、もし正規表現が
11911420複数の方法でマッチングする場合、かなり簡単に大量の時間と空間を
11921421消費することを意味します。
11931422正規表現を注意深く構築することは助けになりますが、かなりの場合これは
11941423不十分です ("Mastering Regular Expressions" という本を読む必要があります;
11951424L<perlfaq2> を参照してください)。
11961425空間の不足は Perl がメモリ不足になることで明らかになります。
11971426
11981427=item *
11991428
12001429=begin original
12011430
12021431Sorting - the quicksort algorithm used in Perls before 5.8.0 to
1203implement the sort() function is very easy to trick into misbehaving
1432implement the sort() function was very easy to trick into misbehaving
1204so that it consumes a lot of time. Nothing more is required than
1433so that it consumes a lot of time. Starting from Perl 5.8.0 a different
1205resorting a list already sorted. Starting from Perl 5.8.0 a different
1434sorting algorithm, mergesort, is used by default. Mergesort cannot
1206sorting algorithm, mergesort, is used. Mergesort is insensitive to
1435misbehave on any input.
1207its input data, so it cannot be similarly fooled.
12081436
12091437=end original
12101438
12111439ソート - 5.8.0 以前の Perl で sort() 関数を実装するために使われていた
12121440クイックソートアルゴリズムは、大量の時間を消費するような策略がとても
1213簡単で
1441簡単でした
1214既にソートされているリストを再ソートさせる以上のことは不要です。
12151442Perl 5.8.0 から、異なったソートアルゴリズムであるマージソートが
1216使われています。
1443デフォルトで使われています。
1217マージソートは入力データによって影響を受けないので、同じような策略は
1444マージソートは入力データによって影響を受けません。
1218不可能です。
12191445
12201446=back
12211447
12221448=begin original
12231449
1224See L<http://www.cs.rice.edu/~scrosby/hash/> for more information,
1450See L<https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf> for more information,
1225and any computer science textbook on the algorithmic complexity.
1451and any computer science textbook on algorithmic complexity.
12261452
12271453=end original
12281454
1229さらなる情報については L<http://www.cs.rice.edu/~scrosby/hash/> および、
1455さらなる情報については L<https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf> および、
12301456アルゴリズム的複雑性に関する情報工学の教科書を参照してください。
12311457
1458=head2 Using Sudo
1459
1460(sudo を使う)
1461
1462=begin original
1463
1464The popular tool C<sudo> provides a controlled way for users to be able
1465to run programs as other users. It sanitises the execution environment
1466to some extent, and will avoid the L<shebang race condition|/"Shebang
1467Race Condition">. If you don't have the safe version of set-id scripts,
1468then C<sudo> may be a more convenient way of executing a script as
1469another user than writing a C wrapper would be.
1470
1471=end original
1472
1473人気のあるツールである C<sudo> は、
1474ユーザーが他のユーザーとしてプログラムを実行する制御された手段を
1475提供します。
1476これはある程度実行環境をサニタイズして、
1477L<シェバン競合条件|/"Shebang Race Condition"> を回避します。
1478安全なバージョンの set-id スクリプトを持っていない場合、
1479C<sudo> は、他のユーザーとしてスクリプトを実行するための、
1480C ラッパーを書くよりもより便利な手段になります。
1481
1482=begin original
1483
1484However, C<sudo> sets the real user or group ID to that of the target
1485identity, not just the effective ID as set-id bits do. As a result, Perl
1486can't detect that it is running under C<sudo>, and so won't automatically
1487take its own security precautions such as turning on taint mode. Where
1488C<sudo> configuration dictates exactly which command can be run, the
1489approved command may include a C<-T> option to perl to enable taint mode.
1490
1491=end original
1492
1493しかし、C<sudo> はターゲットの身元として set-id ビットが行うような
1494単なる実効 ID ではなく、実ユーザー ID やグループ ID を設定します。
1495結果として、Perl はこれが C<sudo> の基で実行されていることを検出できず、
1496汚染チェックモードを友好にすると行ったセキュリティ上の予防措置を
1497自動的に有効にしません。
1498C<sudo> 設定が実行されるコマンドを正確に設定する部分では、
1499perl が汚染チェックモードを有効にするために、承認されたコマンドに
1500C<-T> オプションを含むことができます。
1501
1502=begin original
1503
1504In general, it is necessary to evaluate the suitability of a script to
1505run under C<sudo> specifically with that kind of execution environment
1506in mind. It is neither necessary nor sufficient for the same script to
1507be suitable to run in a traditional set-id arrangement, though many of
1508the issues overlap.
1509
1510=end original
1511
1512一般的に、C<sudo> の基で実効するためのスクリプトの適合性を評価することは、
1513特に想定している実行環境では必要です。
1514同じスクリプトに対して伝統的な set-id 配置で実行できるようにすることは
1515必要でも十分でもありませんが、多くの問題は重なっています。
1516
12321517=head1 SEE ALSO
12331518
12341519=begin original
12351520
1236L<perlrun> for its description of cleaning up environment variables.
1521L<perlrun/ENVIRONMENT> for its description of cleaning up environment
1522variables.
12371523
12381524=end original
12391525
1240L<perlrun> には環境変数を洗浄する方法が記述されています。
1526L<perlrun/ENVIRONMENT> には環境変数を洗浄する方法が記述されています。
12411527
12421528=begin meta
12431529
12441530Translate: KIMURA Koichi (5.005_03)
1245Update: Kentaro Shirakata <argrath@ub32.org> (5.6.1-)
1531Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
1532Status: completed
12461533
12471534=end meta