Recaptcha на RoR не работает, когда включен UFW - PullRequest
0 голосов
/ 28 апреля 2020

У меня есть Rails 6 с гемами devise и recaptcha. Сервер на nginx + пассажир. Проект работает в производственном режиме.

У меня включена регистрация для регистрации:

def check_captcha
  unless verify_recaptcha
    self.resource = resource_class.new sign_up_params
    resource.validate 
    set_minimum_password_length
    respond_with_navigational(resource) { render :new }
  end 
end

Работает нормально, но только когда брандмауэр (ufw) отключен. Когда я включаю его и пытаюсь зарегистрироваться, я получаю сообщение, что я не заполнил капчу. Разрешены порты DNS, http и https. Мой статус UFW:

Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere                  
53 (DNS)                   ALLOW IN    Anywhere                  
443/tcp                    ALLOW IN    Anywhere                  
80/tcp                     ALLOW IN    Anywhere                  
5432                       ALLOW IN    Anywhere                  
443                        ALLOW IN    Anywhere                  
80                         ALLOW IN    Anywhere                  
53                         ALLOW IN    Anywhere    

Я также не вижу ничего в журналах Rails:

I, [2020-04-28T11:00:40.700773 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b] Started POST "/users" for N.N.N.N at 2020-04-28 11:00:40 +0300
I, [2020-04-28T11:00:40.702106 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b] Processing by Users::RegistrationsController#create as HTML
I, [2020-04-28T11:00:40.702208 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b]   Parameters: {"authenticity_token"=>"3HpUeJwnKmPUGFQlS1nGet51aBDs0+viFoALSz/Xrh8ZjH1Js1RY2P0ln41E5naIGngkH4r+TFb87RNcnVn47g==", "user"=>{"email"=>"tmp3@tmp3.ru", "name"=>"tmp3@tmp3.ru", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "g-recaptcha-response"=>"03AGdBq26sLAjqOfpXX0W1MTIvyqTsyVndHBrADT2j1e7I0entSUKa09F_y0FjSn4SHUB56VhBZudlur8hmyHOy8IIC8JNrxSitXNrKS9LUPW5nmDzXOojfePXLu9lQGaY7K4btItcsbaOjWNYpMyHvGHgJpuJJicx9JeLwd-Mq10_6pDGTKHCI7GdNpRISh62ndmiLAD7yzWAZ8rMqRzgs_I4Zhv6gZ8PuqyFY9PUMlcIkeungWiHisNV7cuQBFfRFUqHMOSg056XFipd4cwFRgeManknKDq-nLFrPwPh7RZ3_l8cYStCR1cD1BaMNNZTyfo9gI4N-iis3vbt6nG1_2YC1LWl4wortH5Ii5lO8Nbbzb4p3cVgOImSpnOcfdFbAYvpV4We2h5y", "commit"=>"Регистрация"}
D, [2020-04-28T11:00:43.915005 #2164] DEBUG -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b]   [1m[36mUser Exists? (0.8ms)[0m  [1m[34mSELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2[0m  [["email", "tmp3@tmp3.ru"], ["LIMIT", 1]]
I, [2020-04-28T11:00:43.917986 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b]   Rendering devise/registrations/new.html.haml within layouts/application
I, [2020-04-28T11:00:43.919602 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b]   Rendered devise/shared/_error_messages.html.haml (Duration: 0.8ms | Allocations: 294)
I, [2020-04-28T11:00:43.923336 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b]   Rendered devise/registrations/new.html.haml within layouts/application (Duration: 5.2ms | Allocations: 1994)
I, [2020-04-28T11:00:43.926216 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b] Filter chain halted as :check_captcha rendered or redirected
I, [2020-04-28T11:00:43.926387 #2164]  INFO -- : [39400f1e-d1b7-4bb6-875d-fb4fb3d7679b] Completed 200 OK in 3224ms (Views: 8.7ms | ActiveRecord: 0.8ms | Allocations: 5658)
I, [2020-04-28T11:07:08.515910 #2164]  INFO -- : [03e8a57d-ffe9-4b82-a668-375774b43c0c] Started GET "/users/sign_up" for N.N.N.N  at 2020-04-28 11:07:08 +0300

Как я уже сказал, когда я отключаю брандмауэр, все работает нормально.

...