Commit 0ecaed69 authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot

Merge branch 'security-477-enforce-configured-scopes' into 'master'

Enforce configured scopes for OAuth applications

See merge request gitlab-org/security/gitlab!1708
parents a272bd39 31cc65d7
......@@ -51,6 +51,11 @@ Doorkeeper.configure do
# Issue access tokens with refresh token (disabled by default)
use_refresh_token
# Forbids creating/updating applications with arbitrary scopes that are
# not in configuration, i.e. `default_scopes` or `optional_scopes`.
# (disabled by default)
enforce_configured_scopes
# Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
# by default in non-development environments). OAuth2 delegates security in
# communication to the HTTPS protocol so it is wise to keep this enabled.
......
......@@ -98,6 +98,19 @@ RSpec.describe Oauth::ApplicationsController do
end
describe 'POST #create' do
let(:oauth_params) do
{
doorkeeper_application: {
name: 'foo',
redirect_uri: redirect_uri,
scopes: scopes
}
}
end
let(:redirect_uri) { 'http://example.org' }
let(:scopes) { ['api'] }
subject { post :create, params: oauth_params }
it 'creates an application' do
......@@ -116,38 +129,42 @@ RSpec.describe Oauth::ApplicationsController do
expect(response).to redirect_to(profile_path)
end
context 'redirect_uri' do
context 'when redirect_uri is invalid' do
let(:redirect_uri) { 'javascript://alert()' }
render_views
it 'shows an error for a forbidden URI' do
invalid_uri_params = {
doorkeeper_application: {
name: 'foo',
redirect_uri: 'javascript://alert()',
scopes: ['api']
}
}
post :create, params: invalid_uri_params
subject
expect(response.body).to include 'Redirect URI is forbidden by the server'
expect(response).to render_template('doorkeeper/applications/index')
end
end
context 'when scopes are not present' do
let(:scopes) { [] }
render_views
it 'shows an error for blank scopes' do
invalid_uri_params = {
doorkeeper_application: {
name: 'foo',
redirect_uri: 'http://example.org'
}
}
post :create, params: invalid_uri_params
subject
expect(response.body).to include 'Scopes can't be blank'
expect(response).to render_template('doorkeeper/applications/index')
end
end
context 'when scopes are invalid' do
let(:scopes) { %w(api foo) }
render_views
it 'shows an error for invalid scopes' do
subject
expect(response.body).to include 'Scopes doesn't match configured on the server.'
expect(response).to render_template('doorkeeper/applications/index')
end
end
......@@ -185,14 +202,4 @@ RSpec.describe Oauth::ApplicationsController do
def disable_user_oauth
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:user_oauth_applications?).and_return(false)
end
def oauth_params
{
doorkeeper_application: {
name: 'foo',
redirect_uri: 'http://example.org',
scopes: ['api']
}
}
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment