PluginProbe
CSS & JavaScript Toolbox / trunk
CSS & JavaScript Toolbox vtrunk
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / controllers / template.php

template.php in CSS & JavaScript Toolbox trunk, at controllers/template.php

139 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version $ Id; ?FILE_NAME ?DATE ?TIME ?AUTHOR $
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 // import dependencies.
10 cssJSToolbox::import('framework:mvc:controller-ajax.inc.php');
11
12 /**
13 *
14 * DESCRIPTION
15 *
16 * @author ??
17 * @version ??
18 */
19 class CJTTemplateController extends CJTAjaxController {
20
21 /**
22 * put your comment there...
23 *
24 * @var mixed
25 */
26 protected $controllerInfo = array('model' => 'template');
27
28 /**
29 * put your comment there...
30 *
31 * @var mixed
32 */
33 protected $onsave = array('parameters' => array('data'));
34
35 /**
36 *
37 * Initialize new object.
38 *
39 * @return void
40 */
41 public function __construct() {
42 // Initialize parent!
43 parent::__construct();
44 // Add actions.
45 $this->registryAction('edit');
46 $this->registryAction('save');
47 $this->registryAction('info');
48 $this->registryAction('getTemplateBy');
49 }
50
51 /**
52 * put your comment there...
53 *
54 */
55 protected function editAction() {
56 $this->model->inputs['id'] = (int) $_REQUEST['id'];
57 // Display the view.
58 parent::displayAction();
59 }
60
61 /**
62 * put your comment there...
63 *
64 */
65 protected function getTemplateByAction() {
66 // Initialize.
67 $returns = array_flip($_GET['returns']);
68 // Set inputs.
69 $inputs =& $this->model->inputs;
70 $inputs['filter'] = $_GET['filter'];
71 // Query Block.
72 $this->response = array_intersect_key((array) $this->model->getTemplateBy(), $returns);
73 }
74
75 /**
76 * put your comment there...
77 *
78 */
79 protected function infoAction() {
80 $this->model->inputs['id'] = (int) $_REQUEST['id'];
81 // Display the view.
82 parent::displayAction();
83 }
84
85 /**
86 * Save template data with proper sanitization to prevent XSS attacks.
87 *
88 * Security Fix: Sanitizes all user inputs (description, keywords, name, changeLog, version)
89 * to prevent Stored XSS vulnerabilities. This addresses the security issue where malicious
90 * scripts could be injected through template fields and executed when viewing the Templates
91 * Manager page, Template Lookup feature, or when using the Embed/Link Templates functionality.
92 *
93 * @security CVE Reference: Stored XSS in template save endpoint
94 */
95 protected function saveAction() {
96 // Read inputs
97 $item = filter_input(INPUT_POST, 'item', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY);
98
99 // Sanitize template fields to prevent XSS
100 if (isset($item['template'])) {
101 // Sanitize description field - strip all HTML tags
102 if (isset($item['template']['description'])) {
103 $item['template']['description'] = sanitize_textarea_field($item['template']['description']);
104 }
105
106 // Sanitize keywords field - strip all HTML tags
107 if (isset($item['template']['keywords'])) {
108 $item['template']['keywords'] = sanitize_textarea_field($item['template']['keywords']);
109 }
110
111 // Sanitize name field
112 if (isset($item['template']['name'])) {
113 $item['template']['name'] = sanitize_text_field($item['template']['name']);
114 }
115 }
116
117 // Sanitize revision fields
118 if (isset($item['revision'])) {
119 // Sanitize changeLog field
120 if (isset($item['revision']['changeLog'])) {
121 $item['revision']['changeLog'] = sanitize_textarea_field($item['revision']['changeLog']);
122 }
123
124 // Sanitize version field
125 if (isset($item['revision']['version'])) {
126 $item['revision']['version'] = sanitize_text_field($item['revision']['version']);
127 }
128 }
129
130 // Posted template data is in the item array, the others is just for making the request!
131 $this->model->inputs['item'] = $this->onsave($item);
132 if ($revision = $this->model->save()) {
133 $this->response = array('revision' => $revision);
134 }
135 }
136 } // End class.
137
138 // Hookable!
139 CJTTemplateController::define('CJTTemplateController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));