forked from NEKOGET/FuelPHP_docs_jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.html
613 lines (590 loc) · 20.2 KB
/
security.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Security::";
</script>
<script src="./../assets/js/combined.js"></script>
<title>Security - クラス - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<a href="http://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>Security クラス</h2>
<p>Security クラスは、あなたのアプリケーションを CSRF から守ります。</p>
<section>
<h3 id="configuration">設定</h3>
<p>
Security クラスは、<kbd>app/config/config.php</kbd> 設定ファイルのセキュリティセクションで設定できます。
</p>
<p>以下のセキュリティ設定が定義可能です。</p>
<table class="config">
<tbody>
<tr class="header">
<th>パラメータ</th>
<th>型</th>
<th>デフォルト</th>
<th>説明</th>
</tr>
<tr>
<th>token_salt</th>
<td>string</td>
<td><pre class="php"><code>'put your salt value here...'</code></pre></td>
<td>
安全なトークンを生成するためにソルトを使用します。この文字列はランダムにし、容易に推測されないようにしてください。
</td>
</tr>
<tr>
<th>csrf_token_key</th>
<td>string</td>
<td><pre class="php"><code>'fuel_csrf_token'</code></pre></td>
<td>
CSRF トークンクッキーの名前。トークンを含むフィールド名としても使用。
</td>
</tr>
<tr>
<th>csrf_expiration</th>
<td>integer</td>
<td><pre class="php"><code>0</code></pre></td>
<td>
CRSF トークンクッキーの有効期限。デフォルトでは、ブラウザセッション終了時まで有効。
</td>
</tr>
<tr>
<th>csrf_bad_request_on_fail</th>
<td>boolean</td>
<td><pre class="php"><code>false</code></pre></td>
<td>
<strong>true</strong> にすると、 CSRF トークンの検証が失敗したときに HttpBadRequestException が投げられます。
<strong>false</strong> にすると、一般的な SecurityException が投げられます。後方互換のためデフォルトは <strong>false</strong> です。
</td>
</tr>
<tr>
<th>uri_filter</th>
<td>array</td>
<td><pre class="php"><code>array('htmlentities')</code></pre></td>
<td>
URI をフィルタするのに使用する呼び出し可能なアイテム(PHP 関数、オブジェクトメソッド、静的クラスメソッド)の配列。デフォルトでは、PHP のビルトイン関数 htmlentities を使用。
</td>
</tr>
<tr>
<th>input_filter</th>
<td>array</td>
<td><pre class="php"><code>array()</code></pre></td>
<td>
$_GET、$_POST、$_COOKIE をフィルタするのに呼び出し可能なアイテム(PHP 関数、オブジェクトメソッド、静的クラスメソッド)の配列。デフォルトでは、未定義。
</td>
</tr>
<tr>
<th>output_filter</th>
<td>array</td>
<td><pre class="php"><code>array('Security::htmlentities')</code></pre></td>
<td>
View または Presenter に送信する変数をフィルタするのに呼び出し可能なアイテム(PHP 関数、オブジェクトメソッド、静的クラスメソッド)の配列。
セキュリティ上、出力フィルタ(output filter)は<strong>必ず</strong>定義する必要がある。
</td>
</tr>
<tr>
<th>htmlentities_flags</th>
<td>integer</td>
<td><pre class="php"><code>null</code></pre></td>
<td>
HTML エンティティをエンコーディングするときに使用するフラッグ。デフォルトは ENT_QUOTES。
</td>
</tr>
<tr>
<th>htmlentities_double_encode</th>
<td>boolean</td>
<td><pre class="php"><code>null</code></pre></td>
<td>
エンコードされたものを再エンコードするかどうか。デフォルトは <strong>false</strong>。
</td>
</tr>
<tr>
<th>auto_filter_output</th>
<td>boolean</td>
<td><pre class="php"><code>true</code></pre></td>
<td>
true にすると、ビューに渡すオブジェクトはすべて自動的にエンコードされる。
</td>
</tr>
<tr>
<th>whitelisted_classes</th>
<td>array</td>
<td><pre class="php"><code>array('stdClass', 'Fuel\\Core\\View',<br /> 'Fuel\\Core\\Presenter', 'Closure')</code></pre></td>
<td>
ビューに渡す変数の自動エンコーディングが有効なとき、オブジェクトを渡すときに問題が生じることがある。
この配列で定義したクラスは自動エンコードされない。
</td>
</tr>
<tr>
<th>csrf_autoload</th>
<td>boolean</td>
<td><pre class="php"><code>false</code></pre></td>
<td>
true にすると、check_token() を使用して CSRF トークンを自動的にチェックする。チェックに失敗すると SecurityException 例外が投げられる。
</td>
</tr>
<tr>
<th>csrf_autoload_methods</th>
<td>array</td>
<td><pre class="php"><code>array('post', 'put', 'delete')</code></pre></td>
<td>
csrf_autoload を true にすると、この配列にある http メソッドすべてで CSRF トークンが検証される。
</td>
</tr>
<tr>
<th>csrf_auto_token</th>
<td>boolean</td>
<td><pre class="php"><code>false</code></pre></td>
<td>
When true, Form::open() adds CSRF token hidden field automatically.
</td>
</tr>
</tbody>
</table>
<p class="note">"csrf_autoload" を有効にすると、指定したタイプの HTTP リクエスト<strong>すべて</strong>で CSRF トークンを含める<strong>必要があります</strong>。さもないと、検証に失敗し、SecurityException 例外が投げられます。</p>
<p class="note">オートロードが有効な場合で CSRF 検証失敗を自前で処理したい場合は、index.php で SecurityException 例外をキャッチすることができます。</p>
</section>
<article>
<h4 class="method" id="method_check_token">check_token($value = null)</h4>
<p><strong>check_token</strong> メソッドは、CSRF トークンをチェックします。<br />
check_token はトークンが存在することを保証します。また、チェックする値を受け取ったとき、(チェックの結果に関わらず)
トークンを再生成します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>チェックする CSRF トークン、未指定の場合は POST または JSON からの値をチェックする。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>boolean</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>Security::check_token();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_fetch_token">fetch_token()</h4>
<p><strong>fetch_token</strong> メソッドはクッキーから CSRF トークンを取得します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>なし</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$csrf_token = Security::fetch_token();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_js_fetch_token">js_fetch_token()</h4>
<p><strong>js_fetch_token</strong> メソッドは、現在の CSRF トークンを返す JavaScript fuel_csrf_token() 関数を作成します。AJAX 操作のためにフォーム送信時に適切なフィールドに挿入します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>なし</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// javascript 関数を出力する
echo Security::js_fetch_token();
// 生成された javascript コードをページで使用できる
<script type="text/javascript">
var current_token = fuel_csrf_token();
</script>
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_js_set_token">js_set_token()</h4>
<p>
<strong>js_set_token</strong> メソッドは、JavaScript fuel_set_csrf_token() 関数を生成します。
この関数は呼び出されたフォームに CSRF トークンフィールドをセットします。
onsubmit (フォーム送信)にこれを用いて、
csrf クッキーの値を更新します。
複数のウィンドウを開きたい場合、これを使う必要があります。
また CSRF トークンを厳密に更新する必要があります。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>なし</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// javascript 関数を出力する
echo Security::js_set_token();
// 生成された関数を onsubmit 時に実行します。
// 「this」パラメータを忘れないでください。更新するフォームを関数が知るために必要です。
<form onsubmit="fuel_set_csrf_token(this);">
<!-- do your stuff here -->
</form>
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_generate_token">generate_token()</h4>
<p>
<strong>generate_token</strong> メソッドは、セキュリティトークンを生成します。
このメソッドは、CSRF トークンを生成するのに使用します。セキュアでランダムなトークンが必要な場合、このメソッドを
アプリケーションの任意の場所で使用できます。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>なし</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$token = Security::generate_token();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_clean">clean($value, $filters = null)</h4>
<p><strong>clean</strong> メソッドは、提供されるフィルタを用いてデータを綺麗にします。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><i>必須</i></td>
<td>綺麗にされる値。文字列または文字列からなる配列。</td>
</tr>
<tr>
<th><kbd>$filters</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>
文字列を綺麗にするのに使用するフィルタ。フィルタは単一の値、または値からなる配列。それぞれの値は、妥当な PHP コールバック。
関数 ('htmlentities'), オブジェクト ($this), 静的メソッド ('Classname::method') を指定可能。
</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// まず strip tags を適用し、残った html エンティティを変換し、さらに特別なメソッドを適用する
$filters = array('strip_tags', 'htmlentities', '\\cleaners\\soap::clean');
$text = Security::clean($text, $filters);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_strip_tags">strip_tags($value)</h4>
<p><strong>strip_tags</strong> メソッドは、文字列から HTML および PHP タグを取り除きます。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><i>必須</i></td>
<td>タグを取り除かれる文字列</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$text = '<p>Test paragraph.</p>';
$text = Security::strip_tags($text);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_xss_clean">xss_clean($value, array $options = array())</h4>
<p><strong>xss_clean</strong> メソッドは、HTMLawed ライブラリを使用して、文字列から危険な HTML タグを取り除きます。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><i>必須</i></td>
<td>タグを取り除かれる文字列</td>
</tr>
<tr>
<th><kbd>$options</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>htmLawed の追加のオプション設定の配列。綺麗にする規則をカスタマイズする場合に使用する。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>string</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$text = '<SCRIPT>alert("XSS attack!")</SCRIPT>';
$text = Security::xss_clean($text);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_htmlentities">htmlentities($value, $flags = null, $encoding = null, $double_encode = null)</h4>
<p>
<strong>htmlentities</strong> メソッドは、HTML 文字を実体参照に変換します。 このメソッドは、PHP の htmlentities() 関数と同じ操作ですが、
配列やオブジェクトにも適用できます。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><i>必須</i></td>
<td>変換される文字列。</td>
</tr>
<tr>
<th><kbd>$flags</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>htmlentities() に渡すフラグ。未指定の場合、デフォルト値は ENT_QUOTES。</td>
</tr>
<tr>
<th><kbd>$encoding</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>値の文字エンコーディング。未指定の場合、デフォルト値は FuelPHP のデフォルト文字エンコーディング。</td>
</tr>
<tr>
<th><kbd>$double_encoding</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>true の場合、エンコードされた文字列をさらにエンコードしない。未指定の場合、デフォルト値は <strong>false</strong>。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed</td>
</tr>
<tr>
<th>例外</th>
<td>文字列にキャストできないオブジェクトを渡すと、<strong>RuntimeException</strong> が投げられる。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$text = '<p>Test paragraph.</p>';
$text = Security::htmlentities($text);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<h3 id="procedural_helpers">手続き型ヘルパ</h3>
<article>
<h4 id="function_e" class="method" data-class="">e($string)</h4>
<p><strong>e</strong> 関数は、<a href="#method_htmlentities">Security::htmlentities</a> の別名。</p>
<table class="method">
<tbody>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$string</kbd></th>
<td><em>必須</em></td>
<td>タグを取り除かれる文字列。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>string、<a href="#method_htmlentities">Security::htmlentities</a> の返り値</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$text = '<p>Test paragraph.</p>';
$text = e($text);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2016 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.8/develop/classes/security.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.8/develop_japanese/classes/security.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.8/develop_japanese/classes/security.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>