@@ -102,6 +102,9 @@ public function show(int $contextId): DataResponse {
102102 #[NoAdminRequired]
103103 public function create (string $ name , string $ iconName , string $ description = '' , array $ nodes = []): DataResponse {
104104 try {
105+ if (!$ this ->isValidIcon ($ iconName )) {
106+ return new DataResponse (['message ' => 'Invalid icon name ' ], Http::STATUS_BAD_REQUEST );
107+ }
105108 return new DataResponse ($ this ->contextService ->create (
106109 $ name ,
107110 $ iconName ,
@@ -128,9 +131,10 @@ public function create(string $name, string $iconName, string $description = '',
128131 * @param ?string $description provide this parameter to set a new description
129132 * @param ?array{id: int, type: int, permissions: int, order: int} $nodes provide this parameter to set a new list of nodes.
130133 *
131- * @return DataResponse<Http::STATUS_OK, TablesContext, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_FORBIDDEN, array{message: string}, array{}>
134+ * @return DataResponse<Http::STATUS_OK, TablesContext, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST , array{message: string}, array{}>
132135 *
133136 * 200: returning the full context information
137+ * 400: bad request
134138 * 403: No permissions
135139 * 404: Not found
136140 *
@@ -139,6 +143,9 @@ public function create(string $name, string $iconName, string $description = '',
139143 #[NoAdminRequired]
140144 public function update (int $ contextId , ?string $ name , ?string $ iconName , ?string $ description , ?array $ nodes ): DataResponse {
141145 try {
146+ if ($ iconName !== null && !$ this ->isValidIcon ($ iconName )) {
147+ return new DataResponse (['message ' => 'Invalid icon name ' ], Http::STATUS_BAD_REQUEST );
148+ }
142149 $ nodes = $ nodes !== null ? $ this ->sanitizeInputNodes ($ nodes ) : null ;
143150 return new DataResponse ($ this ->contextService ->update (
144151 $ contextId ,
@@ -271,6 +278,14 @@ public function updateContentOrder(int $contextId, int $pageId, array $content):
271278 return new DataResponse ($ this ->contextService ->updateContentOrder ($ pageId , $ content ));
272279 }
273280
281+ protected function isValidIcon (string $ iconName ): bool {
282+ if ($ iconName === '' || !preg_match ('/^[a-zA-Z0-9-]+$/ ' , $ iconName )) {
283+ return false ;
284+ }
285+ $ iconPath = dirname (__DIR__ , 2 ) . '/img/material/ ' . $ iconName . '.svg ' ;
286+ return file_exists ($ iconPath );
287+ }
288+
274289 /**
275290 * @param Context[] $contexts
276291 * @return array
0 commit comments