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
960f5e0a
Unverified
Commit
960f5e0a
authored
Aug 27, 2018
by
Serge S. Koval
Committed by
GitHub
Aug 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1505 from pawl/issue_1503
check for valid scheme in the redirect target url (prevent xss)
parents
4ecd7429
0dc5a48f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
helpers.py
flask_admin/helpers.py
+11
-2
test_helpers.py
flask_admin/tests/test_helpers.py
+17
-0
No files found.
flask_admin/helpers.py
View file @
960f5e0a
...
...
@@ -8,6 +8,9 @@ from flask_admin._compat import urljoin, urlparse, iteritems
from
._compat
import
string_types
VALID_SCHEMES
=
[
'http'
,
'https'
]
def
set_current_view
(
view
):
g
.
_admin_view
=
view
...
...
@@ -128,10 +131,16 @@ def prettify_class_name(name):
def
is_safe_url
(
target
):
# prevent urls starting with "javascript:"
target
=
target
.
strip
()
target_info
=
urlparse
(
target
)
target_scheme
=
target_info
.
scheme
if
target_scheme
and
target_scheme
not
in
VALID_SCHEMES
:
return
False
ref_url
=
urlparse
(
request
.
host_url
)
test_url
=
urlparse
(
urljoin
(
request
.
host_url
,
target
))
return
(
test_url
.
scheme
in
(
'http'
,
'https'
)
and
ref_url
.
netloc
==
test_url
.
netloc
)
return
ref_url
.
netloc
==
test_url
.
netloc
def
get_redirect_target
(
param_name
=
'url'
):
...
...
flask_admin/tests/test_helpers.py
0 → 100644
View file @
960f5e0a
import
flask
from
flask_admin
import
helpers
def
test_is_safe_url
():
app
=
flask
.
Flask
(
__name__
)
with
app
.
test_request_context
(
'http://127.0.0.1/admin/car/edit/'
):
assert
helpers
.
is_safe_url
(
'http://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
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)'
)
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