Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only redirect to whitelisted services #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,6 @@ log:
#allowed_service_ips:
# - 127.0.0.1
# - 192.168.0.0/24

allowed_service_hosts:
- http://localhost
8 changes: 6 additions & 2 deletions lib/casserver/cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,12 @@ def clean_service_url(dirty_service)

$LOG.debug("Cleaned dirty service URL #{dirty_service.inspect} to #{clean_service.inspect}") if
dirty_service != clean_service

return clean_service
allowed_hosts = settings.config[:allowed_service_hosts] rescue []
if allowed_hosts.include? clean_service
return clean_service
else
return '/'
end
end
module_function :clean_service_url

Expand Down
11 changes: 10 additions & 1 deletion spec/casserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@
#page.should have_xpath("<script>alert(32)</script>")
end

end # describe '/login'
it "does not redirect to not allowed service" do
visit "/login?service="+CGI.escape("http://badguy.com")

fill_in 'username', :with => VALID_USERNAME
fill_in 'password', :with => VALID_PASSWORD

click_button 'login-submit'
page.current_url.should_not =~ /^#{Regexp.escape("http://badguy.com")}\/?\?ticket=ST\-[1-9rA-Z]+/
end

end # describe '/login'

describe '/logout' do
describe 'user logged in' do
Expand Down
5 changes: 4 additions & 1 deletion spec/config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ enable_single_sign_out: true
#downcase_username: true

allowed_service_ips:
- 127.0.0.0/24
- 127.0.0.0/24
allowed_service_hosts:
- http://localhost
- http://my.app.test