Load Javascript U2F library selectively.
1. Only on supported Chrome versions 2. Mainly, this lets us simplify the javascript-based U2F check to `window.u2f`, where `window.u2f` can either be loaded from the GitLab server (for Chrome) or from the Firefox extension. 3. This is a better way to provide browser detection for U2F.
This commit is contained in:
parent
df49492fc0
commit
4b33c4c6d1
10 changed files with 18 additions and 22 deletions
|
@ -16,6 +16,7 @@ v 8.10.0 (unreleased)
|
||||||
- Make images fit to the size of the viewport !4810
|
- Make images fit to the size of the viewport !4810
|
||||||
- Fix check for New Branch button on Issue page !4630 (winniehell)
|
- Fix check for New Branch button on Issue page !4630 (winniehell)
|
||||||
- Fix MR-auto-close text added to description. !4836
|
- Fix MR-auto-close text added to description. !4836
|
||||||
|
- Support U2F devices in Firefox. !5177
|
||||||
- Fix issue, preventing users w/o push access to sort tags !5105 (redetection)
|
- Fix issue, preventing users w/o push access to sort tags !5105 (redetection)
|
||||||
- Add Spring EmojiOne updates.
|
- Add Spring EmojiOne updates.
|
||||||
- Add syntax for multiline blockquote using `>>>` fence !3954
|
- Add syntax for multiline blockquote using `>>>` fence !3954
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
#= require_directory ./u2f
|
#= require_directory ./u2f
|
||||||
#= require_directory .
|
#= require_directory .
|
||||||
#= require fuzzaldrin-plus
|
#= require fuzzaldrin-plus
|
||||||
#= require u2f
|
|
||||||
|
|
||||||
window.slugify = (text) ->
|
window.slugify = (text) ->
|
||||||
text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase()
|
text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase()
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
# Helper class for U2F (universal 2nd factor) device registration and authentication.
|
|
||||||
|
|
||||||
class @U2FUtil
|
class @U2FUtil
|
||||||
@isU2FSupported: ->
|
@isU2FSupported: ->
|
||||||
if @testMode
|
window.u2f
|
||||||
true
|
|
||||||
else
|
|
||||||
gon.u2f.browser_supports_u2f
|
|
||||||
|
|
||||||
@enableTestMode: ->
|
|
||||||
@testMode = true
|
|
||||||
|
|
||||||
<% if Rails.env.test? %>
|
|
||||||
U2FUtil.enableTestMode();
|
|
||||||
<% end %>
|
|
||||||
|
|
|
@ -344,10 +344,6 @@ class ApplicationController < ActionController::Base
|
||||||
session[:skip_tfa] && session[:skip_tfa] > Time.current
|
session[:skip_tfa] && session[:skip_tfa] > Time.current
|
||||||
end
|
end
|
||||||
|
|
||||||
def browser_supports_u2f?
|
|
||||||
browser.chrome? && browser.version.to_i >= 41 && !browser.device.mobile?
|
|
||||||
end
|
|
||||||
|
|
||||||
def redirect_to_home_page_url?
|
def redirect_to_home_page_url?
|
||||||
# If user is not signed-in and tries to access root_path - redirect him to landing page
|
# If user is not signed-in and tries to access root_path - redirect him to landing page
|
||||||
# Don't redirect to the default URL to prevent endless redirections
|
# Don't redirect to the default URL to prevent endless redirections
|
||||||
|
|
|
@ -80,8 +80,7 @@ module AuthenticatesWithTwoFactor
|
||||||
challenges = sign_requests.map(&:challenge)
|
challenges = sign_requests.map(&:challenge)
|
||||||
session[:challenges] = challenges
|
session[:challenges] = challenges
|
||||||
gon.push(u2f: { challenges: challenges, app_id: u2f_app_id,
|
gon.push(u2f: { challenges: challenges, app_id: u2f_app_id,
|
||||||
sign_requests: sign_requests,
|
sign_requests: sign_requests })
|
||||||
browser_supports_u2f: browser_supports_u2f? })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,7 +100,6 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
|
||||||
|
|
||||||
gon.push(u2f: { challenges: session[:challenges], app_id: u2f_app_id,
|
gon.push(u2f: { challenges: session[:challenges], app_id: u2f_app_id,
|
||||||
register_requests: registration_requests,
|
register_requests: registration_requests,
|
||||||
sign_requests: sign_requests,
|
sign_requests: sign_requests })
|
||||||
browser_supports_u2f: browser_supports_u2f? })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
5
app/helpers/u2f_helper.rb
Normal file
5
app/helpers/u2f_helper.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module U2fHelper
|
||||||
|
def inject_u2f_api?
|
||||||
|
browser.chrome? && browser.version.to_i >= 41 && !browser.device.mobile?
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,7 @@
|
||||||
|
- content_for :page_specific_javascripts do
|
||||||
|
- if inject_u2f_api?
|
||||||
|
= page_specific_javascript_tag('u2f.js')
|
||||||
|
|
||||||
%div
|
%div
|
||||||
.login-box
|
.login-box
|
||||||
.login-heading
|
.login-heading
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
- header_title "Two-Factor Authentication", profile_two_factor_auth_path
|
- header_title "Two-Factor Authentication", profile_two_factor_auth_path
|
||||||
= render 'profiles/head'
|
= render 'profiles/head'
|
||||||
|
|
||||||
|
- content_for :page_specific_javascripts do
|
||||||
|
- if inject_u2f_api?
|
||||||
|
= page_specific_javascript_tag('u2f.js')
|
||||||
|
|
||||||
.row.prepend-top-default
|
.row.prepend-top-default
|
||||||
.col-lg-3
|
.col-lg-3
|
||||||
%h4.prepend-top-0
|
%h4.prepend-top-0
|
||||||
|
|
|
@ -87,6 +87,7 @@ module Gitlab
|
||||||
config.assets.precompile << "profile/application.js"
|
config.assets.precompile << "profile/application.js"
|
||||||
config.assets.precompile << "lib/utils/*.js"
|
config.assets.precompile << "lib/utils/*.js"
|
||||||
config.assets.precompile << "lib/*.js"
|
config.assets.precompile << "lib/*.js"
|
||||||
|
config.assets.precompile << "u2f.js"
|
||||||
|
|
||||||
# Version of your assets, change this if you want to expire all your assets
|
# Version of your assets, change this if you want to expire all your assets
|
||||||
config.assets.version = '1.0'
|
config.assets.version = '1.0'
|
||||||
|
|
Loading…
Reference in a new issue