diff --git a/locales/en.json b/locales/en.json index 6d5dfc628..0880fdddd 100644 --- a/locales/en.json +++ b/locales/en.json @@ -31,6 +31,7 @@ "appslist_fetched": "The app list has been fetched", "appslist_removed": "The app list has been removed", "appslist_retrieve_error": "Unable to retrieve the remote app list: {error}", + "appslist_retrieve_bad_format": "Retrieved file is not a valid app list", "appslist_unknown": "Unknown app list", "ask_current_admin_password": "Current administration password", "ask_email": "Email address", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index f1c0bae20..5499f4b02 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -100,10 +100,22 @@ def app_fetchlist(url=None, name=None): # Download file try: - applist = requests.get(url, timeout=30).text + applist_request = requests.get(url, timeout=30) except Exception as e: raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error', error=str(e))) - + + if (applist_request.status_code != 200): + raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_error', error="404, not found")) + + # Validate app list format + # TODO / Possible improvement : better validation for app list (check that + # json fields actually look like an app list and not any json file) + applist = applist_request.text + try: + json.loads(applist) + except ValueError, e: + raise MoulinetteError(errno.EBADR, m18n.n('appslist_retrieve_bad_format')) + # Write app list to file list_file = '%s/%s.json' % (repo_path, name) with open(list_file, "w") as f: