Security checklist for developers/ja

この文書は、 の補足として提供されています. これは、一般的な開発タスクと、実行する必要のあるセキュリティ対策のリストです.



セキュリティ チェックリスト
{| class="wikitable" | ! 作業の対象 ! チェックリスト


 * valign="top" |
 * valign="top" |



ブラウザーのCookie

 * valign="top" |
 * の代わりに を使用することでレビュアーの不安を軽減しましたか?
 * を使用して Cookie を取得しましたか?
 * を使用して Cookie を設定しましたか?


 * valign="top" |
 * valign="top" |



動的コード生成
関数、 関数、  関数の   パターン修飾子を使用することは避けてください. これらの機能は強力で便利ですが、本質的に安全ではありません:
 * valign="top" |


 * 正規表現で処理されるテキストに任意の文字列を入れることが簡単で、 パターン修飾子と組み合わせると、コード インジェクション攻撃を引き起こす可能性があります.
 * 文字列の一部であるコードを読み取り、メンテナンスすることが難しくなります.
 * 静的解析ツールは、コードの警告やエラーをキャッチできません.
 * opcode キャッシュ (APC など) は、文字列に混在するコードをキャッシュできません.
 * には、ガベージ コレクションの問題点がある場合があります.
 * A loop which has a  inside will create a new function on each iteration.

Sometimes you really do need these features (obviously  needs to run  ) but in most cases, we'd rather see the function broken out and referred as a callback.

Inline lambda functions will make it easier to make your callback inline while retaining the benefits of code that's written in native syntax instead of strings.


 * Anything external that is used in part of regex should be escaped with preg_quote ($externalStr, $delimiter). It puts a backslash in front of every character that is part of the regular expression syntax, and escapes also the delimiter given as second parameter:


 * valign="top" |
 * valign="top" |



外部プログラム

 * valign="top" |
 * executed the program via from namespace  ?
 * quoted all arguments to external programs using the above's secure parameter passing facilities (which is basically everything except for )?

Note that old /  are not recommended because they make it easier for developers to miss escaping a parameter.
 * valign="top" |
 * valign="top" |

フォーム

 * valign="top" |
 * used  to implement anti-CSRF measures?
 * used when checking the token to avoid timing attacks?
 * reduced reviewer anxiety by using or extending MediaWiki's existing form functionality?


 * valign="top" |
 * valign="top" |



GET データ

 * valign="top" |
 * reduced reviewer anxiety by using  instead of  ?


 * valign="top" |
 * valign="top" |



出力 (API、CSS、JavaScript、HTML、XML など)
Any content that MediaWiki generates can be a vector for XSS attacks.
 * valign="top" |
 * used the  and   helper classes?


 * reduced reviewer anxiety by using ResourceLoader to deliver CSS and JavaScript resources?
 * valign="top" |
 * valign="top" |



利用者提供 CSS
User provided CSS (Say for use in a  attribute) needs to be sanitized to prevent XSS, as well as to disallow insertion of tracking images (via background-image), etc
 * valign="top" |
 * Use the Sanitizer::checkCss method for any css received from a user, possibly along with the Html class.


 * For CSS provided by the extension (and not the user), this is not needed (and will remove some valid things like ). However, extension provided CSS should go in stylesheets loaded by ResourceLoader, and not in   attributes.
 * valign="top" |
 * valign="top" |



POST データ

 * valign="top" |
 * reduced reviewer anxiety by using  instead of
 * Always validate that any POST data received is what you expect it to be


 * valign="top" |
 * valign="top" |



クエリ文字列

 * valign="top" |
 * See #GET data above


 * valign="top" |
 * valign="top" |

セッション

 * valign="top" |


 * valign="top" |
 * valign="top" |



レビュアーの不安

 * valign="top" |
 * Clearly added comments to explain unexpected or odd parts of your code?


 * valign="top" |
 * valign="top" |



SQL クエリ

 * valign="top" |
 * used MediaWiki's database wrappers?


 * }



自動チェック
Some of these issues can be checked with phan-taint-check-plugin, which is required for all MediaWiki code in Wikimedia production. This is of course just a tool, and it cannot detect all issue types, and may miss issues even in the issue types it can check for.



関連項目

 * Security for developers