Skip to content

Commit

Permalink
Whitelist urllib and urlparse modules (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
nngu6036 authored and instification committed Apr 18, 2019
1 parent af45495 commit 522cbc3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions collective/trustedimports/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<include zcml:condition="installed pystache" package=".pystache" />
<include zcml:condition="installed phonenumbers" package=".phonenumbers" />
<include zcml:condition="installed zeep" package=".soap" />
<include package=".url" />

</configure>
9 changes: 9 additions & 0 deletions collective/trustedimports/url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from collective.trustedimports.util import whitelist_module, wrap_protected, is_url_allowed
from AccessControl import allow_class, ModuleSecurityInfo, ClassSecurityInfo, Unauthorized
from AccessControl.class_init import InitializeClass
from Products.PythonScripts.Utility import allow_module
import urllib
import urlparse

ModuleSecurityInfo('urllib').declarePublic('quote')
ModuleSecurityInfo('urlparse').declarePublic('urlparse')
37 changes: 37 additions & 0 deletions collective/trustedimports/url.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
urllib
===========

>>> teval("import urllib;return urllib.quote('châteu', safe='')")
'ch%C3%A2teu'


We also can parse with urlparse
>>> print teval("from urlparse import urlparse;return urlparse('https://www.google.com/')")
ParseResult...


We cannot user other function of urllib, such as
>>> teval("import urllib;urllib.urlopen('https://www.google.com')")
Traceback (most recent call last):
...
Unauthorized: You are not allowed to access 'urlopen' in this context


We cannot user other function of urlparse, such as
>>> teval("from urlparse import urljoin; urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')")
Traceback (most recent call last):
...
Unauthorized: You are not allowed to access 'urljoin' in this context


We can use these functions in system python

>>> import urllib
>>> urllib.urlopen('https://www.google.com')
<addinfourl at ...

>>> from urlparse import urljoin
>>> urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
'http://www.cwi.nl/%7Eguido/FAQ.html'


0 comments on commit 522cbc3

Please sign in to comment.