【发布时间】:2015-09-04 17:30:49
【问题描述】:
我是一个sugarCRM 实例的管理员,我在heroku 上有一个rails 应用程序。如果在 SugarCRM 中添加联系人,我希望能够自动将联系人添加到 rails 应用程序。我在我的 SugarCRM 中写了一个 before_save logic_hook:
function pushConts($bean, $event, $arguments)
{
$r = new HttpRequest('http://localhost:3000/contacts/', HttpRequest::METH_POST);
$r->addPostFields(array('first_name' => $bean->first_name, 'last_name' => $bean->last_name, 'phone' => $bean->phone_mobile,'email' => $bean->email1, ));
//$r->addHeaders(array('X-CSRF-Token'=> 'testing-csrf-token');
try
{
echo $r->send()->getBody();
} catch(HttpException $ex){
SugarApplication::appendErrorMessage("<span style='color: red; font-size: 1.8em;'>Could Not Save Contact: Rails app is down.</span>");
$queryParams = array('module' => 'Contacts', 'action' => 'ListView');
SugarApplication::redirect('index.php?' . http_build_query($queryParams));
}
当我尝试按原样发送时,rails 应用程序的控制台输出是:
Started POST "/contacts/" for 127.0.0.1 at 2015-06-18 15:30:14 -0500
Processing by ContactsController#create as */*
Parameters: {"first_name"=>"contact", "last_name"=>"one", "phone"=>"(555) 555-5555", "email"=>"phone.support@example.us"}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 1ms
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
actionpack (4.2.0) lib/action_controller/metal/request_forgery_protection.rb:181:in `handle_unverified_request'
actionpack (4.2.0) lib/action_controller/metal/request_forgery_protection.rb:209:in `handle_unverified_request'
devise (3.4.1) lib/devise/controllers/helpers.rb:251:in `handle_unverified_request'
<stack trace continues>
我知道逻辑挂钩本身可以工作,因为我尝试将skip_before_filter :verify_authenticity_token 添加到我的联系人控制器,然后它按预期工作,但出于安全原因,这不是一个可行的解决方案。
正如您所看到的,我尝试发送带有标题的X-CSRF-Token,但这也不起作用。
我可以向这个逻辑挂钩或我的 rails 应用程序本身(或两者)添加什么,以便我可以将 Http 请求从我的 sugarCRM 发送到我的 rails 应用程序而不会损害(太多)安全性?
【问题讨论】:
标签: php ruby-on-rails httprequest csrf sugarcrm