diff --git a/app/controllers/admin/forms_controller.rb b/app/controllers/admin/forms_controller.rb
index e82cff51a..15f716482 100644
--- a/app/controllers/admin/forms_controller.rb
+++ b/app/controllers/admin/forms_controller.rb
@@ -474,6 +474,7 @@ def form_params
:department,
:bureau,
:load_css,
+ :verify_csrf,
:ui_truncate_text_responses,
:question_text_01,
:question_text_02,
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d91c8054f..d92807c7f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -254,6 +254,12 @@ def paginate(scope, default_per_page = 20)
}, collection]
end
+ # customized response for `#verify_authenticity_token`
+ def handle_unverified_request
+ render json: { messages: { submission: ["invalid CSRF authenticity token"] } }, status: :unprocessable_entity
+ end
+
+
private
# For Devise
diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb
index bc7290278..dcbef51b7 100644
--- a/app/controllers/submissions_controller.rb
+++ b/app/controllers/submissions_controller.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
class SubmissionsController < ApplicationController
- protect_from_forgery only: []
before_action :set_form, only: %i[new create]
+ append_before_action :verify_authenticity_token, if: :form_requires_verification
layout 'public', only: :new
@@ -141,4 +141,8 @@ def submission_params
permitted_fields << %i[language location_code referer page fba_directive]
params.require(:submission).permit(permitted_fields)
end
+
+ def form_requires_verification
+ @form.verify_csrf?
+ end
end
diff --git a/app/views/admin/forms/delivery.html.erb b/app/views/admin/forms/delivery.html.erb
index 1af8dd80a..c9dc0dbba 100644
--- a/app/views/admin/forms/delivery.html.erb
+++ b/app/views/admin/forms/delivery.html.erb
@@ -90,6 +90,14 @@
<%= render 'components/whitelist_options', f: f %>
+
<%= f.submit (@form.persisted? ? "Update Form" : "Create Form"), class: "usa-button" %>
diff --git a/app/views/admin/forms/example.html.erb b/app/views/admin/forms/example.html.erb index e0ac85bb5..62349411f 100644 --- a/app/views/admin/forms/example.html.erb +++ b/app/views/admin/forms/example.html.erb @@ -77,6 +77,6 @@ <% end %> - +