appstore: validate the id and the version
This commit is contained in:
+6
-3
@@ -40,6 +40,7 @@ const apps = require('./apps.js'),
|
||||
dashboard = require('./dashboard.js'),
|
||||
debug = require('debug')('box:appstore'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
manifestFormat = require('cloudron-manifestformat'),
|
||||
network = require('./network.js'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
@@ -415,9 +416,11 @@ async function downloadManifest(appStoreId, manifest) {
|
||||
|
||||
if (!appStoreId) return { appStoreId: '', manifest };
|
||||
|
||||
const parts = appStoreId.split('@');
|
||||
const [id, version] = appStoreId.split('@');
|
||||
if (!manifestFormat.isId(id)) throw new BoxError(BoxError.BAD_FIELD, 'appStoreId is not valid');
|
||||
if (version && !semver.valid(version)) throw new BoxError(BoxError.BAD_FIELD, 'package version is not valid semver');
|
||||
|
||||
const url = await getApiServerOrigin() + '/api/v1/apps/' + parts[0] + (parts[1] ? '/versions/' + parts[1] : '');
|
||||
const url = await getApiServerOrigin() + '/api/v1/apps/' + id + (version ? '/versions/' + version : '');
|
||||
|
||||
debug(`downloading manifest from ${url}`);
|
||||
|
||||
@@ -429,7 +432,7 @@ async function downloadManifest(appStoreId, manifest) {
|
||||
|
||||
if (!response.body.manifest || typeof response.body.manifest !== 'object') throw new BoxError(BoxError.NOT_FOUND, `Missing manifest. Failed to get app info from store. status: ${response.status} text: ${response.text}`);
|
||||
|
||||
return { appStoreId: parts[0], manifest: response.body.manifest };
|
||||
return { appStoreId: id, manifest: response.body.manifest };
|
||||
}
|
||||
|
||||
async function getApps() {
|
||||
|
||||
Reference in New Issue
Block a user