Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
202bd2da
Commit
202bd2da
authored
Jun 14, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport InternalRedirect#sanitize_redirect
parent
adb06988
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
app/controllers/concerns/internal_redirect.rb
app/controllers/concerns/internal_redirect.rb
+4
-0
spec/controllers/concerns/internal_redirect_spec.rb
spec/controllers/concerns/internal_redirect_spec.rb
+25
-0
No files found.
app/controllers/concerns/internal_redirect.rb
View file @
202bd2da
...
...
@@ -23,6 +23,10 @@ module InternalRedirect
nil
end
def
sanitize_redirect
(
url_or_path
)
safe_redirect_path
(
url_or_path
)
||
safe_redirect_path_for_url
(
url_or_path
)
end
def
host_allowed?
(
uri
)
uri
.
host
==
request
.
host
&&
uri
.
port
==
request
.
port
...
...
spec/controllers/concerns/internal_redirect_spec.rb
View file @
202bd2da
...
...
@@ -54,6 +54,31 @@ describe InternalRedirect do
end
end
describe
'#sanitize_redirect'
do
let
(
:valid_path
)
{
'/hello/world?hello=world'
}
let
(
:valid_url
)
{
"http://test.host
#{
valid_path
}
"
}
it
'returns `nil` for invalid paths'
do
invalid_path
=
'//not/valid'
expect
(
controller
.
sanitize_redirect
(
invalid_path
)).
to
eq
nil
end
it
'returns `nil` for invalid urls'
do
input
=
'http://test.host:3000/invalid'
expect
(
controller
.
sanitize_redirect
(
input
)).
to
eq
nil
end
it
'returns input for valid paths'
do
expect
(
controller
.
sanitize_redirect
(
valid_path
)).
to
eq
valid_path
end
it
'returns path for valid urls'
do
expect
(
controller
.
sanitize_redirect
(
valid_url
)).
to
eq
valid_path
end
end
describe
'#host_allowed?'
do
it
'allows uris with the same host and port'
do
expect
(
controller
.
host_allowed?
(
URI
(
'http://test.host/test'
))).
to
be
(
true
)
...
...
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