@@ -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 ,
@@ -139,6 +142,9 @@ public function create(string $name, string $iconName, string $description = '',
139142 #[NoAdminRequired]
140143 public function update (int $ contextId , ?string $ name , ?string $ iconName , ?string $ description , ?array $ nodes ): DataResponse {
141144 try {
145+ if ($ iconName !== null && !$ this ->isValidIcon ($ iconName )) {
146+ return new DataResponse (['message ' => 'Invalid icon name ' ], Http::STATUS_BAD_REQUEST );
147+ }
142148 $ nodes = $ nodes !== null ? $ this ->sanitizeInputNodes ($ nodes ) : null ;
143149 return new DataResponse ($ this ->contextService ->update (
144150 $ contextId ,
@@ -271,6 +277,14 @@ public function updateContentOrder(int $contextId, int $pageId, array $content):
271277 return new DataResponse ($ this ->contextService ->updateContentOrder ($ pageId , $ content ));
272278 }
273279
280+ protected function isValidIcon (string $ iconName ): bool {
281+ if ($ iconName === '' || !preg_match ('/^[a-zA-Z0-9-]+$/ ' , $ iconName )) {
282+ return false ;
283+ }
284+ $ iconPath = dirname (__DIR__ , 2 ) . '/img/material/ ' . $ iconName . '.svg ' ;
285+ return file_exists ($ iconPath );
286+ }
287+
274288 /**
275289 * @param Context[] $contexts
276290 * @return array
0 commit comments