Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pywb/rewrite/jsonp_rewriter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from urllib.parse import parse_qs, urlsplit
from pywb.rewrite.content_rewriter import StreamingRewriter


Expand All @@ -7,7 +8,7 @@ class JSONPRewriter(StreamingRewriter):
#JSONP = re.compile(r'^(?:\s*\/\*(?:.*)\*\/)*\s*(\w+)\(\{')
# Match a single /* and // style comments at the beginning
JSONP = re.compile(r'(?:^[ \t]*(?:(?:\/\*[^\*]*\*\/)|(?:\/\/[^\n]+[\n])))*[ \t]*(\w+)\(\{', re.M)
CALLBACK = re.compile(r'[?].*callback=([^&]+)')
CALLBACK = re.compile(r'^[A-Za-z_$][0-9A-Za-z_$]*(?:\.[A-Za-z_$][0-9A-Za-z_$]*)*$')

def rewrite(self, string):
# see if json is jsonp, starts with callback func
Expand All @@ -16,16 +17,21 @@ def rewrite(self, string):
return string

# see if there is a callback param in current url
m_callback = self.CALLBACK.search(self.url_rewriter.wburl.url)
if not m_callback:
query = parse_qs(urlsplit(self.url_rewriter.wburl.url).query, keep_blank_values=True)
callbacks = query.get('callback')
if not callbacks:
return string
if m_callback.group(1) == '?':

callback = callbacks[-1]
if callback == '?':
# this is a very sharp edge case e.g. callback=?
# since we only have this string[m_json.end(1):]
# would cut off the name of the CB if any is included
# so we just pass the string through
return string
if not self.CALLBACK.match(callback):
return string

string = m_callback.group(1) + string[m_json.end(1):]
string = callback + string[m_json.end(1):]
return string

4 changes: 1 addition & 3 deletions pywb/warcserver/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PywbHttpAdapter(HTTPAdapter):
until a better solution is found
"""

def __init__(self, cert_reqs='CERT_NONE', ca_cert_dir=None, **init_kwargs):
def __init__(self, cert_reqs='CERT_REQUIRED', ca_cert_dir=None, **init_kwargs):
self.cert_reqs = cert_reqs
self.ca_cert_dir = ca_cert_dir
return super(PywbHttpAdapter, self).__init__(**init_kwargs)
Expand Down Expand Up @@ -50,5 +50,3 @@ class DefaultAdapters(object):
remote_adapter = PywbHttpAdapter(max_retries=Retry(3))


requests.packages.urllib3.disable_warnings()

Loading