Skip to content

Commit

Permalink
Merge pull request #5428 from nanasess/fix-freearea
Browse files Browse the repository at this point in the history
[4.2]フリーエリアのpurify漏れを修正
  • Loading branch information
chihiro-adachi authored Jul 11, 2022
2 parents 80ab4dc + 581fd67 commit 3c6f0ea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Eccube/Resource/template/default/Product/detail.twig
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ file that was distributed with this source code.
</div>
{% if Product.freearea %}
<div class="ec-productRole__description">
{{ include(template_from_string(Product.freearea)) }}
{{ include(template_from_string(Product.freearea|purify)) }}
</div>
{% endif %}
</div>
Expand Down
44 changes: 44 additions & 0 deletions tests/Eccube/Tests/Web/ProductControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,48 @@ public function testFeaturedNewsXSSAttackPreventionDetailPage()
$this->assertStringNotContainsString("<script>alert('XSS Attack')</script>", $testNewsArea->outerHtml());
}

/**
* 商品詳細画面(フリーエリア)で
* 危険なXSS htmlインジェクションが削除されたことを確認するテスト
* 下記のものをチェックします。
* ・ ID属性の追加
* ・ <script> スクリプトインジェクション
*
* @see https://github.com/EC-CUBE/ec-cube/issues/5372
* @return void
*/
public function testFeaturedNewsXSSAttackPreventionDetailPageWithFreearea()
{
$Product = $this->createProduct('Product out of stock', 1);
$Product->setFreeArea("<div id='dangerous-id' class='safe_to_use_class'>
<p>商品説明分テスト#1</p>
<script>alert('XSS Attack')</script>
<a href='https://www.google.com'>safe html</a>
</div>");
$this->entityManager->flush();

// 1つの新着情報を保存した後にホームページにアクセスする。
// Request Homepage after saving a single news item
$crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());

// <div>タグから危険なid属性が削除されていることを確認する。
// Find that dangerous id attributes are removed from <div> tags.
$testNewsArea_notFoundTest = $crawler->filter('#dangerous-id');
$this->assertEquals(0, $testNewsArea_notFoundTest->count());

// 安全なclass属性が出力されているかどうかを確認する。
// Find if classes (which are safe) have been outputted
$testNewsArea = $crawler->filter('.safe_to_use_class');
$this->assertEquals(1, $testNewsArea->count());

// 安全なHTMLが存在するかどうかを確認する
// Find if the safe HTML exists
$this->assertStringContainsString('<p>商品説明分テスト#1</p>', $testNewsArea->outerHtml());
$this->assertStringContainsString('<a href="https://www.google.com">safe html</a>', $testNewsArea->outerHtml());

// 安全でないスクリプトが存在しないかどうかを確認する
// Find if the unsafe script does not exist
$this->assertStringNotContainsString("<script>alert('XSS Attack')</script>", $testNewsArea->outerHtml());
}
}

0 comments on commit 3c6f0ea

Please sign in to comment.