Commit e9dc3344 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

plankton: Validate meta key/value length

Fail with BadRequest if length of metadata key or value is not valid.
parent d21d032b
......@@ -74,6 +74,9 @@ PROPERTY_PREFIX = 'property:'
PLANKTON_META = ('container_format', 'disk_format', 'name',
'status', 'created_at')
MAX_META_KEY_LENGTH = 128 - len(PLANKTON_DOMAIN) - len(PROPERTY_PREFIX)
MAX_META_VALUE_LENGTH = 256
from pithos.backends.util import PithosBackendPool
_pithos_backend_pool = \
PithosBackendPool(
......@@ -206,6 +209,14 @@ class ImageBackend(object):
if k in PLANKTON_META or k.startswith(PROPERTY_PREFIX)]
prefixed = dict(prefixed)
for k, v in prefixed.items():
if len(k) > 128:
raise InvalidMetadata('Metadata keys should be less than %s '
'characters' % MAX_META_KEY_LENGTH)
if len(v) > 256:
raise InvalidMetadata('Metadata values should be less than %s '
'characters.' % MAX_META_VALUE_LENGTH)
self.backend.update_object_meta(self.user, account, container, name,
PLANKTON_DOMAIN, prefixed, replace)
logger.debug("User '%s' updated image '%s', meta: '%s'", self.user,
......@@ -469,6 +480,10 @@ class Forbidden(ImageBackendError):
pass
class InvalidMetadata(ImageBackendError):
pass
def image_to_dict(image_url, meta, permissions):
"""Render an image to a dictionary"""
account, container, name = split_url(image_url)
......
......@@ -48,9 +48,11 @@ def image_backend(user_id):
image_backend = backend.get_backend()(user_id)
try:
yield image_backend
except backend.Forbidden:
except backend.Forbidden as e:
raise faults.Forbidden
except backend.ImageNotFound:
raise faults.ItemNotFound
except backend.InvalidMetadata as e:
raise faults.BadRequest(str(e))
finally:
image_backend.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment