Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
SECURITY: Check for email verification status during login (#92)
This commit also includes a migration which will deactivate any users with existing connections to unverified-email Patreon accounts. They will be asked to verify their email on their next login.
- Loading branch information
1 parent
0c88b9b
commit 846d012
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
db/post_migrate/20221025153038_deactivate_unverified_email_patreon_accounts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class DeactivateUnverifiedEmailPatreonAccounts < ActiveRecord::Migration[6.1] | ||
| def up | ||
| execute <<~SQL | ||
| UPDATE users SET active = false | ||
| WHERE users.id IN ( | ||
| SELECT user_id FROM user_associated_accounts | ||
| WHERE provider_name = 'patreon' | ||
| AND extra -> 'raw_info' -> 'data' -> 'attributes' ->> 'is_email_verified' = 'false' | ||
| ) | ||
| SQL | ||
| end | ||
|
|
||
| def down | ||
| # noop | ||
| end | ||
| end |
47 changes: 47 additions & 0 deletions
47
db/post_migrate/20221026043851_delete_unverified_patreon_user_info.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class DeleteUnverifiedPatreonUserInfo < ActiveRecord::Migration[6.1] | ||
| def up | ||
| execute <<~SQL | ||
| DELETE FROM user_auth_tokens | ||
| WHERE user_id IN ( | ||
| SELECT user_id | ||
| FROM user_associated_accounts | ||
| WHERE provider_name = 'patreon' | ||
| AND COALESCE(JSON_EXTRACT_PATH(extra::json, 'raw_info', 'data', 'attributes', 'is_email_verified')::text, 'false') <> 'true' | ||
| ) | ||
| SQL | ||
|
|
||
| execute <<~SQL | ||
| UPDATE user_api_keys | ||
| SET revoked_at = NOW() | ||
| WHERE user_id IN ( | ||
| SELECT user_id | ||
| FROM user_associated_accounts | ||
| WHERE provider_name = 'patreon' | ||
| AND COALESCE(JSON_EXTRACT_PATH(extra::json, 'raw_info', 'data', 'attributes', 'is_email_verified')::text, 'false') <> 'true' | ||
| ) | ||
| SQL | ||
|
|
||
| execute <<~SQL | ||
| UPDATE api_keys | ||
| SET revoked_at = NOW() | ||
| WHERE created_by_id IN ( | ||
| SELECT user_id | ||
| FROM user_associated_accounts | ||
| WHERE provider_name = 'patreon' | ||
| AND COALESCE(JSON_EXTRACT_PATH(extra::json, 'raw_info', 'data', 'attributes', 'is_email_verified')::text, 'false') <> 'true' | ||
| ) | ||
| SQL | ||
|
|
||
| execute <<~SQL | ||
| DELETE FROM user_associated_accounts | ||
| WHERE provider_name = 'patreon' | ||
| AND COALESCE(JSON_EXTRACT_PATH(extra::json, 'raw_info', 'data', 'attributes', 'is_email_verified')::text, 'false') <> 'true' | ||
| SQL | ||
| end | ||
|
|
||
| def down | ||
| # noop | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters