Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
c35fdddd
Commit
c35fdddd
authored
Sep 05, 2018
by
Fantix King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiple slashes
parent
75e51ebc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
helpers.py
flask_admin/helpers.py
+7
-1
test_helpers.py
flask_admin/tests/test_helpers.py
+6
-1
No files found.
flask_admin/helpers.py
View file @
c35fdddd
...
@@ -10,6 +10,7 @@ from ._compat import string_types
...
@@ -10,6 +10,7 @@ from ._compat import string_types
VALID_SCHEMES
=
[
'http'
,
'https'
]
VALID_SCHEMES
=
[
'http'
,
'https'
]
_substitute_whitespace
=
compile
(
r'[\s\x00-\x08\x0B\x0C\x0E-\x19]+'
)
.
sub
_substitute_whitespace
=
compile
(
r'[\s\x00-\x08\x0B\x0C\x0E-\x19]+'
)
.
sub
_fix_multiple_slashes
=
compile
(
r'(^([^/]+:)?//)/*'
)
.
sub
def
set_current_view
(
view
):
def
set_current_view
(
view
):
...
@@ -137,8 +138,13 @@ def is_safe_url(target):
...
@@ -137,8 +138,13 @@ def is_safe_url(target):
# refs https://stackoverflow.com/questions/10438008
# refs https://stackoverflow.com/questions/10438008
target
=
target
.
replace
(
'
\\
'
,
'/'
)
target
=
target
.
replace
(
'
\\
'
,
'/'
)
#
prevent urls starting with "javascrip
t:"
#
handle cases like "j a v a s c r i p
t:"
target
=
_substitute_whitespace
(
''
,
target
)
target
=
_substitute_whitespace
(
''
,
target
)
# Chrome and FireFox "fix" more than two slashes into two after protocol
target
=
_fix_multiple_slashes
(
lambda
m
:
m
.
group
(
1
),
target
,
1
)
# prevent urls starting with "javascript:"
target_info
=
urlparse
(
target
)
target_info
=
urlparse
(
target
)
target_scheme
=
target_info
.
scheme
target_scheme
=
target_info
.
scheme
if
target_scheme
and
target_scheme
not
in
VALID_SCHEMES
:
if
target_scheme
and
target_scheme
not
in
VALID_SCHEMES
:
...
...
flask_admin/tests/test_helpers.py
View file @
c35fdddd
...
@@ -11,9 +11,14 @@ def test_is_safe_url():
...
@@ -11,9 +11,14 @@ def test_is_safe_url():
assert
helpers
.
is_safe_url
(
'https://127.0.0.1/admin/car/'
)
assert
helpers
.
is_safe_url
(
'https://127.0.0.1/admin/car/'
)
assert
helpers
.
is_safe_url
(
'/admin/car/'
)
assert
helpers
.
is_safe_url
(
'/admin/car/'
)
assert
helpers
.
is_safe_url
(
'admin/car/'
)
assert
helpers
.
is_safe_url
(
'admin/car/'
)
assert
helpers
.
is_safe_url
(
'http////www.google.com'
)
assert
not
helpers
.
is_safe_url
(
'http://127.0.0.2/admin/car/'
)
assert
not
helpers
.
is_safe_url
(
'http://127.0.0.2/admin/car/'
)
assert
not
helpers
.
is_safe_url
(
' javascript:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
' javascript:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
'javascript:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
'javascript:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
'javascrip
\n
t:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
'javascrip
\n
t:alert(document.domain)'
)
assert
not
helpers
.
is_safe_url
(
'
\\\\
www.google.com'
)
assert
not
helpers
.
is_safe_url
(
r'\\www.google.com'
)
assert
not
helpers
.
is_safe_url
(
r'\\/www.google.com'
)
assert
not
helpers
.
is_safe_url
(
'/////www.google.com'
)
assert
not
helpers
.
is_safe_url
(
'http:///www.google.com'
)
assert
not
helpers
.
is_safe_url
(
'https:////www.google.com'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment