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
8af10e0b
Unverified
Commit
8af10e0b
authored
Dec 20, 2018
by
Serge S. Koval
Committed by
GitHub
Dec 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1699 from lbhsot/master
refs #1503 fix reflected xss
parents
19397625
aca862f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
helpers.py
flask_admin/helpers.py
+14
-2
test_helpers.py
flask_admin/tests/test_helpers.py
+7
-0
No files found.
flask_admin/helpers.py
View file @
8af10e0b
from
re
import
sub
from
re
import
sub
,
compile
from
jinja2
import
contextfunction
from
jinja2
import
contextfunction
from
flask
import
g
,
request
,
url_for
,
flash
from
flask
import
g
,
request
,
url_for
,
flash
from
wtforms.validators
import
DataRequired
,
InputRequired
from
wtforms.validators
import
DataRequired
,
InputRequired
...
@@ -9,6 +9,8 @@ from ._compat import string_types
...
@@ -9,6 +9,8 @@ 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
_fix_multiple_slashes
=
compile
(
r'(^([^/]+:)?//)/*'
)
.
sub
def
set_current_view
(
view
):
def
set_current_view
(
view
):
...
@@ -131,8 +133,18 @@ def prettify_class_name(name):
...
@@ -131,8 +133,18 @@ def prettify_class_name(name):
def
is_safe_url
(
target
):
def
is_safe_url
(
target
):
# prevent urls like "\\www.google.com"
# some browser will change \\ to // (eg: Chrome)
# refs https://stackoverflow.com/questions/10438008
target
=
target
.
replace
(
'
\\
'
,
'/'
)
# handle cases like "j a v a s c r i p t:"
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:"
# prevent urls starting with "javascript:"
target
=
target
.
strip
()
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 @
8af10e0b
...
@@ -11,7 +11,14 @@ def test_is_safe_url():
...
@@ -11,7 +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
(
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