diff --git a/app.py b/app.py index 656ecfddc..9926ee766 100644 --- a/app.py +++ b/app.py @@ -11,6 +11,7 @@ from flask_login import LoginManager from flask_mail import Mail from flask_principal import Principal from jwkest.jwk import RSAKey +from werkzeug.exceptions import HTTPException import features @@ -143,7 +144,11 @@ FILTERED_VALUES = [ @app.after_request def _request_end(resp): - jsonbody = request.get_json(force=True, silent=True) + try: + jsonbody = request.get_json(force=True, silent=True) + except HTTPException: + jsonbody = None + values = request.values.to_dict() if jsonbody and not isinstance(jsonbody, dict): diff --git a/endpoints/api/image.py b/endpoints/api/image.py index 9fb3c5c92..3a9dcd82c 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -8,11 +8,18 @@ from endpoints.exception import NotFound def image_dict(image, with_history=False, with_tags=False): + parsed_command = None + if image.command: + try: + parsed_command = json.loads(image.command) + except (ValueError, TypeError): + parsed_command = {'error': 'Could not parse command'} + image_data = { 'id': image.docker_image_id, 'created': format_date(image.created), 'comment': image.comment, - 'command': json.loads(image.command) if image.command else None, + 'command': parsed_command, 'size': image.image_size, 'uploading': image.uploading, 'sort_index': len(image.parents), diff --git a/endpoints/web.py b/endpoints/web.py index be22dfeb7..cdb463cfa 100644 --- a/endpoints/web.py +++ b/endpoints/web.py @@ -843,6 +843,10 @@ def redirect_to_repository(namespace_name, repo_name, tag_name): @process_oauth @anon_protect def redirect_to_namespace(namespace): + okay, _ = model.user.validate_username(namespace) + if not okay: + abort(404) + user_or_org = model.user.get_user_or_org(namespace) if not user_or_org: abort(404)