• 検索結果がありません。

hackety-hack.com を用いたテストケース生成機能の検証

第 4 章 提案手法のツール化と実験

4.3 機能評価 (2) テストケースの生成とテストの実施

4.3.2 hackety-hack.com を用いたテストケース生成機能の検証

このポリシーを用いた静的検証の結果、ナビゲーションエラーを含むセキュリ ティ上の問題は見つからなかった。そこで、セキュリティ警告にもとづいたテス トケース生成を行うためにフォルトインジェクションを行った。Listing4.4に示

すように’raw’コマンドによるクロスサイトスクリプティングのエラーと、権限の

チェックの無効化によるNavigation errorを埋め込む。埋め込んだバグに対応す るツールの警告はそれぞれ、“RRMW003”、“RRMW002”となった。

1 diff --git a/app/views/questions/_list.html.haml b/app/views/questions/

_list.html.haml

2 index fe52303..7a9c7c5 100644

3 --- a/app/views/questions/_list.html.haml

4 +++ b/app/views/questions/_list.html.haml

5 @@ -3,6 +3,7 @@

6 %h3= question.answers.count

7 #{question.answers.count == 1 ? "answer" : "answers"}

8 .summary

9 + = raw question.title

10 %h2.title= link_to question.title, resource_path(question)

11 .meta

12 Asked by

13diff --git a/app/views/questions/show.html.haml b/app/views/questions/

show.html.haml

14index b53a34b..29a84f6 100644

15--- a/app/views/questions/show.html.haml

16+++ b/app/views/questions/show.html.haml

17@@ -3,8 +3,10 @@

18 = resource.title

19

20 - content_for :sidebar do

21- - if can? :update, resource

22- = link_to ’Edit’, edit_resource_path, :class => "edit btn"

23+ NAV ERROR

24+ = link_to ’Edit’, edit_resource_path, :class => "edit btn"

25+ -# if can? :update, resource

26+ -# = link_to ’Edit’, edit_resource_path, :class => "edit btn"

27 - if can? :destroy, resource

28 = link_to ’Delete’, resource_path, :class => "delete btn", :confirm

=> ’Are you sure?’, :method => :delete

Listing 4.4: Example requirements

次に、各種のセキュリティ機能と、セキュリティ警告を確認するためのテスト ケースの生成を行う。テストケース生成の制御は“testplan.json”ファイルで行う。

Listing4.5がフォルトインジェクションされたhackety-hackに対するテストプ ランの抜粋である。前半ではCSRF対策や、アクセス制御に関するコマンドのテ ストケース生成のための設定となる。

