Skip to content

Commit aca41a7

Browse files
authored
[WRSAT-473] Encrypt the SSN column (#198)
1 parent a889a4b commit aca41a7

File tree

8 files changed

+32
-3
lines changed

8 files changed

+32
-3
lines changed

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ COPY . .
6161
RUN bundle exec bootsnap precompile app/ lib/
6262

6363
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
64-
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
65-
64+
RUN \
65+
SECRET_KEY_BASE_DUMMY=1 \
66+
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=dummy \
67+
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=dummy \
68+
ACTIVE_RECORD_DERIVATION_SALT_KEY=dummy \
69+
./bin/rails assets:precompile
6670

6771
# Final stage for app image
6872
FROM base

app/models/screener.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Screener < ApplicationRecord
44
has_one :nc_screener, dependent: :destroy
55
attr_accessor :email_confirmation
66
attr_accessor :from_download_form
7+
encrypts :ssn_last_four
78
enum :is_american_indian, {unfilled: 0, yes: 1, no: 2}, prefix: true
89
enum :is_working, {unfilled: 0, yes: 1, no: 2}, prefix: true
910
enum :is_volunteer, {unfilled: 0, yes: 1, no: 2}, prefix: true

app/views/download_form/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<% unless has_email %>
1313
<div>
14-
<%= link_to(generate_pdf_path, class: "button button--primary spacing-below-0") do %>
14+
<%= link_to(generate_pdf_path, class: "button button--primary spacing-below-0", target: "_blank") do %>
1515
<i class="button__icon--left icon-get_app"></i>
1616
<%= t("views.download_form.edit.download_form") %>
1717
<% end %>

config/environments/development.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@
7575

7676
config.hosts << "development.wrsat.codeforamerica.app"
7777
config.hosts << /.*\.development\.wrsat\.codeforamerica\.app$/
78+
79+
config.active_record.encryption.primary_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY", "edSK9biPXNhUVP17nNj6xPhtOeB84FAX")
80+
config.active_record.encryption.deterministic_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY", "eVrXlDsnIP0iSDNuxeub906KGv7SOU6j")
81+
config.active_record.encryption.key_derivation_salt = ENV.fetch("ACTIVE_RECORD_DERIVATION_SALT_KEY", "ZpsjowhMSuZXLkAgzJRXXEIIDVytGv4z")
7882
end

config/environments/production.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,8 @@
8383
#
8484
# Skip DNS rebinding protection for the default health check endpoint.
8585
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
86+
87+
config.active_record.encryption.primary_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY")
88+
config.active_record.encryption.deterministic_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY")
89+
config.active_record.encryption.key_derivation_salt = ENV.fetch("ACTIVE_RECORD_DERIVATION_SALT_KEY")
8690
end

config/environments/staging.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@
8181
#
8282
# Skip DNS rebinding protection for the default health check endpoint.
8383
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
84+
85+
config.active_record.encryption.primary_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY")
86+
config.active_record.encryption.deterministic_key = ENV.fetch("ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY")
87+
config.active_record.encryption.key_derivation_salt = ENV.fetch("ACTIVE_RECORD_DERIVATION_SALT_KEY")
8488
end

config/environments/test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@
5050

5151
# Raise error when a before_action's only/except options reference missing actions.
5252
config.action_controller.raise_on_missing_callback_actions = true
53+
54+
config.active_record.encryption.primary_key = "a" * 32
55+
config.active_record.encryption.deterministic_key = "b" * 32
56+
config.active_record.encryption.key_derivation_salt = "c" * 32
5357
end

spec/models/screener_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,4 +709,12 @@
709709
end
710710
end
711711
end
712+
713+
describe "encryption" do
714+
it "stores ssn_last_four as encrypted data" do
715+
screener = create(:screener, ssn_last_four: "4567")
716+
expect(screener.encrypted_attribute?(:ssn_last_four)).to eq true
717+
expect(screener.ssn_last_four).to eq "4567"
718+
end
719+
end
712720
end

0 commit comments

Comments
 (0)