[gnome-shell] extensionSystem: Check metadata types



commit 56d0b6d8317cbb824e997ce6a926028788b11dc8
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Apr 20 19:29:19 2022 +0200

    extensionSystem: Check metadata types
    
    We currently check that an extension provides required metadata
    properties, but then assume that all properties have the expected
    type.
    
    It turns out that this is putting too much trust in extensions,
    so add an appropriate check.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5347
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2272>

 js/ui/extensionSystem.js | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
index 41a03fdf3a..fbfd6c4b05 100644
--- a/js/ui/extensionSystem.js
+++ b/js/ui/extensionSystem.js
@@ -310,11 +310,29 @@ var ExtensionManager = class {
             throw new Error(`Failed to parse metadata.json: ${e}`);
         }
 
-        let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
+        const requiredProperties = [{
+            prop: 'uuid',
+            typeName: 'string',
+        }, {
+            prop: 'name',
+            typeName: 'string',
+        }, {
+            prop: 'description',
+            typeName: 'string',
+        }, {
+            prop: 'shell-version',
+            typeName: 'string array',
+            typeCheck: v => Array.isArray(v) && v.length > 0 && v.every(e => typeof e === 'string'),
+        }];
         for (let i = 0; i < requiredProperties.length; i++) {
-            let prop = requiredProperties[i];
+            const {
+                prop, typeName, typeCheck = v => typeof v === typeName,
+            } = requiredProperties[i];
+
             if (!meta[prop])
                 throw new Error(`missing "${prop}" property in metadata.json`);
+            if (!typeCheck(meta[prop]))
+                throw new Error(`property "${prop}" is not of type ${typeName}`);
         }
 
         if (uuid != meta.uuid)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]