1 {

2 // CSRF

3 "protect_from_forgery": {

4 "type": "csrf",

5 "testcase_type": "Modification of existing testcase",

6 "testcase": {

7 "init_steps": [

8 "Given I’m logged in as someone who can post to the blog",

9 "When I visit the blog admin page"

10 //"And I fill out the new blog form"

11 ],

12 "target_step": "And I press \u0022Create Blog post\u0022",

13 "success_step": "Then I should see that my post has been created"}

14<snip>

15 // Devise

16 "authenticate_user!": {

17 "type": "authentication",

18 "testcase_type": "automatic",

19 "target_path": "questions",

20 "success_text": "Have A Question?",

21 "error_text": "You need to sign in or sign up before continuing."

22 },

23 // CanCan

24 "load_and_authorize_resource": {

25 "type": "global_authorization",

26 "testcase_type": "automatic",

27 "strong_privilege_user": "blog_poster",

28 "weak_privilege_user" : "user",

29 "strong_privilege_path": "blog admin page",

30 "success_text": "New Post",

31 "error_text": "You are not authorized to access this page"

32 },

33 // CanCan View can

34 "can?": {

35 "type": "conditional_authorization",

36 "testcase_type": "Use existing testcase",

37 "testcases": {

38 "navigation and authorization - OK": [

39 "Given questions exist",

40 "Given a logged in moderator",

41 "When I visit the questions page",

42 "When I click the first question link",

43 "# Then show me the page",

44 "Then I should see \u0022Edit\u0022"

45 ],

46 "navigation and authorization - NG": [

47 "Given questions exist",

48 "Given a logged in user",

49 "When I visit the questions page",

50 "When I click the first question link",

51 "# Then show me the page",

52 "Then I should not see \u0022Edit\u0022"

53 ]

54 }

55 },

56

57<snip>

58 // Make sure, this is a Nav. error

59 "RRMW0002": {

60 "type": "Missing view side authorization check",

61 "testcase_type": "Use existing testcase",

62 "testcases": {

63 "replay navigation error": [

64 "Given questions exist",

65 "Given user exist",

66 "When I visit the questions page",

67 "When I click the first question link",

68 "When I click \u0022Edit\u0022",

69 "And I should see \u0022Sign In\u0022"

70 ],

71 "TO BE": [

72 "Given questions exist",

73 "Given user exist",

74 "When I visit the questions page",

75 "When I click the first question link",

76 "And I should not see \u0022Edit\u0022"

77 ]

78 }

79 },

80 "RRMW0003": { // XSS Type 1: Reflected XSS (or Non-Persistent)

81 "type": "Cross Site Scripting",

82 "subtype": "Type 1: Reflected XSS",

83 "testcase_type": "Modification of existing testcase",

84 "testcase": {

85 "init_steps": [

86 "Given I am a user that has created a question",

87 "When I visit the new question page"

88 //"And I fill out the new blog form"

89 ],

90 "target_steps": [

91 "And I fill in \u0022Title\u0022 with",

92 "And I fill in \u0022Description\u0022 with"

93 ],

94 "post_step": "And I press \u0022Ask Everyone\u0022"}}}

Listing 4.5: Example test plan

CSRFのテストプランでは、アプリケーション上の任意のPOST(Submitボタ ン)を行うページの正常なアクセスをCucumberのテストシナリオで与える。これ に対応して生成されたテストケースをListing4.6に示す。与えられた正常なテス トシナリオとそれを元に、hidden_fieldに対して改ざんを加えるテストシナリオ の2つが生成される。後者の場合は、正常であればCSRFのチェックにより、ホー ムページへリダイレクトされる。

テストケースの生成については、個別のコマンドや警告に応じた設定方法を用 いている。Device、CanCanなどの既知のパッケージを用いた場合には、一般的

なテストシナリオが利用できるため、開発者はテストケース生成の場所や、テス トで利用する文字列等を設定する。CSRFやXSSなどの不正な値の入力について は、通常の動作シナリオから派生して、攻撃シナリオを生成させている。

1 Feature: CWE-352: Cross-Site Request Forgery (CSRF)

2 The web application does not, or can not, sufficiently verify

3 whether a well-formed, valid, consistent request was intentionally

4 provided by the user who submitted the request.

5

6 Scenario: RRMT0005[0]

7 normal access (existing testcase)

8

9 Given I’m logged in as someone who can post to the blog

10 When I visit the blog admin page

11 And I press "Create Blog post"

12 Then I should see that my post has been created

13

14 Scenario: RRMT0005[1]

15 tampered hidden_field (existing testcase)

16

17 Given I’m logged in as someone who can post to the blog

18 When I visit the blog admin page

19 And I press "Create Blog post" with tampered authenticity_token

20 Then I should see that you need to sign in or sign up before continuing.

Listing 4.6: Example requirements

4.3.3 まとめ

機能評価(2)では、RailsのWebアプリケーションの実装コードを静的解析し、

セキュリティ上問題となる箇所を特定し、その箇所に対するセキュリティテスト ケースを生成することで、問題箇所が実際に脆弱性を持つか確認する手法につい て評価した。

この実験ではテストフレームワークのCucumberを用いたセキュリティテスト ケースの自動生成が可能であることを確認した。表4.11に示すように、フレーム ワークのエスケープ機能の有効性の確認、静的検証で指摘した問題箇所の、(動的)

テストによる脆弱性の判定が可能となることを確認した。

また、hackety-hack.comを用いた実験では、CSRFやXSSなどのような実装 に起因するセキュリティ問題に追加して、設計に関係するアクセス制御ポリシーの 作成からその実装コードの静的検証および動的な機能テストまでを一貫してツー ルで管理する手法について有効性を確認した。

Outline

関連したドキュメント