Skip to content
代码片段 群组 项目
提交 36edf2f2 编辑于 作者: Bojan Marjanovic's avatar Bojan Marjanovic
浏览文件

Merge branch '376474-oauth-application-secret-prefix' into 'master'

No related branches found
No related tags found
无相关合并请求
......@@ -24,6 +24,10 @@ export const containsSensitiveToken = (message) => {
name: 'Feed Token',
regex: 'feed_token=((glft-)?[0-9a-zA-Z_-]{20}|glft-[a-h0-9]+-[0-9]+_)',
},
{
name: 'GitLab OAuth Application Secret',
regex: `gloas-[0-9a-zA-Z_-]{64}`,
},
];
for (const rule of sensitiveDataPatterns) {
......
......@@ -124,4 +124,8 @@
# 2 hours in seconds
# This is also the database default value
access_token_expires_in 7200
# Use a custom class for generating the application secret.
# https://doorkeeper.gitbook.io/guides/configuration/other-configurations#custom-application-secret-generator
application_secret_generator 'Gitlab::DoorkeeperSecretStoring::Token::UniqueApplicationToken'
end
# frozen_string_literal: true
module Gitlab
module DoorkeeperSecretStoring
module Token
class UniqueApplicationToken
# Acronym for 'GitLab OAuth Application Secret'
OAUTH_APPLICATION_SECRET_PREFIX_FORMAT = "gloas-%{token}"
# Maintains compatibility with ::Doorkeeper::OAuth::Helpers::UniqueToken
# Returns a secure random token, prefixed with a GitLab identifier.
def self.generate(*)
format(OAUTH_APPLICATION_SECRET_PREFIX_FORMAT, token: SecureRandom.hex(32))
end
end
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Oauth::ApplicationsController do
RSpec.describe Oauth::ApplicationsController, feature_category: :system_access do
let(:user) { create(:user) }
let(:application) { create(:oauth_application, owner: user) }
......@@ -86,10 +86,10 @@
it_behaves_like 'redirects to login page when the user is not signed in'
it_behaves_like 'redirects to 2fa setup page when the user requires it'
it 'returns the secret in json format' do
it 'returns the prefixed secret in json format' do
subject
expect(json_response['secret']).not_to be_nil
expect(json_response['secret']).to match(/gloas-\h{64}/)
end
context 'when renew fails' do
......@@ -153,6 +153,15 @@
expect(response).to render_template :show
end
context 'the secret' do
render_views
it 'is in the response' do
subject
expect(response.body).to match(/gloas-\h{64}/)
end
end
it 'redirects back to profile page if OAuth applications are disabled' do
disable_user_oauth
......
......@@ -28,6 +28,7 @@ describe('containsSensitiveToken', () => {
'token: feed_token=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'token: feed_token=glft-ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'token: feed_token=glft-a8cc74ccb0de004d09a968705ba49099229b288b3de43f26c473a9d8d7fb7693-1234',
'token: gloas-a8cc74ccb0de004d09a968705ba49099229b288b3de43f26c473a9d8d7fb7693',
'https://example.com/feed?feed_token=123456789_abcdefghij',
'glpat-1234567890 and feed_token=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
];
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Doorkeeper::Application, type: :model, feature_category: :system_access do
let(:application) { create(:oauth_application) }
it 'uses a prefixed secret' do
expect(application.plaintext_secret).to match(/gloas-\h{64}/)
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe OauthAccessToken do
RSpec.describe OauthAccessToken, feature_category: :system_access do
let(:app_one) { create(:oauth_application) }
let(:app_two) { create(:oauth_application) }
let(:app_three) { create(:oauth_application) }
......@@ -23,6 +23,10 @@
end
describe 'Doorkeeper secret storing' do
it 'does not have a prefix' do
expect(token.plaintext_token).not_to start_with('gl')
end
it 'stores the token in hashed format' do
expect(token.token).not_to eq(token.plaintext_token)
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册