diff --git a/app/src/App.php b/app/src/App.php
index 5ef64d27..11e99e52 100644
--- a/app/src/App.php
+++ b/app/src/App.php
@@ -241,11 +241,7 @@ public static function getDeviceType(Request $request): int
// Cookieからデバイスタイプを取得
$device_type = $request->rawCookie('device');
- $devices = [
- App::DEVICE_PC,
- App::DEVICE_SP,
- ];
- if (!empty($device_type) && in_array($device_type, $devices)) {
+ if (!empty($device_type) && static::isExistsDeviceId($device_type)) {
return (int)$device_type;
}
@@ -261,6 +257,16 @@ public static function getDeviceType(Request $request): int
return App::DEVICE_PC;
}
+ /**
+ * デバイスタイプが既知のものか?(許可されているか?)
+ * @param string $id
+ * @return bool
+ */
+ public static function isExistsDeviceId(string $id): bool
+ {
+ return in_array($id, self::ALLOW_DEVICES);
+ }
+
/**
* デバイスタイプを取得する
* @param Request $request
@@ -269,8 +275,7 @@ public static function getDeviceType(Request $request): int
public static function getDeviceTypeStr(Request $request): string
{
$device_id = static::getDeviceType($request);
- $device_table = App::DEVICE_FC2_KEY;
- return $device_table[$device_id];
+ return App::DEVICE_FC2_KEY[$device_id] ?? App::DEVICE_FC2_KEY[App::DEVICE_PC];
}
/**
diff --git a/app/src/Web/Controller/Admin/BlogTemplatesController.php b/app/src/Web/Controller/Admin/BlogTemplatesController.php
index 3b119972..cb8cc7a3 100644
--- a/app/src/Web/Controller/Admin/BlogTemplatesController.php
+++ b/app/src/Web/Controller/Admin/BlogTemplatesController.php
@@ -10,6 +10,7 @@
use Fc2blog\Model\Fc2TemplatesModel;
use Fc2blog\Model\Model;
use Fc2blog\Service\BlogService;
+use Fc2blog\Util\Log;
use Fc2blog\Web\Request;
class BlogTemplatesController extends AdminController
@@ -45,6 +46,11 @@ public function index(Request $request): string
}
$this->set('device_blog_templates', $device_blog_templates);
$this->set('devices', BlogTemplatesModel::DEVICE_NAME);
+ if (!App::isExistsDeviceId($request->get("device_type", (string)App::DEVICE_PC))) {
+ Log::notice("invalid device_type params :" . $request->get("device_type"));
+ return $this->error400();
+ }
+ $this->set('req_device_type', $request->get("device_type"));
return "admin/blog_templates/index.twig";
}
@@ -77,6 +83,11 @@ public function fc2_index(Request $request): string
$this->set('templates', $templates);
$this->set('paging', $paging);
$this->set('devices', BlogTemplatesModel::DEVICE_NAME);
+ if (!App::isExistsDeviceId($request->get("device_type", (string)App::DEVICE_PC))) {
+ Log::notice("invalid device_type params :" . $request->get("device_type"));
+ return $this->error400();
+ }
+ $this->set('req_device_type', $request->get("device_type"));
return "admin/blog_templates/fc2_index.twig";
}
@@ -101,6 +112,12 @@ public function fc2_view(Request $request): string
$device_type = $request->get('device_type', (string)App::DEVICE_PC);
$request->set('device_type', $device_type);
+ if (!App::isExistsDeviceId($request->get("device_type", (string)App::DEVICE_PC))) {
+ Log::notice("invalid device_type params :" . $request->get("device_type"));
+ return $this->error400();
+ }
+ $this->set('req_device_type', $request->get("device_type"));
+
// テンプレート取得
$device_key = App::getDeviceFc2Key($device_type);
$template = Model::load('Fc2Templates')->findByIdAndDevice($request->get('fc2_id'), $device_key);
diff --git a/app/twig_templates/admin/blog_templates/fc2_index.twig b/app/twig_templates/admin/blog_templates/fc2_index.twig
index 68332ae5..d531c0a3 100644
--- a/app/twig_templates/admin/blog_templates/fc2_index.twig
+++ b/app/twig_templates/admin/blog_templates/fc2_index.twig
@@ -3,7 +3,7 @@
{% block content %}
- {{ _('FC2 Template list') }}[{{ _(attribute(constant('Fc2blog\\App::DEVICE_FC2_KEY'), req.get('device_type'))) }}]
{{ _('FC2 Template list') }}[{{ _(attribute(constant('Fc2blog\\App::DEVICE_FC2_KEY'), req_device_type)) }}]
{{ template.name }}
diff --git a/app/twig_templates/admin/blog_templates/fc2_view_sp.twig b/app/twig_templates/admin/blog_templates/fc2_view_sp.twig index 7668ba19..09b7f18a 100644 --- a/app/twig_templates/admin/blog_templates/fc2_view_sp.twig +++ b/app/twig_templates/admin/blog_templates/fc2_view_sp.twig @@ -3,14 +3,14 @@ {% block content %} -@@ -19,7 +19,7 @@
- {{ _('Preview') }} + {{ _('Preview') }}
diff --git a/app/twig_templates/admin/blog_templates/index_sp.twig b/app/twig_templates/admin/blog_templates/index_sp.twig index 6027a50c..e83554a2 100644 --- a/app/twig_templates/admin/blog_templates/index_sp.twig +++ b/app/twig_templates/admin/blog_templates/index_sp.twig @@ -8,7 +8,7 @@