diff options
author | Cindy Pallares <cindy@gitlab.com> | 2018-11-28 22:53:48 +0000 |
---|---|---|
committer | Cindy Pallares <cindy@gitlab.com> | 2018-11-28 19:14:15 -0500 |
commit | 5736d6606ad7c6d729baa6c4ef789a47ada4ceda (patch) | |
tree | 1ae542a04e8782f61a592e3bceeacc087639a1e5 /db/post_migrate | |
parent | c0e5d9afee57745a79c072b0f57fdcbe164312da (diff) | |
download | gitlab-ce-5736d6606ad7c6d729baa6c4ef789a47ada4ceda.tar.gz |
Merge branch 'security-fix-uri-xss-applications' into 'master'
[master] Resolve "Reflected XSS in OAuth Authorize window due to redirect_uri allowing arbitrary protocols"
See merge request gitlab/gitlabhq!2572
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb b/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb new file mode 100644 index 00000000000..ff5510e8eb7 --- /dev/null +++ b/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class MigrateForbiddenRedirectUris < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + FORBIDDEN_SCHEMES = %w[data:// vbscript:// javascript://] + NEW_URI = 'http://forbidden-scheme-has-been-overwritten' + + disable_ddl_transaction! + + def up + update_forbidden_uris(:oauth_applications) + update_forbidden_uris(:oauth_access_grants) + end + + def down + # noop + end + + private + + def update_forbidden_uris(table_name) + update_column_in_batches(table_name, :redirect_uri, NEW_URI) do |table, query| + where_clause = FORBIDDEN_SCHEMES.map do |scheme| + table[:redirect_uri].matches("#{scheme}%") + end.inject(&:or) + + query.where(where_clause) + end + end +end |