diff --git a/plugins/baser-core/src/Controller/Admin/ContentsController.php b/plugins/baser-core/src/Controller/Admin/ContentsController.php index 2c4c066bbd..10736bb836 100644 --- a/plugins/baser-core/src/Controller/Admin/ContentsController.php +++ b/plugins/baser-core/src/Controller/Admin/ContentsController.php @@ -231,6 +231,8 @@ public function delete(ContentsServiceInterface $service) { if ($this->request->is(['post', 'put', 'delete'])) { $id = $this->request->getData('content.id'); + // 数字以外の ID は型変換できず例外になるため、存在しないページとして扱う + if (!is_scalar($id) || !ctype_digit((string)$id)) $this->notFound(); /* @var \BaserCore\Model\Entity\Content $content */ $content = $service->get($id); if ($service->deleteRecursive($id)) { diff --git a/plugins/baser-core/src/Controller/Admin/PermissionGroupsController.php b/plugins/baser-core/src/Controller/Admin/PermissionGroupsController.php index eceb4ecb4a..83da8514de 100644 --- a/plugins/baser-core/src/Controller/Admin/PermissionGroupsController.php +++ b/plugins/baser-core/src/Controller/Admin/PermissionGroupsController.php @@ -95,9 +95,12 @@ public function add(PermissionGroupsAdminServiceInterface $service, int $userGro $this->BcMessage->setError(__d('baser_core', 'データベース処理中にエラーが発生しました。') . $e->getMessage()); } } + // prefix が無い場合は getNew() が TypeError になるため、一覧の初期値と同じ Admin にする + $prefix = $this->getRequest()->getQuery('prefix'); + if (!is_string($prefix) || $prefix === '') $prefix = 'Admin'; $this->set($service->getViewVarsForForm( $userGroupId, - $entity?? $service->getNew($this->getRequest()->getQuery('prefix')) + $entity?? $service->getNew($prefix) )); } diff --git a/plugins/baser-core/src/Controller/Admin/PermissionsController.php b/plugins/baser-core/src/Controller/Admin/PermissionsController.php index a6e89576a4..bbbcc509c9 100644 --- a/plugins/baser-core/src/Controller/Admin/PermissionsController.php +++ b/plugins/baser-core/src/Controller/Admin/PermissionsController.php @@ -144,9 +144,9 @@ public function add( */ public function edit( PermissionsAdminServiceInterface $service, - $userGroupId, - $permissionId, - $permissionGroupId = null + int $userGroupId, + int $permissionId, + ?int $permissionGroupId = null ) { $permission = $service->get($permissionId); if ($this->request->is(['patch', 'post', 'put'])) { diff --git a/plugins/baser-core/src/Controller/Admin/PluginsController.php b/plugins/baser-core/src/Controller/Admin/PluginsController.php index 596ecf03ca..d580f4ebe4 100644 --- a/plugins/baser-core/src/Controller/Admin/PluginsController.php +++ b/plugins/baser-core/src/Controller/Admin/PluginsController.php @@ -72,6 +72,8 @@ public function index(PluginsServiceInterface $service) */ public function install(PluginsAdminServiceInterface $service, string $name) { + // 存在しないプラグイン名では設定を取得できず TypeError になるため、存在しないページとして扱う + if (!BcUtil::getPluginPath($name)) $this->notFound(); $this->set($service->getViewVarsForInstall($this->Plugins->getPluginConfig($name))); if ($service->getInstallStatusMessage($name) || !$this->request->is(['put', 'post'])) { return; @@ -320,7 +322,8 @@ public function reset_db(PluginsServiceInterface $service, UsersServiceInterface { if (!$this->request->is('put')) { $this->BcMessage->setError(__d('baser_core', '無効な処理です。')); - return; + // reset_db のテンプレートは存在せず MissingTemplateException になるため、一覧へ戻す + return $this->redirect(['action' => 'index']); } $plugin = $service->getByName($this->request->getData('name')); try { diff --git a/plugins/baser-core/src/Controller/Admin/SitesController.php b/plugins/baser-core/src/Controller/Admin/SitesController.php index 9bedcbeb09..8eaad71d61 100644 --- a/plugins/baser-core/src/Controller/Admin/SitesController.php +++ b/plugins/baser-core/src/Controller/Admin/SitesController.php @@ -116,7 +116,7 @@ public function add( * @unitTest * @note(value="インストーラーを実装してからテーマの保有するプラグインをインストールする処理を追加する") */ - public function edit(SitesAdminServiceInterface $service, $id) + public function edit(SitesAdminServiceInterface $service, int $id) { if (!$id) { $this->notFound(); diff --git a/plugins/baser-core/src/Controller/Admin/UserGroupsController.php b/plugins/baser-core/src/Controller/Admin/UserGroupsController.php index 030616f533..020e1c8814 100644 --- a/plugins/baser-core/src/Controller/Admin/UserGroupsController.php +++ b/plugins/baser-core/src/Controller/Admin/UserGroupsController.php @@ -108,7 +108,7 @@ public function add(UserGroupsServiceInterface $service) * @noTodo * @unitTest */ - public function edit(UserGroupsServiceInterface $service, UsersServiceInterface $usersService, $id) + public function edit(UserGroupsServiceInterface $service, UsersServiceInterface $usersService, int $id) { $userGroup = $service->get($id); if ($this->request->is(['patch', 'post', 'put'])) { diff --git a/plugins/baser-core/src/Controller/Admin/UsersController.php b/plugins/baser-core/src/Controller/Admin/UsersController.php index 763e0f206d..64e87de658 100644 --- a/plugins/baser-core/src/Controller/Admin/UsersController.php +++ b/plugins/baser-core/src/Controller/Admin/UsersController.php @@ -203,7 +203,7 @@ public function login_code(UsersServiceInterface $usersService, TwoFactorAuthent * @unitTest * @noTodo */ - public function login_agent(UsersServiceInterface $service, $id): ?Response + public function login_agent(UsersServiceInterface $service, int $id): ?Response { // 特権確認 if (BcUtil::isAdminUser() === false) { @@ -352,7 +352,7 @@ public function add(UsersAdminServiceInterface $service) * @noTodo * @unitTest */ - public function edit(UsersAdminServiceInterface $service, $id = null) + public function edit(UsersAdminServiceInterface $service, ?int $id = null) { if (!$id && empty($this->request->getData())) { $this->BcMessage->setError(__d('baser_core', '無効なIDです。')); diff --git a/plugins/baser-core/src/Middleware/BcAdminMiddleware.php b/plugins/baser-core/src/Middleware/BcAdminMiddleware.php index 62c455d1c9..cc8c4e6241 100644 --- a/plugins/baser-core/src/Middleware/BcAdminMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcAdminMiddleware.php @@ -65,8 +65,10 @@ public function setCurrentSite($request): ServerRequestInterface $queryCurrentSiteId = $request->getQuery('site_id'); $sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites'); if ($queryCurrentSiteId) { - $query = $sitesTable->find()->where(['Sites.id' => $queryCurrentSiteId]); - if(!$query->count()) { + // 数字以外は型変換できず例外になるため、存在しないサイトとして扱う + $query = (is_scalar($queryCurrentSiteId) && ctype_digit((string)$queryCurrentSiteId))? + $sitesTable->find()->where(['Sites.id' => $queryCurrentSiteId]) : null; + if(!$query || !$query->count()) { $request = $request->withQueryParams(array_merge( $request->getQueryParams(), ['site_id' => $defaultSiteId] diff --git a/plugins/baser-core/src/Service/ContentsService.php b/plugins/baser-core/src/Service/ContentsService.php index a607885ecc..85bd314358 100644 --- a/plugins/baser-core/src/Service/ContentsService.php +++ b/plugins/baser-core/src/Service/ContentsService.php @@ -246,8 +246,8 @@ public function setConditions(Query $query, array $queryParams): Query if(!empty($params['type!'])) $conditions['Contents.type IS NOT'] = $params['type!']; // author_id if(!empty($params['parent_id'])) $conditions['Contents.parent_id'] = $params['parent_id']; - // author_id - if(!empty($params['author_id'])) $conditions['Contents.author_id'] = $params['author_id']; + // author_id(数字以外は型変換できず例外になるため条件にしない) + if(!empty($params['author_id']) && is_scalar($params['author_id']) && ctype_digit((string)$params['author_id'])) $conditions['Contents.author_id'] = $params['author_id']; // site_id if(!empty($params['site_id'])) $conditions['Contents.site_id'] = $params['site_id']; // title @@ -271,10 +271,10 @@ public function setConditions(Query $query, array $queryParams): Query } // folder_id - if (!is_null($params['folder_id']) && $params['folder_id']) { + if (!is_null($params['folder_id']) && $params['folder_id'] && is_scalar($params['folder_id']) && ctype_digit((string)$params['folder_id'])) { $folder = $this->Contents->find()->select(['lft', 'rght']) - ->where(['Contents.id' => $queryParams['folder_id']])->first(); - $conditions[] = ['Contents.rght <' => $folder->rght, 'Contents.lft >' => $folder->lft]; + ->where(['Contents.id' => $params['folder_id']])->first(); + if ($folder) $conditions[] = ['Contents.rght <' => $folder->rght, 'Contents.lft >' => $folder->lft]; } return $query->where($conditions); diff --git a/plugins/baser-core/src/Service/DblogsService.php b/plugins/baser-core/src/Service/DblogsService.php index 38233dfbee..7f79f6f1cd 100644 --- a/plugins/baser-core/src/Service/DblogsService.php +++ b/plugins/baser-core/src/Service/DblogsService.php @@ -170,7 +170,8 @@ public function getIndex(array $queryParams = []): Query if (!empty($queryParams['message'])) { $query->where(['message LIKE' => '%' . $queryParams['message'] . '%']); } - if (!empty($queryParams['user_id'])) { + // 数値で指定する条件に数字以外が渡されると型変換できず例外になるため、条件にしない + if (!empty($queryParams['user_id']) && is_scalar($queryParams['user_id']) && ctype_digit((string)$queryParams['user_id'])) { $query->where(['user_id' => $queryParams['user_id']]); } diff --git a/plugins/baser-core/src/Service/UsersService.php b/plugins/baser-core/src/Service/UsersService.php index 278c104904..d1d505df8f 100644 --- a/plugins/baser-core/src/Service/UsersService.php +++ b/plugins/baser-core/src/Service/UsersService.php @@ -159,6 +159,10 @@ private function createIndexConditions(Query $query, array $params): Query 'real_name' => null ], $params); + // 数値で指定する条件に数字以外が渡されると型変換できず例外になるため、条件にしない + if (!is_null($params['user_group_id']) && (!is_scalar($params['user_group_id']) || !ctype_digit((string)$params['user_group_id']))) { + $params['user_group_id'] = null; + } if (!is_null($params['user_group_id'])) { $query->matching('UserGroups', function($q) use ($params) { return $q->where(['UserGroups.id' => $params['user_group_id']]); diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/ContentsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/ContentsControllerTest.php index 0594772ba1..5cc16ff320 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/ContentsControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/ContentsControllerTest.php @@ -348,4 +348,17 @@ public function testAdmin_empty() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } + + /** + * test delete + * 数字以外の ID は 404 + */ + public function testDelete_non_numeric_id() + { + $this->enableSecurityToken(); + $this->enableCsrfToken(); + $this->post('/baser/admin/baser-core/contents/delete', ['content' => ['id' => "6'"]]); + $this->assertResponseCode(404); + } + } diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionGroupsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionGroupsControllerTest.php index b9a8e69c38..b23ae0b86f 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionGroupsControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionGroupsControllerTest.php @@ -180,4 +180,15 @@ public function test_rebuild_by_user_group() '1' ]); } + + /** + * test add + * prefix を指定しない場合は Admin として表示する + */ + public function testAdd_without_prefix() + { + $this->get('/baser/admin/baser-core/permission_groups/add/1'); + $this->assertResponseOk(); + } + } diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionsControllerTest.php index f8736153a1..dbd0d1db99 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionsControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/PermissionsControllerTest.php @@ -210,6 +210,16 @@ public function testPublish() $this->assertTrue($permission->status); } + /** + * test edit + * 数字以外の ID は 404 + */ + public function testEdit_non_numeric_id() + { + $this->get('/baser/admin/baser-core/permissions/edit/' . urlencode("2'") . '/1'); + $this->assertResponseCode(404); + } + /** * test delete / copy / publish / unpublish * 数字以外の ID は 404 diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php index b60515ab71..cd440615de 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php @@ -408,4 +408,27 @@ public function test_get_core_update() rename(ROOT . DS . 'composer.bak.lock', ROOT . DS . 'composer.lock'); } + /** + * test install + * 存在しないプラグイン名は 404 + */ + public function testInstall_not_exists() + { + $this->get('/baser/admin/baser-core/plugins/install/' . urlencode("BcBlog'")); + $this->assertResponseCode(404); + } + + /** + * test reset_db + * PUT 以外は一覧へ戻す + */ + public function testReset_db_not_put() + { + $this->enableSecurityToken(); + $this->enableCsrfToken(); + $this->post('/baser/admin/baser-core/plugins/reset_db', ['name' => 'BcBlog']); + $this->assertRedirect(['plugin' => 'BaserCore', 'prefix' => 'Admin', 'controller' => 'Plugins', 'action' => 'index']); + $this->assertFlashMessage('無効な処理です。'); + } + } diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/UsersControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/UsersControllerTest.php index fdf4a353c5..3fa5d86098 100644 --- a/plugins/baser-core/tests/TestCase/Controller/Admin/UsersControllerTest.php +++ b/plugins/baser-core/tests/TestCase/Controller/Admin/UsersControllerTest.php @@ -466,6 +466,18 @@ public function testBack_agent() $this->assertRedirect('/baser/admin'); } + /** + * test edit / login_agent + * 数字以外の ID は 404 + */ + public function testEdit_non_numeric_id() + { + $this->get('/baser/admin/baser-core/users/edit/' . urlencode("1'")); + $this->assertResponseCode(404); + $this->get('/baser/admin/baser-core/users/login_agent/' . urlencode("1'")); + $this->assertResponseCode(404); + } + /** * test delete * 数字以外の ID は 404 diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcAdminMiddlewareTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcAdminMiddlewareTest.php index 817138e3d6..d2ef09ba06 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcAdminMiddlewareTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcAdminMiddlewareTest.php @@ -58,6 +58,11 @@ public function testProcess(): void $request = $this->getRequest('/baser/admin/?site_id=1'); $request = $this->execPrivateMethod($this->BcAdminMiddleware, 'setCurrentSite', [$request]); $this->assertEquals(1, $request->getAttribute('currentSite')->id); + + // 数字以外のサイトIDは既定のサイトにする + $request = $this->getRequest('/baser/admin/?site_id=' . urlencode("1'")); + $request = $this->execPrivateMethod($this->BcAdminMiddleware, 'setCurrentSite', [$request]); + $this->assertEquals(1, $request->getAttribute('currentSite')->id); } } diff --git a/plugins/baser-core/tests/TestCase/Service/ContentsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/ContentsServiceTest.php index 749cb243a5..35fd50ee8f 100644 --- a/plugins/baser-core/tests/TestCase/Service/ContentsServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/ContentsServiceTest.php @@ -1291,4 +1291,18 @@ public function testGetCrumbs() $rs = $this->ContentsService->getCrumbs(5); $this->assertCount(3, $rs); } + + /** + * test getIndex + * 数字以外の作成者ID・フォルダーID、存在しないフォルダーIDは条件にしない + */ + public function testGetIndex_invalid_filter(): void + { + $this->loadFixtureScenario(ContentsScenario::class); + $count = $this->ContentsService->getIndex([])->count(); + $this->assertEquals($count, $this->ContentsService->getIndex(['author_id' => "1'"])->count()); + $this->assertEquals($count, $this->ContentsService->getIndex(['folder_id' => "1'"])->count()); + $this->assertEquals($count, $this->ContentsService->getIndex(['folder_id' => 99999])->count()); + } + } diff --git a/plugins/baser-core/tests/TestCase/Service/DblogsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/DblogsServiceTest.php index 7603915b90..5c0aaf73fe 100644 --- a/plugins/baser-core/tests/TestCase/Service/DblogsServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/DblogsServiceTest.php @@ -141,4 +141,16 @@ public function test_delete() $this->assertEquals($count - 1, $this->DblogsService->getIndex()->count()); } + /** + * test getIndex + * 数字以外のユーザーIDは条件にしない + */ + public function testGetIndex_non_numeric_user_id() + { + $this->assertEquals( + $this->DblogsService->getIndex([])->count(), + $this->DblogsService->getIndex(['user_id' => "1'"])->count() + ); + } + } diff --git a/plugins/baser-core/tests/TestCase/Service/UsersServiceTest.php b/plugins/baser-core/tests/TestCase/Service/UsersServiceTest.php index 4f07a6c630..7ab1899dbe 100644 --- a/plugins/baser-core/tests/TestCase/Service/UsersServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/UsersServiceTest.php @@ -453,4 +453,18 @@ public function test_createIndexConditions() $this->assertTrue($found, 'バインド値 %山田% が存在すること'); } + /** + * test createIndexConditions + * 数字以外のユーザーグループIDは条件にしない + */ + public function test_createIndexConditions_non_numeric_user_group_id() + { + $query = $this->Users->Users->find(); + $result = $this->execPrivateMethod($this->Users, 'createIndexConditions', [$query, ['user_group_id' => "1'"]]); + $this->assertStringNotContainsString('INNER JOIN user_groups UserGroups', $result->sql()); + $this->assertEquals($this->Users->getIndex([])->count(), $this->Users->getIndex(['user_group_id' => "1'"])->count()); + // 配列形式も条件にしない + $this->assertEquals($this->Users->getIndex([])->count(), $this->Users->getIndex(['user_group_id' => [1]])->count()); + } + } diff --git a/plugins/bc-blog/src/Controller/Admin/BlogCategoriesController.php b/plugins/bc-blog/src/Controller/Admin/BlogCategoriesController.php index 29033a0848..bd306d247d 100755 --- a/plugins/bc-blog/src/Controller/Admin/BlogCategoriesController.php +++ b/plugins/bc-blog/src/Controller/Admin/BlogCategoriesController.php @@ -59,7 +59,7 @@ public function index( * @noTodo * @unitTest */ - public function add(BlogCategoriesAdminServiceInterface $service, string $blogContentId) + public function add(BlogCategoriesAdminServiceInterface $service, int $blogContentId) { if ($this->request->is('post')) { // EVENT BlogCategories.beforeAdd diff --git a/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php b/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php index 81dba1053a..29c137e359 100755 --- a/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php +++ b/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php @@ -130,7 +130,7 @@ public function add(BlogTagsServiceInterface $service) * @noTodo * @unitTest */ - public function edit(BlogTagsServiceInterface $service, $id) + public function edit(BlogTagsServiceInterface $service, int $id) { $blogTag = $service->get($id); if ($this->request->is(['patch', 'post', 'put'])) { diff --git a/plugins/bc-blog/src/Controller/BlogController.php b/plugins/bc-blog/src/Controller/BlogController.php index 47e26f2e7f..8aeb9aa8db 100755 --- a/plugins/bc-blog/src/Controller/BlogController.php +++ b/plugins/bc-blog/src/Controller/BlogController.php @@ -240,6 +240,10 @@ public function archives( } } } + // 年月日として解釈できない値は、カレンダーウィジェットの mktime() で TypeError になるため、存在しないページとして扱う + if ((isset($pass[1]) && $year === '') || (isset($pass[2]) && $month === '') || (isset($pass[3]) && $day === '')) { + $this->notFound(); + } $this->set($service->getViewVarsForArchivesByDate( $this->paginate($blogPostsService->getIndexByDate($year, $month, $day, array_merge([ 'status' => 'publish', diff --git a/plugins/bc-blog/src/Service/BlogPostsService.php b/plugins/bc-blog/src/Service/BlogPostsService.php index 59c184e67a..458e79de0c 100755 --- a/plugins/bc-blog/src/Service/BlogPostsService.php +++ b/plugins/bc-blog/src/Service/BlogPostsService.php @@ -244,6 +244,10 @@ protected function createIndexConditions(Query $query, array $params) foreach($params as $key => $value) { if ($value === '') unset($params[$key]); } + // 数値で指定する条件に数字以外が渡されると型変換できず例外になるため、条件にしない + foreach(['user_id', 'blog_tag_id', 'blog_category_id'] as $key) { + if (isset($params[$key]) && (!is_scalar($params[$key]) || !ctype_digit((string)$params[$key]))) unset($params[$key]); + } if (empty($params)) return $query; $params = array_merge([ diff --git a/plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php b/plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php index 09405396ad..114a2caa65 100755 --- a/plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php +++ b/plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php @@ -256,6 +256,11 @@ public function test_archives() $vars = $this->_controller->viewBuilder()->getVars(); $this->assertEquals('yearly', $vars['blogArchiveType']); $this->assertEquals('post1', $vars['posts']->toArray()[0]->name); + // 年月日として解釈できない値は 404 + $this->get('/news/archives/date/2023/' . urlencode("1'")); + $this->assertResponseCode(404); + $this->get('/news/archives/date/2023/1/' . urlencode("1'")); + $this->assertResponseCode(404); } /** diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 2259165eb7..4422eef759 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -1210,6 +1210,27 @@ public function test_getUrl() $this->assertEquals('https://localhost/archives/1', $rs); } + /** + * test getIndex + * 数字以外のユーザーID・タグID・カテゴリIDは条件にしない + */ + public function testGetIndex_non_numeric_id() + { + BlogPostFactory::make(['id' => 1, 'blog_content_id' => 1, 'user_id' => 1, 'blog_category_id' => 1])->persist(); + BlogPostFactory::make(['id' => 2, 'blog_content_id' => 1, 'user_id' => 2, 'blog_category_id' => 2])->persist(); + $this->assertEquals(2, $this->BlogPostsService->getIndex([ + 'user_id' => "1'", + 'blog_tag_id' => "1'", + 'blog_category_id' => "1'", + ])->count()); + // 配列形式も条件にしない + $this->assertEquals(2, $this->BlogPostsService->getIndex([ + 'user_id' => [1], + 'blog_tag_id' => [1], + 'blog_category_id' => [1], + ])->count()); + } + /** * test filterBlogTagIds */ diff --git a/plugins/bc-custom-content/src/Controller/Admin/CustomEntriesController.php b/plugins/bc-custom-content/src/Controller/Admin/CustomEntriesController.php index 467415fb1c..6a46d65660 100644 --- a/plugins/bc-custom-content/src/Controller/Admin/CustomEntriesController.php +++ b/plugins/bc-custom-content/src/Controller/Admin/CustomEntriesController.php @@ -23,6 +23,7 @@ use BcCustomContent\Service\CustomTablesService; use BcCustomContent\Service\CustomTablesServiceInterface; use Cake\Event\EventInterface; +use Cake\Http\Exception\NotFoundException; use Cake\ORM\Exception\PersistenceFailedException; /** @@ -54,7 +55,9 @@ public function beforeFilter(EventInterface $event) /** @var CustomTablesService $entriesService */ $tablesService = $this->getService(CustomTablesServiceInterface::class); - $contentId = $tablesService->getCustomContentId($tableId); + // 数字以外の ID は int 型の引数に渡せず TypeError になるため、存在しないページとして扱う + if (!ctype_digit((string)$tableId)) throw new NotFoundException(__d('baser_core', 'カスタムテーブルが見つかりません。')); + $contentId = $tablesService->getCustomContentId((int)$tableId); if ($contentId) { /** @var ContentsService $contentsService */ diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomEntriesControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomEntriesControllerTest.php index 52418b8eff..a40b5aed57 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomEntriesControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomEntriesControllerTest.php @@ -22,6 +22,7 @@ use BcCustomContent\Test\Scenario\CustomEntriesScenario; use Cake\Core\Configure; use Cake\Event\Event; +use Cake\Http\Exception\NotFoundException; use Cake\ORM\TableRegistry; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -514,4 +515,17 @@ public function test_move_down() //不要なテーブルを削除 $dataBaseService->dropTable('custom_entry_1_recruit_categories'); } + + /** + * test beforeFilter + * 数字以外のテーブル ID は NotFoundException + */ + public function test_beforeFilter_non_numeric_id() + { + $this->expectException(NotFoundException::class); + $request = $this->loginAdmin($this->getRequest('/baser/admin/bc-custom-content/custom_entries/index/' . urlencode("1'"))); + $controller = new CustomEntriesController($request); + $controller->beforeFilter(new Event('beforeFilter')); + } + } diff --git a/plugins/bc-mail/src/Service/Admin/MailMessagesAdminService.php b/plugins/bc-mail/src/Service/Admin/MailMessagesAdminService.php index 6c52378fd0..ac0b410a1d 100644 --- a/plugins/bc-mail/src/Service/Admin/MailMessagesAdminService.php +++ b/plugins/bc-mail/src/Service/Admin/MailMessagesAdminService.php @@ -88,8 +88,13 @@ public function getViewVarsForDownloadCsv(int $mailContentId, ServerRequest $req { $currentContent = $request->getAttribute('currentContent'); $this->setup($mailContentId); + $encoding = $request->getQuery('encoding'); + // 対応していない文字コードは mb_convert_encoding で ValueError になるため、既定の UTF-8 にする + if (!is_string($encoding) || !in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()), true)) { + $encoding = 'utf-8'; + } return [ - 'encoding' => $request->getQuery('encoding') ?? 'utf-8', + 'encoding' => $encoding, 'messages' => $this->MailMessages->convertMessageToCsv($this->getIndex()->all()->toArray()), 'contentName' => $currentContent ? $request->getAttribute('currentContent')?->name : '', 'escapeFormula' => !$request->getQuery('disable_formula_escape'), diff --git a/plugins/bc-mail/tests/TestCase/Service/Admin/MailMessagesAdminServiceTest.php b/plugins/bc-mail/tests/TestCase/Service/Admin/MailMessagesAdminServiceTest.php index c2674aa954..1040acaff7 100644 --- a/plugins/bc-mail/tests/TestCase/Service/Admin/MailMessagesAdminServiceTest.php +++ b/plugins/bc-mail/tests/TestCase/Service/Admin/MailMessagesAdminServiceTest.php @@ -138,12 +138,21 @@ public function test_getViewVarsForDownloadCsv() // 正常系実行:Encodingを指定するケース $request = $this->getRequest()->withQueryParams([ 'Site' => SiteFactory::get(1), - 'encoding' => 'abc', + 'encoding' => 'SJIS-win', 'Content' => ContentFactory::get(1) ]); $this->loginAdmin($request); $result = $this->MailMessagesAdminService->getViewVarsForDownloadCsv(1, $request); - $this->assertEquals('abc', $result['encoding']); + $this->assertEquals('SJIS-win', $result['encoding']); + + // 異常系実行:対応していない Encoding を指定するケースは UTF-8 にする + $request = $this->getRequest()->withQueryParams([ + 'encoding' => 'UTF-8