「開発:セキュリティ」の版間の差分

提供:MoodleDocs
移動先:案内検索
90行目: 90行目:
* [[開発:セキュリティ:Cross-site_request_forgery|Cross-site request forgery]] (XSRF)
* [[開発:セキュリティ:Cross-site_request_forgery|Cross-site request forgery]] (XSRF)
* [[開発:セキュリティ:クロスサイトスクリプティング|クロスサイトスクリプティング (Cross-site scripting)]] (XSS)
* [[開発:セキュリティ:クロスサイトスクリプティング|クロスサイトスクリプティング (Cross-site scripting)]] (XSS)
* [[開発:セキュリティ:SQL injection|SQL injection]]
* [[開発:セキュリティ:SQLインジェクション|SQLインジェクション]]
* [[開発:セキュリティ:Command-line injection|Command-line injection]]
* [[開発:セキュリティ:Command-line injection|Command-line injection]]
* [[開発:セキュリティ:Data-loss|Data-loss]]
* [[開発:セキュリティ:Data-loss|Data-loss]]

2010年1月25日 (月) 16:09時点における版

作成中です - Mitsuhiro Yoshida 2010年1月9日 (土) 15:53 (UTC)

このページでは、不道徳な人たちがMoodleサイトを攻撃できないよう、セキュアなMoodleコードを書く方法を記述します。

また、ページでは、一般的なタイプの脆弱性について整理しています。それぞれのタイプに関して、以下のことを説明します:

  1. 危険性とは
  2. トラブルを避けるため、Moodleはどのように設計されているか
  3. Moodle開発者として、あなたのコードをセキュアなものにするには何をすべきか
  4. あなたのMoodleをさらに安全にするため、管理者として何をすべきか

それぞれの脆弱性に関する説明は、下記一覧でリンクされている、異なるページにあります。

また、このページでは、ガイドラインのキーとなる内容すべてに関して、要約しています。

ウェブアプリケーションのセキュリティ

ウェブアプリケーションをセキュアにするための必要条件

いくつかの法人では、ウェブアプリケーションに関して、最大レベルのセキュリティを要求しています。多くの場合、あなたは類似の一般的な推奨内容を読むことになります:

  • 管理バックエンドを分離する。
  • ウェブアプリケーションに機密情報を保存しない。
  • SSLを使用して、コミュニケーションを暗号化すべき。
  • ユーザすべての行動をログに記録する。
  • サーバアプリケーションは、完全に分離されるべき。
  • ユーザからサーバにファイルをアップロードさせない。
  • ユーザからサーバにリッチテキストを入力させない (プレインテキストのみに制限する)。
  • 分離されたチャネル経由で、ユーザIDおよび操作を認証する。
  • すべてのソフトウェアを常に最新にする。
  • サードパーティのブラウザ拡張モジュールを推奨しない。
  • 1つのウェブページのみ使用して、異なるサイトを複数のウィンドウで開かない。セキュアアプリケーションを使用する前および後に、ブラウザを閉じる/開く。

ウェブベースのバンキングシステムは、これらの「セキュア」なウェブアプリケーションの良い例です。ここではセキュリティが最優先されます - セキュリティ上の問題は、顧客、銀行または保険会社にコストを発生させ、銀行の世間一般に対するイメージも失墜させます。限定要因は、アプリケーション開発、メンテナンス、ユーザビリティであると考えられますが、代替チャネルでのコミュニケーションコストも含まれます。

安定したセキュリティ

今日、あなたは、数多くのウェブアプリケーションがセキュリティデザインのルールに反していることを知ることができます。例えば、ウェブベースのメールシステムでは、ファイル添付としてリッチテキストを受け入れたり、極めて機密な情報をメールメッセージが含んでいます。実際のところ、Web 2.0の考え方はセキュリティデザインのルールに直接反して、誰でもコンテンツを送信することができています - アプリケーション開発者/管理者のみ信頼できるコンテンツを追加すべきです。

ウェブアプリケーションを設計する場合、私たちのユーザが何をサポートされるべきなのか調査して、機能およびセキュリティ間に適度なバランスを見つけます。

Moodleセキュリティデザイン

ウェブアプリケーションのセキュリティは、使用目的およびそれぞれのタイプのユーザが利用できる機能に依存します。

ユーザタイプ

管理者

管理者には、以下の権限があります:

  • すべての設定を変更する
  • コースを作成する
  • すべてのコースにアクセスする
  • 言語パックを変更する
  • すべてのユーザを変更する

間接的に、管理者はシェルおよびPHPコードの実行を許可されます。Moodle管理者は、config.php内のハードコードされた設定により、制限を受ける場合もあります。低水準のサーバでは、管理者はPHPコードを読んで修正することができるため、権限を制限することはできません。

すべての管理者は、完全に信頼された存在です。

教師

Teachers are usually creating course content, enrolling students and teaching. They usually need following privileges:

  • upload files and submit html texts
  • create and manage activities
  • access student grades and other personal information

