Mercurial > public > sg101
comparison core/management/commands/ssl_images.py @ 963:4619290d171d
Whitelist hot-linked image sources.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 01 Sep 2015 20:33:40 -0500 |
parents | 62cd07bb891c |
children | a6331579ff43 |
comparison
equal
deleted
inserted
replaced
962:10e7570a3aab | 963:4619290d171d |
---|---|
37 re.DOTALL | re.UNICODE) | 37 re.DOTALL | re.UNICODE) |
38 IMAGE_REF_RE = re.compile(markdown.inlinepatterns.IMAGE_REFERENCE_RE, | 38 IMAGE_REF_RE = re.compile(markdown.inlinepatterns.IMAGE_REFERENCE_RE, |
39 re.DOTALL | re.UNICODE) | 39 re.DOTALL | re.UNICODE) |
40 | 40 |
41 SG101_HOSTS = set(['www.surfguitar101.com', 'surfguitar101.com']) | 41 SG101_HOSTS = set(['www.surfguitar101.com', 'surfguitar101.com']) |
42 WHITELIST_HOSTS = set(settings.USER_IMAGES_SOURCES) | |
42 MODEL_CHOICES = ['comments', 'posts'] | 43 MODEL_CHOICES = ['comments', 'posts'] |
43 | 44 |
44 PHOTO_MAX_SIZE = (660, 720) | 45 PHOTO_MAX_SIZE = (660, 720) |
45 PHOTO_BASE_URL = 'https://s3.amazonaws.com/' | 46 PHOTO_BASE_URL = 'https://s3.amazonaws.com/' |
46 PHOTO_BUCKET_NAME = 'sg101.forum.photos' | 47 PHOTO_BUCKET_NAME = 'sg101.forum.photos' |
222 new_src = r.path # convert to relative path | 223 new_src = r.path # convert to relative path |
223 elif r.scheme == 'http': | 224 elif r.scheme == 'http': |
224 # Try a few things to get this on ssl: | 225 # Try a few things to get this on ssl: |
225 new_src = convert_to_ssl(r) | 226 new_src = convert_to_ssl(r) |
226 elif r.scheme == 'https': | 227 elif r.scheme == 'https': |
227 new_src = src # already https, accept it as-is | 228 if r.hostname in WHITELIST_HOSTS: |
229 new_src = src # already in whitelist | |
230 else: | |
231 new_src = convert_to_ssl(r) | |
228 | 232 |
229 if new_src: | 233 if new_src: |
230 if title: | 234 if title: |
231 s = u'![{alt}]({src} {title})'.format(alt=alt, src=new_src, title=title) | 235 s = u'![{alt}]({src} {title})'.format(alt=alt, src=new_src, title=title) |
232 else: | 236 else: |