Skip to content

A platform for community discussion. Free, open, simple.

SECURITY: Gate staged user fields on email verification

Isaac Janzen6365ac20dcae
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 1f9337ffdf5..5df6cf2ff79 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -566,11 +566,13 @@ class InvitesController < ApplicationController
# Show email if the user already authenticated their email
different_external_email = false
+ email_verified_by_authentication = false
if server_session[:authentication]
auth_result = Auth::Result.from_session_data(server_session[:authentication], user: nil)
if invite.email == auth_result.email
email = invite.email
+ email_verified_by_authentication = auth_result.email_valid
else
different_external_email = true
end
@@ -599,7 +601,8 @@ class InvitesController < ApplicationController
info[:different_external_email] = true if different_external_email
- if staged_user = User.where(staged: true).with_email(invite.email).first
+ if (email_verified_by_link || email_verified_by_authentication) &&
+ (staged_user = User.where(staged: true).with_email(invite.email).first)
info[:username] = staged_user.username
info[:user_fields] = staged_user.user_fields
end
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index ac1a2dfb51f..dd8708409b2 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -58,13 +58,62 @@ RSpec.describe InvitesController do
end
end
- it "shows default user fields" do
+ it "does not expose staged user fields without email verification" do
user_field = Fabricate(:user_field)
staged_user = Fabricate(:user, staged: true, email: invite.email)
staged_user.set_user_field(user_field.id, "some value")
staged_user.save_custom_fields
get "/invites/#{invite.invite_key}"
+ expect(response.body).to have_tag("div#data-preloaded") do |element|
+ json = JSON.parse(element.current_scope.attribute("data-preloaded").value)
+ invite_info = JSON.parse(json["invite_info"])
+ expect(invite_info["username"]).not_to eq(staged_user.username)
+ expect(invite_info["user_fields"]).to be_nil
+ end
+ end
+
+ it "does not expose staged user fields when authentication email is unverified" do
+ user_field = Fabricate(:user_field)
+ staged_user = Fabricate(:user, staged: true, email: invite.email)
+ staged_user.set_user_field(user_field.id, "some value")
+ staged_user.save_custom_fields
+
+ server_session[:authentication] = { email: invite.email, email_valid: false }
+
+ get "/invites/#{invite.invite_key}"
+ expect(response.body).to have_tag("div#data-preloaded") do |element|
+ json = JSON.parse(element.current_scope.attribute("data-preloaded").value)
+ invite_info = JSON.parse(json["invite_info"])
+ expect(invite_info["email"]).to eq(invite.email)
+ expect(invite_info["user_fields"]).to be_nil
+ end
+ end
+
+ it "shows staged user fields when authentication email is verified" do
+ user_field = Fabricate(:user_field)
+ staged_user = Fabricate(:user, staged: true, email: invite.email)
+ staged_user.set_user_field(user_field.id, "some value")
+ staged_user.save_custom_fields
+
+ server_session[:authentication] = { email: invite.email, email_valid: true }
+
+ get "/invites/#{invite.invite_key}"
+ expect(response.body).to have_tag("div#data-preloaded") do |element|
+ json = JSON.parse(element.current_scope.attribute("data-preloaded").value)
+ invite_info = JSON.parse(json["invite_info"])
+ expect(invite_info["username"]).to eq(staged_user.username)
+ expect(invite_info["user_fields"][user_field.id.to_s]).to eq("some value")
+ end
+ end
+
+ it "shows staged user fields when email is verified by link token" do
+ user_field = Fabricate(:user_field)
+ staged_user = Fabricate(:user, staged: true, email: invite.email)
+ staged_user.set_user_field(user_field.id, "some value")
+ staged_user.save_custom_fields
+
+ get "/invites/#{invite.invite_key}?t=#{invite.email_token}"
expect(response.body).to have_tag("div#data-preloaded") do |element|
json = JSON.parse(element.current_scope.attribute("data-preloaded").value)
invite_info = JSON.parse(json["invite_info"])