Uploading of files with javascript, flash and other scripted is often considered to be a security risk. Unfortunately we can not remove these risks from teacher roles because even basic SCORM packages consist of html and javascript which needs to use user session.

Browser trusts everything coming from one server, it does not know anything about our courses or origin of data. Once the file is uploaded to server it becomes part of the server application. It is not possible to differentiate between wanted and unwanted code stored on the server.

All teachers with risky capabilities have to be trusted, it is not possible to give teacher access to students. In theory teachers may use XSS attacks to gain administrator access.

Technically it would be possible to create system where teachers can not attack other users but it would prevent all javascript, flash, SCORM, java, html forms, SVG, etc.

学生

Students are participating in courses, they are not trusted. Students need following privileges:

  • post formatted text with inline images and attachments
  • upload binary documents

Uploaded files must not be opened directly in browser from the same server. Instead the files need to be served from different domain, or server has to force download of all files to local hard drive before opening them. Serving of untrusted files from different domain will be implemented in 2.0.

All student submitted text has to be sanitised before printing the text on any page, this prevent XSS attacks on other users but at the same time prevents flash, javascript, SVG and all other HTML scripting. There are two types of html cleaning - less reliable blacklisting (KSES) and more robust whitelisting (HTML Purifier).

ゲスト

For security reasons unregistered users can not be allowed to upload any files or submit any text that is stored in database. Guests could try to spam other users, exploit problems in html cleaning routines, abuse other vulnerabilities or try social engineering based attacks.

Sites with enabled user sign-up via email have to take extra care in order to prevent spamming and other types of attacks.

ケイパビリティリスク

Moodle is very flexible system, administrators may define multiple roles. Each role is a set of capabilities defined at system level, roles may be modified via overrides at lower context levels. Risks are part of description of each capability, administrators have to make sure only trusted users get potentially dangerous capabilities.

セキュリティ脆弱性の一般的なタイプ

Summary of the guidelines

Authenticate the user

  • With very few exceptions, every script should call require_login or require_course_login as near the start as possible.

Verify course and module access

  • all course areas have to be protected by "require_login" or "require_course_login" with correct $course parameter
  • all module areas have to be protected by "require_login" or "require_course_login" with correct $course and $cm parameter

Check permissions

  • Before allowing the user to see anything or do anything, call to has_capability or require_capability.
  • Capabilities should be annotated with the appropriate risks.
  • If appropriate, restrict what people can see according to groups.

Don't trust any input from users

  • Use moodleforms whenever possible, with an appropriate setType method call for each field.
  • Before performing actions, use is_post_with_sesskey to check sesskey and that you are handling a POST request.
    • In Moodle 1.9, use data_submitted() && confirm_sesskey() instead.
  • Before destroying large amounts of data, add a confirmation step.
  • If not using a moodleform, clean input using optional_param or required_param with an appropriate PARAM_... type.
    • Do not access $_GET, $_POST or $_REQUEST directly.
    • Group optional_param and required_param calls together at the top of the script, to make them easy to find.

Similarly, clean data from other external resources like RSS feeds before use.

Clean and escape data before output

  • Use s or p to output plain text content.
  • use format_string to output content with minimal HTML like multi-lang spans (for example, course and activity names).
  • Use format_text to output all other content.
    • Only use $options->noclean if it requires a capability with RISK_XSS to input that content (for example web page resources).
  • Before Moodle 2.0, input from optional_param or required_param must have stripslashes or stripslashes_recursive applied if it is being output directly, rather than being stored in the database.
  • Data destined for JavaScript should be escaped using $PAGE->requires->data_for_js (Moodle 2.0) or addslashes_js (Moodle 1.9).

See Development:Output functions for more details.

Escape data before storing it in the database

  • Use the XMLDB library. This takes care of most escaping issues for you.
  • When you must use custom SQL code, use place-holders to insert values into the queries.
    • Before Moodle 2.0, you have to build SQL by concatenating strings. Take particular care, especially with quoting values, to avoid SQL injection vulnerabilities.
  • Before Moodle 2.0, data loaded from the database must have addslashes or addslashes_object applied to it before it can be written back to the database. (addslashes should no longer be use anywhere in Moodle 2.0 code.)
  • In Moodle 2.0 variables must be passed to database queries through bound parameters

Escape data before using it in shell commands

  • Avoid shell commands if at all possible.
    • Look to see if there is a PHP library instead.
  • If you can't avoid shell commands, use escapeshellcmd and escapeshellarg.


Log every request

  • Every script should call add_to_log.


Other good practice

... that helps with security.

  • Structure your code nicely, minimising the use of global variables. This makes the flow of data, and hence security, easier to verify.
  • Initialise objects ($x = new stdClass;) and arrays ($x = array()) before you first use them.
  • Test every input field with tricky input to ensure that it is escaped and un-escaped the right number of times everywhere, and that Unicode characters are not corrupted. My standard test input is:
< > & &lt; &gt; &amp; ' \' 碁 \ \\

関連情報