未注册的操作(通过自定义模块)导致检测到 XSRF 攻击错误

Unregistered action (via custom module) leads to XSRF Attack Detected error

在 SugarCRM 8.0.1 中,我正在尝试使一个新的、未注册的操作生效。

该操作是一个表单,已添加到我的自定义模块中。我试图通过以下方式从自身获取它,以便在提交表单时,表单数据被发送回自身(也就是 action link 返回到表单所在的同一页面上):

<form method="POST" name="ConfigureSettings" action="#bwc/index.php?module=CustomModule&action=newAction">

SugarCRM Support's Troubleshooting Cross-Site Forgery Messages的基础上,增加一个动作的方法如下:

To add the unregistered action as an allowed action (e.g. custom module), add the following line of code to the config_override.php file:

$sugar_config['http_referer']['actions'] =array( 'index', 'ListView', 'DetailView', 'EditView', 'oauth', 'authorize', 'Authenticate', 'Login', 'SupportPortal', 'bad_action' );

单独这样做是行不通的,尝试保存我的更改或取消编辑我的表单仍然会导致相同的错误:

Cross Site Request Forgery (XSRF) Attack Detected
Form authentication failure (CustomModule -> newAction). Contact your administrator.

我是否必须在 $sugar_config 中编辑某些内容以将其与我的具体操作相关联?我尝试将 bad_action 更改为 newAction,但无济于事。


找到了解决方法 ,它只会记录错误而不是中止操作,它证明我的表单工作正常,我被引导回到同一页面并且表单已更新.

不幸的是,这不是我的问题的解决方案,因为这对于生产实例来说是不安全的,而且我仍然不确定为什么我首先会收到错误,因为我没有重定向到外部站点实例的。

原来HTML表单需要从PHP文件中分离出来,方法是使用模板文件和Smarty标签替换模板文件中PHP的实例。

执行了上述操作,然后将 here 中提到的 {sugar_csrf_form_token} 包含在模板文件中,现在它可以正常工作了。