Skip to content

Commit 1af3f63

Browse files
disable vcs on org (#1092)
* disable vcs on org * fix build error * remove negation * spec for com & enterprise * spec for com & enterprise
1 parent 630a8f2 commit 1af3f63

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

lib/travis/api/app/endpoint/authorization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Authorization < Endpoint
104104
#
105105
# * **redirect_uri**: URI to redirect to after handshake.
106106
get '/handshake/?:provider?' do
107-
method = Travis::Features.enabled_for_all?(:vcs_login) ? :vcs_handshake : :handshake
107+
method = org? ? :handshake : :vcs_handshake
108108
params[:provider] ||= 'github'
109109

110110
send(method) do |user, token, redirect_uri|

spec/unit/endpoint/authorization_spec.rb

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
end
4141

4242
describe "GET /auth/handshake" do
43+
before do
44+
ENV['TRAVIS_SITE'] = 'org'
45+
end
46+
after do
47+
ENV['TRAVIS_SITE'] = nil
48+
end
49+
4350
describe 'evil hackers messing with the state' do
4451
it 'does not succeed if state cookie mismatches' do
4552
Travis.redis.sadd('github:states', 'github-state')
@@ -50,7 +57,7 @@
5057
end
5158
end
5259

53-
describe 'evil hackers messing with redirection' do
60+
describe 'On org, evil hackers messing with redirection' do
5461
before do
5562
WebMock.stub_request(:post, "https://foobar.com/access_token_path")
5663
.to_return(status: 200, body: 'access_token=token&token_type=bearer')
@@ -109,6 +116,66 @@
109116
end
110117
end
111118

119+
describe 'On com and enterprise, evil hackers messing with redirection' do
120+
before do
121+
WebMock.stub_request(:post, "https://foobar.com/access_token_path")
122+
.to_return(status: 200, body: 'access_token=token&token_type=bearer')
123+
124+
WebMock.stub_request(:get, "https://api.github.com/user?per_page=100")
125+
.to_return(
126+
status: 200,
127+
body: JSON.dump(name: 'Piotr Sarnacki', login: 'drogus', gravatar_id: '123', id: 456, foo: 'bar'), headers: {'X-OAuth-Scopes' => 'repo, user, new_scope'}
128+
)
129+
130+
cookie_jar['travis.state-github'] = state
131+
Travis.redis.sadd('github:states', state)
132+
ENV['TRAVIS_SITE'] = nil
133+
end
134+
135+
after do
136+
Travis.redis.srem('github:states', state)
137+
end
138+
139+
context 'when redirect uri is correct' do
140+
let(:state) { 'github-state:::https://travis-ci.com/?any=params' }
141+
142+
it 'it does allow redirect' do
143+
response = get "/auth/handshake/github?code=1234&state=#{URI.encode(state)}"
144+
expect(response.status).to eq(200)
145+
end
146+
end
147+
148+
context 'when redirect uri is not allowed' do
149+
let(:state) { 'github-state:::https://dark-corner-of-web.com/' }
150+
151+
it 'does not allow redirect' do
152+
response = get "/auth/handshake/github?code=1234&state=#{URI.encode(state)}"
153+
expect(response.status).to eq(401)
154+
expect(response.body).to eq("target URI not allowed")
155+
end
156+
end
157+
158+
context 'when script tag is injected into redirect uri' do
159+
let(:state) { 'github-state:::https://travis-ci.com/<sCrIpt' }
160+
161+
it 'does not allow redirect' do
162+
response = get "/auth/handshake/github?code=1234&state=#{URI.encode(state)}"
163+
expect(response.status).to eq(401)
164+
expect(response.body).to eq("target URI not allowed")
165+
end
166+
end
167+
168+
context 'when onerror tag is injected into redirect uri' do
169+
let(:state) { 'github-state:::https://travis-ci.com/<img% src="" onerror="badcode()"' }
170+
171+
it 'does not allow redirect' do
172+
response = get "/auth/handshake/github?code=1234&state=#{URI.encode(state)}"
173+
expect(response.status).to eq(401)
174+
expect(response.body).to eq("target URI not allowed")
175+
end
176+
end
177+
end
178+
112179
describe 'with insufficient oauth permissions' do
113180
before do
114181
Travis.redis.sadd('github:states', 'github-state')

0 commit comments

Comments
 (0)