EC-CUBE4.1系/4.2系におけるRCE可能な脆弱性(JVN#29195731)

更新履歴
2023/11/09 15:00
目次の追加
2023/11/07 14:00
JVNからの公表内容情報へのリンクを追加
2023/10/26 13:00
初版公開

目次

EC-CUBEにおけるRCE可能な脆弱性

EC-CUBE 4.1系/4.2系におけるRCE可能な脆弱性(危険度: 低)があることが判明いたしました。

脆弱性そのものは、修正の反映によりすぐに解決するものです。
以下のいずれかの方法により、ご対応をお願いいたします。

皆様にはお手数おかけし誠に申し訳ございません。
本脆弱性における被害報告は現時点でございませんが、できるだけ速やかにご対応をお願いいたします。

脆弱性の概要

EC-CUBEにおけるRCE可能な脆弱性

危険度:

不具合が存在するEC-CUBEのバージョン:

詳細:

該当バージョンのEC-CUBEにはRCE可能な脆弱性が存在します。EC-CUBEはテンプレートエンジンとしてTwigを利用していますが、EC-CUBEの一部画面でTwigに対する設定不備が存在し、攻撃者が対象のシステム上で任意のコードを実行できる可能性があります。


JVNからの公表内容 (2023/11/07公開)

JVN#29195731: EC-CUBE 3系および 4系において任意のコードを実行される脆弱性

修正ファイル適用による注意点

以下の注意事項をご確認お願いいたします。

本修正ファイルを適用することにより、TwigのSandBox機能が有効になります。
Sandboxは指定されたTwigのタグ、関数、フィルターのみを許可します。
そのため、「商品情報>商品登録>フリーエリア」や「コンテンツ管理>ページ管理>metatag」で指定されたTwigのタグ、関数、フィルター以外を使用している場合、フロントでは、該当箇所の登録情報が表示されなくなります。
ただし、該当箇所以外の情報は通常通り表示されます。
この点をあらかじめご了承ください。
app/config/eccube/packages/twig_extensions.yamlで、利用しているTwigのタグ、関数、フィルターを登録することで、それらを利用可能にすることができます。

修正の際、eccube.twig_sandbox.allowed_*** の部分に必要な内容を追加してください。
以下のymlファイルを参考にしてください。
twig_extensions.yaml

修正方法1: 修正ファイルを利用する場合

開発環境がある場合は、まず開発環境でお試しください。
以下の手順に従って、修正ファイルの反映をお願いいたします。

  1. 修正ファイルのダウンロード

    ご利用中のEC-CUBEのバージョンに該当する修正ファイルをダウンロードしてください。
    ※EC-CUBEのバージョンはこちらの手順でご確認ください。
    ※修正ファイルは各バージョンの最新版に対して作成しています。旧バージョンをご利用の場合は、「修正方法2」のご対応をお願いします。
    ※対象のファイルに対して既にカスタマイズをしている場合は、「修正方法2」のご対応をお願いします。

    ダウンロードし、解凍していただきますと、以下の修正ファイルがあります。必ず該当するバージョンのファイルをご利用ください。

    4.1.2-p2

    • app/config/eccube/packages/twig_extensions.yaml
    • src/Eccube/Resource/template/default/Product/detail.twig
    • src/Eccube/Resource/template/default/default_frame.twig
    • src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php
    • src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php

    4.2.2

    • app/config/eccube/packages/twig_extensions.yaml
    • src/Eccube/Resource/template/default/Product/detail.twig
    • src/Eccube/Resource/template/default/default_frame.twig
    • src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php
    • src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php
  2. EC-CUBEファイルのバックアップ

    あらかじめEC-CUBEファイル全体のバックアップを行ってください。

  3. 修正ファイルの反映

    以下のファイルを上書き更新してください。

    上書きするファイル

    4.1.2-p2

    • app/config/eccube/packages/twig_extensions.yaml
    • src/Eccube/Resource/template/default/Product/detail.twig
    • src/Eccube/Resource/template/default/default_frame.twig
    • src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php
    • src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php

    下記にファイルが存在する場合は同様に上書きをお願いします

    • app/template/default/Product/detail.twig
    • app/template/default/default_frame.twig

    4.2.2

    • app/config/eccube/packages/twig_extensions.yaml
    • src/Eccube/Resource/template/default/Product/detail.twig
    • src/Eccube/Resource/template/default/default_frame.twig
    • src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php
    • src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php

    下記にファイルが存在する場合は同様に上書きをお願いします

    • app/template/default/Product/detail.twig
    • app/template/default/default_frame.twig

    また、snippet.twigに関してはプラグインで拡張する箇所となるため対応不要となります。

    ※デザインテンプレートの適用や、EC-CUBE本体のカスタマイズをしている場合、修正箇所の差分をご確認のうえ反映をお願いします。
    ※開発環境がある場合は、開発環境での反映・動作確認を行った後に、本番環境への反映をおすすめします。

  4. キャッシュの削除

    EC-CUBE のキャッシュの削除が必要です。
    EC-CUBE の管理画面にログインいただき、コンテンツ管理 -> キャッシュ管理 のページからキャッシュの削除をお願いいたします。

  5. 動作確認

    フロント画面と管理画面(ログインが必要)それぞれにおいて、基本操作が正常に行えることをご確認ください。

修正方法2-1: 修正差分を確認して適宜反映する場合(4.1系)

以下のコード差分情報を参照して頂き、必要な箇所に修正を反映してください。

本修正方法はEC-CUBE 4.1.2-p2のバージョンを例として提示しております。
過去バージョンをご利用の場合は、下記修正対象ファイルの修正差分を参考にご対応お願いいたします。

修正差分

app/config/eccube/packages/twig_extensions.yaml CHANGED
@@ -8,3 +8,151 @@ services:
8
8
  #Twig\Extensions\DateExtension: ~
9
9
  Twig\Extensions\IntlExtension: ~
10
10
  #Twig\Extensions\TextExtension: ~
11
+ eccube.twig_sandbox.policy:
12
+ class: Twig\Sandbox\SecurityPolicy
13
+ arguments:
14
+ $allowedTags: "%eccube.twig_sandbox.allowed_tags%"
15
+ $allowedFilters: "%eccube.twig_sandbox.allowed_filters%"
16
+ $allowedFunctions: "%eccube.twig_sandbox.allowed_functions%"
17
+ $allowedMethods: "%eccube.twig_sandbox.allowed_methods%"
18
+ $allowedProperties: "%eccube.twig_sandbox.allowed_properties%"
19
+ eccube.twig_sandbox.extension:
20
+ class: Twig\Extension\SandboxExtension
21
+ arguments:
22
+ - '@eccube.twig_sandbox.policy'
23
+ - false
24
+ tags: ['twig.extension']
25
+ Eccube\Twig\Sandbox\SecurityPolicyDecorator:
26
+ decorates: 'eccube.twig_sandbox.policy'
27
+ parameters:
28
+ eccube.twig_sandbox.allowed_tags:
29
+ - 'apply'
30
+ - 'block'
31
+ - 'deprecated'
32
+ - 'embed'
33
+ - 'extends'
34
+ - 'flush'
35
+ - 'for'
36
+ - 'if'
37
+ - 'set'
38
+ - 'spaceless'
39
+ - 'verbatim'
40
+ - 'with'
41
+ - 'form_theme'
42
+ - 'stopwatch'
43
+ - 'trans'
44
+ - 'trans_default_domain'
45
+ eccube.twig_sandbox.allowed_filters:
46
+ - 'abs'
47
+ - 'batch'
48
+ - 'capitalize'
49
+ - 'column'
50
+ - 'convert_encoding'
51
+ - 'date'
52
+ - 'date_modify'
53
+ - 'default'
54
+ - 'escape'
55
+ - 'first'
56
+ - 'format'
57
+ - 'join'
58
+ - 'json_encode'
59
+ - 'keys'
60
+ - 'last'
61
+ - 'length'
62
+ - 'lower'
63
+ - 'merge'
64
+ - 'nl2br'
65
+ - 'number_format'
66
+ - 'replace'
67
+ - 'reverse'
68
+ - 'round'
69
+ - 'slice'
70
+ - 'spaceless'
71
+ - 'split'
72
+ - 'striptags'
73
+ - 'title'
74
+ - 'trim'
75
+ - 'upper'
76
+ - 'url_encode'
77
+ - 'abbr_class'
78
+ - 'abbr_method'
79
+ - 'file_link'
80
+ - 'file_relative'
81
+ - 'format_args'
82
+ - 'format_args_as_text'
83
+ - 'humanize'
84
+ - 'trans'
85
+ - 'yaml_dump'
86
+ - 'yaml_encode'
87
+ - 'date_day'
88
+ - 'date_day_with_weekday'
89
+ - 'date_format'
90
+ - 'date_min'
91
+ - 'date_sec'
92
+ - 'doctrine_pretty_query'
93
+ - 'doctrine_replace_query_parameters'
94
+ - 'e'
95
+ - 'ellipsis'
96
+ - 'file_ext_icon'
97
+ - 'form_encode_currency'
98
+ - 'format_log_message'
99
+ - 'no_image_product'
100
+ - 'price'
101
+ - 'purify'
102
+ - 'time_ago'
103
+ - 'doctrine_minify_query'
104
+ - 'localizedcurrency'
105
+ - 'localizeddate'
106
+ - 'localizednumber'
107
+ - 'transchoice'
108
+ eccube.twig_sandbox.allowed_functions:
109
+ - 'cycle'
110
+ - 'date'
111
+ - 'max'
112
+ - 'min'
113
+ - 'random'
114
+ - 'range'
115
+ - 'absolute_url'
116
+ - 'asset'
117
+ - 'asset_version'
118
+ - 'csrf_token'
119
+ - 'form_parent'
120
+ - 'is_granted'
121
+ - 'logout_path'
122
+ - 'logout_url'
123
+ - 'path'
124
+ - 'relative_path'
125
+ - 'url'
126
+ - 'active_menus'
127
+ - 'class_categories_as_json'
128
+ - 'csrf_token_for_anchor'
129
+ - 'currency_symbol'
130
+ - 'get_all_carts'
131
+ - 'get_cart'
132
+ - 'get_carts_total_price'
133
+ - 'get_carts_total_quantity'
134
+ - 'has_errors'
135
+ - 'is_reduced_tax_rate'
136
+ - 'product'
137
+ - 'workflow_can'
138
+ - 'workflow_has_marked_place'
139
+ - 'workflow_marked_places'
140
+ - 'workflow_metadata'
141
+ - 'workflow_transition_blockers'
142
+ - 'workflow_transitions'
143
+ - 'device_version'
144
+ - 'full_view_url'
145
+ - 'is_android_os'
146
+ - 'is_device'
147
+ - 'is_full_view'
148
+ - 'is_ios'
149
+ - 'is_mobile'
150
+ - 'is_mobile_view'
151
+ - 'is_not_mobile_view'
152
+ - 'is_tablet'
153
+ - 'is_tablet_view'
154
+ - 'php_*'
155
+ eccube.twig_sandbox.allowed_methods:
156
+ 'Symfony\Bridge\Twig\AppVariable': [ 'getrequest' ]
157
+ 'Symfony\Component\HttpFoundation\Request': [ 'geturi' ]
158
+ eccube.twig_sandbox.allowed_properties: []
src/Eccube/Resource/template/default/Product/detail.twig CHANGED
@@ -405,7 +405,7 @@ file that was distributed with this source code.
405
405
  </div>
406
406
  {% if Product.freearea %}
407
407
  <div class="ec-productRole__description">
408
- {{ include(template_from_string(Product.freearea)) }}
408
+ {{ include(template_from_string(Product.freearea), sandboxed = true) }}
409
409
  </div>
410
410
  {% endif %}
411
411
  </div>
src/Eccube/Resource/template/default/default_frame.twig CHANGED
@@ -16,7 +16,7 @@ file that was distributed with this source code.
16
16
  <meta name="eccube-csrf-token" content="{{ csrf_token(constant('Eccube\\Common\\Constant::TOKEN_NAME')) }}">
17
17
  <title>{{ BaseInfo.shop_name }}{% if subtitle is defined and subtitle is not empty %} / {{ subtitle }}{% elseif title is defined and title is not empty %} / {{ title }}{% endif %}</title>
18
18
  {% if Page.meta_tags is not empty %}
19
- {{ include(template_from_string(Page.meta_tags)) }}
19
+ {{ include(template_from_string(Page.meta_tags), sandboxed = true) }}
20
20
  {% if Page.description is not empty %}
21
21
  <meta name="description" content="{{ Page.description }}">
22
22
  {% endif %}
@@ -32,9 +32,6 @@ file that was distributed with this source code.
32
32
  {% if Page.meta_robots is not empty %}
33
33
  <meta name="robots" content="{{ Page.meta_robots }}">
34
34
  {% endif %}
35
- {% if Page.meta_tags is not empty %}
36
- {{ include(template_from_string(Page.meta_tags)) }}
37
- {% endif %}
38
35
  <link rel="icon" href="{{ asset('assets/img/common/favicon.ico', 'user_data') }}">
39
36
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
40
37
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php ADDED
@@ -0,0 +1,78 @@
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of EC-CUBE
5
+ *
6
+ * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
+ *
8
+ * http://www.ec-cube.co.jp/
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Eccube\Twig\Extension;
15
+
16
+ use Twig\Environment;
17
+ use Twig\Error\LoaderError;
18
+ use Twig\Extension\AbstractExtension;
19
+ use Twig\Extension\SandboxExtension;
20
+ use Twig\Sandbox\SecurityError;
21
+ use Twig\TwigFunction;
22
+
23
+ /**
24
+ * \vendor\twig\twig\src\Extension\CoreExtension の拡張
25
+ */
26
+ class IgnoreTwigSandboxErrorExtension extends AbstractExtension
27
+ {
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ public function getFunctions(): array
32
+ {
33
+ return [
34
+ new TwigFunction('include', [$this, 'twig_include'], ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
35
+ ];
36
+ }
37
+
38
+ /**
39
+ * twig sandboxの例外を操作します
40
+ * app_env = devの場合、エラーを表示する
41
+ * app_env = prodの場合、エラーを表示しない
42
+ *
43
+ * @param Environment $env
44
+ * @param $context
45
+ * @param $template
46
+ * @param $variables
47
+ * @param $withContext
48
+ * @param $ignoreMissing
49
+ * @param $sandboxed
50
+ *
51
+ * @return string|void
52
+ *
53
+ * @throws LoaderError
54
+ * @throws SecurityError
55
+ */
56
+ public function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
57
+ {
58
+ try {
59
+ return \twig_include($env, $context, $template, $variables, $withContext, $ignoreMissing, $sandboxed);
60
+ } catch (SecurityError $e) {
61
+
62
+ // devではエラー画面が表示されるようにする
63
+ $appEnv = env('APP_ENV');
64
+ if ($appEnv === 'dev') {
65
+ throw $e;
66
+ } else {
67
+ // ログ出力
68
+ log_warning($e->getMessage(), ['exception' => $e]);
69
+
70
+ // 例外がスローされた場合、sandboxが効いた状態になってしまうため追加
71
+ $sandbox = $env->getExtension(SandboxExtension::class);
72
+ if (!$sandbox->isSandboxedGlobally()) {
73
+ $sandbox->disableSandbox();
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of EC-CUBE
5
+ *
6
+ * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
+ *
8
+ * http://www.ec-cube.co.jp/
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Eccube\Twig\Sandbox;
15
+
16
+ use Twig\Sandbox\SecurityPolicy as BasePolicy;
17
+ use Twig\Sandbox\SecurityPolicyInterface;
18
+
19
+ class SecurityPolicyDecorator implements SecurityPolicyInterface {
20
+
21
+ /** @var BasePolicy */
22
+ private $securityPolicy;
23
+
24
+ public function __construct(BasePolicy $securityPolicy)
25
+ {
26
+ $this->securityPolicy = $securityPolicy;
27
+ }
28
+
29
+ public function checkSecurity($tags, $filters, $functions)
30
+ {
31
+ $this->securityPolicy->checkSecurity($tags, $filters, $functions);
32
+ }
33
+
34
+ public function checkMethodAllowed($obj, $method)
35
+ {
36
+ // __toStringの場合はチェックをスキップする
37
+ if ($method === '__toString') {
38
+ return;
39
+ }
40
+ $this->securityPolicy->checkMethodAllowed($obj, $method);
41
+ }
42
+
43
+ public function checkPropertyAllowed($obj, $method)
44
+ {
45
+ $this->securityPolicy->checkPropertyAllowed($obj, $method);
46
+ }
47
+ }

修正方法2-2: 修正差分を確認して適宜反映する場合(4.2系)

以下のコード差分情報を参照して頂き、必要な箇所に修正を反映してください。

本修正方法はEC-CUBE 4.2.2のバージョンを例として提示しております。
過去バージョンをご利用の場合は、下記修正対象ファイルの修正差分を参考にご対応お願いいたします。

修正差分

app/config/eccube/packages/twig_extensions.yaml CHANGED
@@ -8,3 +8,166 @@ services:
8
8
  #Twig\Extensions\DateExtension: ~
9
9
  # Twig\Extensions\IntlExtension: ~
10
10
  #Twig\Extensions\TextExtension: ~
11
+
12
+ eccube.twig_sandbox.policy:
13
+ class: Twig\Sandbox\SecurityPolicy
14
+ arguments:
15
+ $allowedTags: "%eccube.twig_sandbox.allowed_tags%"
16
+ $allowedFilters: "%eccube.twig_sandbox.allowed_filters%"
17
+ $allowedFunctions: "%eccube.twig_sandbox.allowed_functions%"
18
+ $allowedMethods: "%eccube.twig_sandbox.allowed_methods%"
19
+ $allowedProperties: "%eccube.twig_sandbox.allowed_properties%"
20
+ eccube.twig_sandbox.extension:
21
+ class: Twig\Extension\SandboxExtension
22
+ arguments:
23
+ - '@eccube.twig_sandbox.policy'
24
+ - false
25
+ tags: ['twig.extension']
26
+ Eccube\Twig\Sandbox\SecurityPolicyDecorator:
27
+ decorates: 'eccube.twig_sandbox.policy'
28
+ parameters:
29
+ eccube.twig_sandbox.allowed_tags:
30
+ - 'apply'
31
+ - 'block'
32
+ - 'deprecated'
33
+ - 'embed'
34
+ - 'extends'
35
+ - 'flush'
36
+ - 'for'
37
+ - 'if'
38
+ - 'set'
39
+ - 'spaceless'
40
+ - 'verbatim'
41
+ - 'with'
42
+ - 'form_theme'
43
+ - 'stopwatch'
44
+ - 'trans'
45
+ - 'trans_default_domain'
46
+ eccube.twig_sandbox.allowed_filters:
47
+ - 'abs'
48
+ - 'batch'
49
+ - 'capitalize'
50
+ - 'column'
51
+ - 'convert_encoding'
52
+ - 'country_name'
53
+ - 'currency_name'
54
+ - 'currency_symbol'
55
+ - 'date'
56
+ - 'date_modify'
57
+ - 'default'
58
+ - 'escape'
59
+ - 'first'
60
+ - 'format'
61
+ - 'format_currency'
62
+ - 'format_date'
63
+ - 'format_datetime'
64
+ - 'format_number'
65
+ - 'format_time'
66
+ - 'join'
67
+ - 'json_encode'
68
+ - 'keys'
69
+ - 'language_name'
70
+ - 'last'
71
+ - 'length'
72
+ - 'locale_name'
73
+ - 'lower'
74
+ - 'merge'
75
+ - 'nl2br'
76
+ - 'number_format'
77
+ - 'replace'
78
+ - 'reverse'
79
+ - 'round'
80
+ - 'slice'
81
+ - 'spaceless'
82
+ - 'split'
83
+ - 'striptags'
84
+ - 'timezone_name'
85
+ - 'title'
86
+ - 'trim'
87
+ - 'upper'
88
+ - 'url_encode'
89
+ - 'abbr_class'
90
+ - 'abbr_method'
91
+ - 'file_link'
92
+ - 'file_relative'
93
+ - 'format_args'
94
+ - 'format_args_as_text'
95
+ - 'humanize'
96
+ - 'serialize'
97
+ - 'trans'
98
+ - 'yaml_dump'
99
+ - 'yaml_encode'
100
+ - 'currency_symbol'
101
+ - 'date_day'
102
+ - 'date_day_with_weekday'
103
+ - 'date_format'
104
+ - 'date_min'
105
+ - 'date_sec'
106
+ - 'doctrine_format_sql'
107
+ - 'doctrine_prettify_sql'
108
+ - 'doctrine_pretty_query'
109
+ - 'doctrine_replace_query_parameters'
110
+ - 'e'
111
+ - 'ellipsis'
112
+ - 'file_ext_icon'
113
+ - 'form_encode_currency'
114
+ - 'format_*_number'
115
+ - 'format_log_message'
116
+ - 'no_image_product'
117
+ - 'price'
118
+ - 'purify'
119
+ - 'time_ago'
120
+ eccube.twig_sandbox.allowed_functions:
121
+ - 'cycle'
122
+ - 'date'
123
+ - 'max'
124
+ - 'min'
125
+ - 'random'
126
+ - 'range'
127
+ - 'country_timezones'
128
+ - 'absolute_url'
129
+ - 'asset'
130
+ - 'asset_version'
131
+ - 'csrf_token'
132
+ - 'form_parent'
133
+ - 'fragment_uri'
134
+ - 'impersonation_exit_path'
135
+ - 'impersonation_exit_url'
136
+ - 'is_granted'
137
+ - 'logout_path'
138
+ - 'logout_url'
139
+ - 'path'
140
+ - 'relative_path'
141
+ - 't'
142
+ - 'url'
143
+ - 'active_menus'
144
+ - 'class_categories_as_json'
145
+ - 'country_names'
146
+ - 'csrf_token_for_anchor'
147
+ - 'currency_names'
148
+ - 'currency_symbol'
149
+ - 'field_choices'
150
+ - 'field_errors'
151
+ - 'field_help'
152
+ - 'field_label'
153
+ - 'field_name'
154
+ - 'field_value'
155
+ - 'get_all_carts'
156
+ - 'get_cart'
157
+ - 'get_carts_total_price'
158
+ - 'get_carts_total_quantity'
159
+ - 'has_errors'
160
+ - 'is_reduced_tax_rate'
161
+ - 'language_names'
162
+ - 'product'
163
+ - 'workflow_can'
164
+ - 'workflow_has_marked_place'
165
+ - 'workflow_marked_places'
166
+ - 'workflow_metadata'
167
+ - 'workflow_transition'
168
+ - 'workflow_transition_blockers'
169
+ - 'workflow_transitions'
170
+ eccube.twig_sandbox.allowed_methods:
171
+ 'Symfony\Bridge\Twig\AppVariable': [ 'getrequest' ]
172
+ 'Symfony\Component\HttpFoundation\Request': [ 'geturi' ]
173
+ eccube.twig_sandbox.allowed_properties: []
src/Eccube/Resource/template/default/Product/detail.twig CHANGED
@@ -439,7 +439,7 @@ file that was distributed with this source code.
439
439
  </div>
440
440
  {% if Product.freearea %}
441
441
  <div class="ec-productRole__description">
442
- {{ include(template_from_string(Product.freearea)) }}
442
+ {{ include(template_from_string(Product.freearea), sandboxed = true) }}
443
443
  </div>
444
444
  {% endif %}
445
445
  </div>
src/Eccube/Resource/template/default/default_frame.twig CHANGED
@@ -16,7 +16,7 @@ file that was distributed with this source code.
16
16
  <meta name="eccube-csrf-token" content="{{ csrf_token(constant('Eccube\\Common\\Constant::TOKEN_NAME')) }}">
17
17
  <title>{{ BaseInfo.shop_name }}{% if subtitle is defined and subtitle is not empty %} / {{ subtitle }}{% elseif title is defined and title is not empty %} / {{ title }}{% endif %}</title>
18
18
  {% if Page.meta_tags is not empty %}
19
- {{ include(template_from_string(Page.meta_tags)) }}
19
+ {{ include(template_from_string(Page.meta_tags), sandboxed = true) }}
20
20
  {% if Page.description is not empty %}
21
21
  <meta name="description" content="{{ Page.description }}">
22
22
  {% endif %}
src/Eccube/Twig/Extension/IgnoreTwigSandboxErrorExtension.php ADDED
@@ -0,0 +1,78 @@
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of EC-CUBE
5
+ *
6
+ * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
+ *
8
+ * http://www.ec-cube.co.jp/
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Eccube\Twig\Extension;
15
+
16
+ use Twig\Environment;
17
+ use Twig\Error\LoaderError;
18
+ use Twig\Extension\AbstractExtension;
19
+ use Twig\Extension\SandboxExtension;
20
+ use Twig\Sandbox\SecurityError;
21
+ use Twig\TwigFunction;
22
+
23
+ /**
24
+ * \vendor\twig\twig\src\Extension\CoreExtension の拡張
25
+ */
26
+ class IgnoreTwigSandboxErrorExtension extends AbstractExtension
27
+ {
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ public function getFunctions(): array
32
+ {
33
+ return [
34
+ new TwigFunction('include', [$this, 'twig_include'], ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
35
+ ];
36
+ }
37
+
38
+ /**
39
+ * twig sandboxの例外を操作します
40
+ * app_env = devの場合、エラーを表示する
41
+ * app_env = prodの場合、エラーを表示しない
42
+ *
43
+ * @param Environment $env
44
+ * @param $context
45
+ * @param $template
46
+ * @param $variables
47
+ * @param $withContext
48
+ * @param $ignoreMissing
49
+ * @param $sandboxed
50
+ *
51
+ * @return string|void
52
+ *
53
+ * @throws LoaderError
54
+ * @throws SecurityError
55
+ */
56
+ public function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
57
+ {
58
+ try {
59
+ return \twig_include($env, $context, $template, $variables, $withContext, $ignoreMissing, $sandboxed);
60
+ } catch (SecurityError $e) {
61
+
62
+ // devではエラー画面が表示されるようにする
63
+ $appEnv = env('APP_ENV');
64
+ if ($appEnv === 'dev') {
65
+ throw $e;
66
+ } else {
67
+ // ログ出力
68
+ log_warning($e->getMessage(), ['exception' => $e]);
69
+
70
+ // 例外がスローされた場合、sandboxが効いた状態になってしまうため追加
71
+ $sandbox = $env->getExtension(SandboxExtension::class);
72
+ if (!$sandbox->isSandboxedGlobally()) {
73
+ $sandbox->disableSandbox();
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
src/Eccube/Twig/Sandbox/SecurityPolicyDecorator.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of EC-CUBE
5
+ *
6
+ * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
+ *
8
+ * http://www.ec-cube.co.jp/
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Eccube\Twig\Sandbox;
15
+
16
+ use Twig\Sandbox\SecurityPolicy as BasePolicy;
17
+ use Twig\Sandbox\SecurityPolicyInterface;
18
+
19
+ class SecurityPolicyDecorator implements SecurityPolicyInterface {
20
+
21
+ /** @var BasePolicy */
22
+ private $securityPolicy;
23
+
24
+ public function __construct(BasePolicy $securityPolicy)
25
+ {
26
+ $this->securityPolicy = $securityPolicy;
27
+ }
28
+
29
+ public function checkSecurity($tags, $filters, $functions)
30
+ {
31
+ $this->securityPolicy->checkSecurity($tags, $filters, $functions);
32
+ }
33
+
34
+ public function checkMethodAllowed($obj, $method)
35
+ {
36
+ // __toStringの場合はチェックをスキップする
37
+ if ($method === '__toString') {
38
+ return;
39
+ }
40
+ $this->securityPolicy->checkMethodAllowed($obj, $method);
41
+ }
42
+
43
+ public function checkPropertyAllowed($obj, $method)
44
+ {
45
+ $this->securityPolicy->checkPropertyAllowed($obj, $method);
46
+ }
47
+ }

問い合わせ先

本脆弱性に関するお問合せ:

EC-CUBE 運営チーム
MAIL: support@ec-cube.net

謝辞

本脆弱性は、

よりご報告いただきました。
この場をお借りして、厚く御礼申し上げます。