Enhancement(機能追加・改善) #1741
XSS 脆弱性、 CSRF 脆弱性のテストを完備できるように体制を整える
100%
説明
XSS 脆弱性、 CSRF 脆弱性のテストを完備できるように体制を整える
http://www.openpne.jp/archives/5532/#m-5 も参照のこと。
- XSS 脆弱性のテストをできるかぎりテンプレート化する
- CSRF 脆弱性のテストをできるかぎりテンプレート化する
- これらのテストの動作を妨げないように、既存の functional test をメンテナンスする
- XSS, CSRF 脆弱性のテストの書き方についてマニュアルを作り、人海戦術ですべてのアクションについての両脆弱性のテストを完備できるようにする
関連するチケット
関係しているリビジョン
fixed test for uploading member profile image doesn't work (refs #1741)
changed repositories in the current connection before executing functional test (refs #1741)
added the opTesterHtmlEscape class and I've tried this class in member/profile and community/search (refs #1741)
fixed some functional tests for pc_frontend is broken (refs #1741)
fixed functional test in pc_backend, added CSRF check (refs #1741)
fixed supported the i18n in checkCSRF() (refs #1741)
CSRF check method changed to the regular expression (refs #1741)
added community of the pc_backend to the functional test (refs #1741)
added member of the backend actions to the functional test (refs #1741)
added the profile actions of pc_backend for the functional test (refs #1741)
added the sns/changeRichTextareaButtonOrder action of pc_backend for the functional test (refs #1741)
added the connection actions of pc_backend for the functional test (refs #1741)
added design/editGadget action of pc_backend for the functional test (refs #1741)
added the admin actions of pc_backend for the functional test (refs #1741)
added the navigation/sort action of pc_backend for the functional test (refs #1741)
added the default actions of pc_backend for the functional test (refs #1741)
added the monitoring actions of pc_backend for the functional test (refs #1741)
fixed removed 'echo' (refs #1741)
added the friend actions of pc_frontend for the functional test (refs #1741)
added the community actions of pc_frontend for the functional test (refs #1741)
added the member actions of pc_frontend for the functional test (refs #1741)
added the member actions of pc_frontend for the functional test (refs #1741)
added the connection actions of pc_frontend for the functional test (refs #1741)
added the XSS/CSRF functional tests for oauth module in the pc_frontend application (refs #1741)
added a XSS test for connection/show in pc_frontend (refs #1741)
fixed the form for modifying consumer that doesn't display some localized form error message (refs #1741)
fixed the deprecated error message make generate invalid array keys (refs #1741)
fixed failed tests of the member module that have mistakes in test and / or test data (refs #1741)
changed to reset repositories in current connection for unit test (refs #1741)
added confirmation/list action of pc_frontend for the functional test (refs #1741)
fixed from the parameters you can specify additional selectors (refs #1741)
fixed test for uploading member profile image doesn't work (refs #1741)
(cherry picked from commit 8e5da56988dfa09feef6ab4d3d0716a8798ef60a)
changed repositories in the current connection before executing functional test (refs #1741)
(cherry picked from commit b0173c5dff1c7f653d789c708fc264d6c8d87131)
added the opTesterHtmlEscape class and I've tried this class in member/profile and community/search (refs #1741)
(cherry picked from commit a96c395850668970bf0783c5bcbc7bdf590e7ceb)
fixed some functional tests for pc_frontend is broken (refs #1741) (cherry picked from commit fbb6aebedd18366313c62abe3f0d51084d856517)
Conflicts:
test/functional/pc_frontend/confirmationActionsTest.php
test/functional/pc_frontend/friendActionsTest.php
fixed functional test in pc_backend, added CSRF check (refs #1741) (cherry picked from commit c806cfd7568d12a6c5a6417f4aab7cde0e60997f)
Conflicts:
lib/test/opTestFunctional.class.php
test/functional/pc_backend/monitoringActionsTest.php
fixed supported the i18n in checkCSRF() (refs #1741)
(cherry picked from commit fb7cd9dcfd6fc4f13ecda3d500d5a2fe8f8e98c5)
CSRF check method changed to the regular expression (refs #1741)
(cherry picked from commit 2bece83c67dcb5ee51242d73c7461a3c6ce5b89b)
added community of the pc_backend to the functional test (refs #1741)
(cherry picked from commit 65e82c9d909643dfee8dad9eb718cfb0cbac8662)
added community of the pc_backend to the functional test (refs #1741) (cherry picked from commit 65e82c9d909643dfee8dad9eb718cfb0cbac8662)
added the profile actions of pc_backend for the functional test (refs #1741)
(cherry picked from commit 8222785930a86b369c36397c097461f30d528f3d)
added the sns/changeRichTextareaButtonOrder action of pc_backend for the functional test (refs #1741) (cherry picked from commit f9325ac2f6b2d682d957c722bca9a5685772f0e1)
Conflicts:
test/functional/pc_backend/snsActionsTest.php
added the connection actions of pc_backend for the functional test (refs #1741)
(cherry picked from commit b464b7f4cdbcbf88b85cbb9e490e55f461971904)
added design/editGadget action of pc_backend for the functional test (refs #1741)
(cherry picked from commit c4cae9d994c9975afcb8bd53ba5379acf55497a8)
added the admin actions of pc_backend for the functional test (refs #1741)
(cherry picked from commit f4935d411eda95c5c785c1cf2600e5d9ab9d64f5)
added the navigation/sort action of pc_backend for the functional test (refs #1741)
(cherry picked from commit f095d1c93c946c1d08a6154cb56ede9f8d328c92)
added the default actions of pc_backend for the functional test (refs #1741)
(cherry picked from commit 320bda95fb8de33fa85481a92b755cfa96560023)
added the monitoring actions of pc_backend for the functional test (refs #1741)
(cherry picked from commit 4722f6fbe718778d3d2429593aad2c469aee8a32)
fixed removed 'echo' (refs #1741)
(cherry picked from commit fbf7f0d7df273d147c3176fdfc5ff67002a3a8df)
added the friend actions of pc_frontend for the functional test (refs #1741)
(cherry picked from commit 32d8fa89929b9c6780c3cd27735d0759adf9f94a)
added the community actions of pc_frontend for the functional test (refs #1741) (cherry picked from commit d946a010edd8a57bd0f12ea4ed759900ddbddfdc)
Conflicts:
test/functional/pc_frontend/communityActionsTest.php
added the member actions of pc_frontend for the functional test (refs #1741) (cherry picked from commit ab428e5ac1ab1c4b908e4d28d0db6626a500a553)
Conflicts:
test/functional/pc_frontend/memberActionsTest.php
added the member actions of pc_frontend for the functional test (refs #1741)
(cherry picked from commit eea5c45392dc5cceeba6f1ee0a88e95bdc043516)
added the connection actions of pc_frontend for the functional test (refs #1741)
(cherry picked from commit 9fb7596a8317089a6ae45b412c9f5cfddaccf268)
added the XSS/CSRF functional tests for oauth module in the pc_frontend application (refs #1741) (cherry picked from commit af270d338cc36dfbc5edd2cf1e046aec8bbf7554)
Conflicts:
test/fixtures/xss_test_data.yml
added a XSS test for connection/show in pc_frontend (refs #1741)
(cherry picked from commit d4eba212bf281f9780a2edb4327d34d5aea79733)
fixed the form for modifying consumer that doesn't display some localized form error message (refs #1741)
(cherry picked from commit 9378217b99386200a4007190c2666b1d963b1b24)
fixed the deprecated error message make generate invalid array keys (refs #1741)
(cherry picked from commit 77f526c3b987e790ef7930edf13a3abb44b89e1d)
fixed failed tests of the member module that have mistakes in test and / or test data (refs #1741)
(cherry picked from commit 6f0ca49bb2f402846bf83abe06efa476eaf79a76)
changed to reset repositories in current connection for unit test (refs #1741)
(cherry picked from commit c64610b5946f4cb58f34319634f674bb3cf2a7a2)
added confirmation/list action of pc_frontend for the functional test (refs #1741) (cherry picked from commit 140172db71d044f6f84d4d9baf326bbdaaa30b57)
Conflicts:
test/functional/pc_frontend/confirmationActionsTest.php
fixed from the parameters you can specify additional selectors (refs #1741)
(cherry picked from commit 87579ef032ad3911c2edeeb64caf5875a84c510a)
履歴
#1 Kousuke Ebihara が13年以上前に更新
XSS 脆弱性のテストについては http://github.com/ebihara/OpenPNE3/commits/36-functional-test-improvement にて動いています。
#2 Kousuke Ebihara が13年以上前に更新
マニュアルはこんな感じか
テスト作成手順¶
まずリストを確認し、 XSS の functional test が作られていないアクションについて、テストを作成します。
作業に入る前に、リストのテストを作成したいアクションの欄をマークしてください。
リストの更新が終わったら、そのアクションの全テンプレートを確認します。テンプレート中にユーザ入力値に基づいて動的に生成される箇所があれば、その出力についてテストを記述する必要があります。
本来はユーザ入力値に限らず、動的な値を埋め込むすべての場所に対して、 HTML 出力を意図している場合を除いて、 HTML 特殊文字のエスケープがおこなわれているかどうかを確認するべきですが、作業量や難易度等を考慮し、今回はそこまではおこなわず、あくまでユーザ入力値に限定します。
DB 内データの出力に関するテスト¶
まず、そのテンプレート中でモデルから得られる値を埋め込んでいるすべての箇所を列挙します。
XSS 脆弱性テスト用のテストデータ (test/fixtures/xss_test_data.yml) を確認し、テストに必要な情報がなければ作成します。
テストデータは以下のような形式になっています。
Member: html_member_1: id: 1055 # it means "XSS (X-55)" name: "<&\"'>Member.name ESCAPING HTML TEST DATA" is_active: 1
文字列を受け入れるフィールドに対して、テスト用の文字列を指定する以外には普通の fixture と変わらずに記述できます。
テスト用の文字列は、かならず、以下のような書式でなければなりません。
<&"'>モデル名.カラム名 ESCAPING HTML TEST DATA
こうして挿入されたテストデータが表示されるアクションのためのテストにおいて、 opTesterHtmlEscape が提供するメソッド群を利用することで、意図通りのエスケープがおこなわれているかどうかを確認することができます。
そのアクションの出力に存在する、「Member.name」の値がすべてエスケープされているかどうかを確認するには、以下のように opTesterHtmlEscape::isAllEscapedData() を実行します。
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color())); $browser ->info('member/profile') ->get('member/1055') ->with('html_escape')->begin() ->isAllEscapedData('Member', 'name') ->end()
反対に、そのアクションの出力に存在する、「Member.name」の値がすべてエスケープ*されていないかどうか*を確認するには、 opTesterHtmlEscape::isAllRawData() を実行してください。
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color())); $browser ->info('member/profile') ->get('member/1055') ->with('html_escape')->begin() ->isAllRawData('Member', 'name') ->end()
また、モデルの値の出力が op_truncate() によって truncate される場合は、 opTesterHtmlEscape::countEscapedData() や opTesterHtmlEscape::countRawData() を用いてください。これは、モデル名やカラム名の他に、期待するデータの数や op_truncate() に渡されている引数も受け付けます。以下は、 op_truncate($string, $width = 36, $etc = '', $rows = 3) を使用したモデルの値の出力が 3 つ存在することをテストする場合の例です。
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color())); $browser ->info('member/profile') ->get('member/1055') ->with('html_escape')->begin() ->countEscapedData(3, 'Member', 'name', array( 'width' => 36, 'etc' => '', 'rows' => 3, )) ->end()
それ以外のユーザ入力値に関するテスト¶
それ以外のユーザ入力値についても、変則的ではありますが、同じようにしてテストをおこなうことができます。
たとえば、アクションの出力中に含まれるリクエストパラメータ html の出力をテストしたい場合、以下のように記述してください。
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color())); $browser ->info('member/profile') ->get('member/1055', array('html' => opTesterHtmlEscape::getRawTestData('request', 'html'))) ->with('html_escape')->begin() ->isAllEscapedData('request', 'html') ->end()
これにより、 <&"'>request.html ESCAPING HTML TEST DATA という値の出力をテストすることになります。
opTesterHtmlEscape::getRawTestData() および opTesterHtmlEscape::isAllEscapedData() の第一引数や第二引数の値は、そのアクション内でユニークなものになっていればなんでも構いません。
#3 Kousuke Ebihara が13年以上前に更新
対応するべきアクションの一覧(作業進捗状況の一覧になるべきもの)は http://spreadsheets.google.com/pub?key=0Ain-euBnqQDLdElHWS1DbFBzRWthMnZUdmZxTlpnQnc&hl=en&output=html にあります (まだ作成途中です)
#4 Kousuke Ebihara が13年以上前に更新
https://spreadsheets.google.com/pub?key=0Ain-euBnqQDLdGxzMnoyOFhBaUlQUVJnS0Y0YXNzZlE&output=html
ここで進捗管理がおこなえるようにしました。この扱い方等のルールについても、なるべく早く準備します。
とり急ぎ。
#5 Kousuke Ebihara が13年以上前に更新
http://redmine.openpne.jp/projects/op3/wiki/Rule_of_functional_test_for_36x
この作業についてのルールを書きました。
#6 Kousuke Ebihara が13年以上前に更新
- 対象バージョン を OpenPNE 3.6beta7 から OpenPNE 3.6beta8 に変更
#7 Kousuke Ebihara が約13年前に更新
- 対象バージョン を OpenPNE 3.6beta8 から OpenPNE3.6beta9 に変更
#9 Kousuke Ebihara が約13年前に更新
- 対象バージョン を OpenPNE3.6beta9 から OpenPNE3.6beta11 に変更
#10 Masato Nagasawa がほぼ13年前に更新
- 対象バージョン を OpenPNE3.6beta11 から OpenPNE 3.6.0 に変更
#11 Masato Nagasawa がほぼ13年前に更新
- 対象バージョン を OpenPNE 3.6.0 から OpenPNE3.6beta11 に変更
#12 Kousuke Ebihara がほぼ13年前に更新
- 期日 を 2011-06-24 にセット
#13 誠二 天重 が9年以上前に更新
- 関連している Bug(バグ) #1877: functional test で特定のパラメータで checkElement() を呼び出すとエラーになる を追加