Merge pull request #1539 from jakedt/noescape

Remove escaped_fragment snapshot rendering.
This commit is contained in:
Jake Moshenko 2016-06-14 12:59:10 -04:00 committed by GitHub
commit f36442aa0d
5 changed files with 0 additions and 64 deletions

1
.gitignore vendored
View file

@ -1,6 +1,5 @@
*.pyc *.pyc
venv venv
static/snapshots/
screenshots/screenshots/ screenshots/screenshots/
stack stack
grunt/node_modules grunt/node_modules

View file

@ -29,7 +29,6 @@ RUN apt-get install -y \
libsasl2-modules \ libsasl2-modules \
nodejs \ nodejs \
npm \ npm \
phantomjs \
python-dev \ python-dev \
python-pip \ python-pip \
python-virtualenv python-virtualenv

View file

@ -8,10 +8,6 @@ if ($host = "www.quay.io") {
return 301 $proper_scheme://quay.io$request_uri; return 301 $proper_scheme://quay.io$request_uri;
} }
if ($args ~ "_escaped_fragment_") {
rewrite ^ /snapshot$uri;
}
# Disable the ability to be embedded into iframes # Disable the ability to be embedded into iframes
add_header X-Frame-Options DENY; add_header X-Frame-Options DENY;

View file

@ -32,7 +32,6 @@ from health.healthcheck import get_healthchecker
from util.cache import no_cache from util.cache import no_cache
from util.headers import parse_basic_auth from util.headers import parse_basic_auth
from util.invoice import renderInvoiceToPdf from util.invoice import renderInvoiceToPdf
from util.seo import render_snapshot
from util.systemlogs import build_logs_archive from util.systemlogs import build_logs_archive
from util.useremails import send_email_changed from util.useremails import send_email_changed
@ -84,19 +83,6 @@ def user_view(path):
return index('') return index('')
@web.route('/snapshot', methods=['GET'])
@web.route('/snapshot/', methods=['GET'])
@web.route('/snapshot/<path:path>', methods=['GET'])
def snapshot(path = ''):
parsed = urlparse(request.url)
final_url = '%s://%s/%s' % (parsed.scheme, 'localhost', path)
result = render_snapshot(final_url)
if result:
return result
abort(404)
@route_show_if(features.ACI_CONVERSION) @route_show_if(features.ACI_CONVERSION)
@web.route('/aci-signing-key') @web.route('/aci-signing-key')
@no_cache @no_cache

View file

@ -1,44 +0,0 @@
import subprocess
import logging
from urllib import urlencode
from urlparse import parse_qs, urlsplit, urlunsplit
from bs4 import BeautifulSoup
logger = logging.getLogger(__name__)
def set_query_parameter(url, param_name, param_value):
# From: http://stackoverflow.com/questions/4293460/how-to-add-custom-parameters-to-an-url-query-string-with-python
scheme, netloc, path, query_string, fragment = urlsplit(url)
query_params = parse_qs(query_string)
query_params[param_name] = [param_value]
new_query_string = urlencode(query_params, doseq=True)
return urlunsplit((scheme, netloc, path, new_query_string, fragment))
def render_snapshot(url):
logger.info('Snapshotting url: %s' % url)
url = set_query_parameter(url, 'use_cdn', False)
out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes',
'--disk-cache=yes', '--ssl-protocol=tlsv1',
'util/phantomjs-runner.js', url])
if not out_html or out_html.strip() == 'Not Found':
return None
# Remove script tags
logger.info('Removing script tags: %s' % url)
try:
soup = BeautifulSoup(out_html.decode('utf8'), 'html.parser')
to_extract = soup.findAll('script')
for item in to_extract:
item.extract()
except:
logger.exception('Exception when trying to parse served HTML')
return out_html
return str(soup)