2012-11-23 113 views
2

我试图将PagSeguro(支付网关 - 巴西版本的PayPal)并入我的网站。客户完成PagSeguro后,他们将数据(通过POST)发送到我指定的功能。但是,我没有收到POST。在完成所有我能想到的故障排除之后,我联系了PagSeguro。他们说他们的日志表明POST正在正常发送,但他们正在接收HTTP 302响应。无法模拟HTTP 302响应

为了弄清楚为什么发生这种情况,我创建了隐藏值的形式来模拟发送POST到我的功能。我把这个表格放在不同的域名下,以防与它有关。每次我从模拟表单发送POST时,都会收到一个HTTP 200响应,而我的日志表明POST已收到。

PagSeguro如何接收与我的模拟不同的响应?它可能与服务器有关或与我的脚本有关吗?

下面是函数(使用笨)其他应当接受POST:

function pagseguro_retorno(){ 
    if (count($_POST) == 0) { 
     return FALSE; 
    } 
    $msg = 'POST RECEIVED'; 
    $simulate = $this->input->post('Simulate'); 
    if (! empty($simulate)){ 
     $result = 'VERIFICADO'; 
     $msg .= ' FROM SIMULATOR'; 
    } else { 
     $this->load->library(PagSeguroNpi); 
     $result = $this->PagSeguroNpi->notificationPost(); 
    } 
    $this->log($msg); 
    if ($result == "VERIFICADO") { 
     $id = $this->input->post('Referencia');//cart id 
     $this->load->model('transacao_model'); 
     $trans_row = $this->transacao_model->get_transaction($id); 
     if (! is_object($trans_row)){ 
      //LOAD NEW TRANSACTION 
      if (! $this->new_transaction($id)){ 
       $notice = "Unable to load new transaction</p><p>"; 
       $this->log($notice); 
       $notice .= '<pre>'.print_r($_POST, TRUE).'</pre>'; 
       $this->email_notice($notice); 
      } 
     } 
     $this->load->model('carrinho_model'); 
     if($_POST['StatusTransacao'] == 'Aprovado'){ 
      $status = 'apr'; 
     }elseif($_POST['StatusTransacao'] == 'Em Análise'){ 
      $status = 'anl'; 
     }elseif($_POST['StatusTransacao'] == 'Aguardando Pagto'){ 
      $status = 'wtg'; 
     }elseif($_POST['StatusTransacao'] == 'Completo'){ 
      $status = 'cmp'; 
      //nothing more happens here - client must click on 'mark as shipped' before cart is removed and history data is loaded 
     }elseif($_POST['StatusTransacao'] == 'Cancelado'){ 
      //reshelf - don't set $status, because the cart's about to be destroyed 
      $this->carrinho_model->reshelf(array($id)); 
     } 
     if (isset($status)){ 
      $this->carrinho_model->update_carrinho($id, array('status' => $status)); 
     } 
    } else if ($result == "FALSO") { 
     $notice = "PagSeguro return was invalid."; 
     $this->log($notice); 
     $notice .= '<pre>'.print_r($_POST, TRUE).'</pre>'; 
     $this->email_notice($notice); 
    } else { 
     $notice = "Error in PagSeguro request"; 
     $this->log($notice); 
     $notice .= '<pre>'.print_r($_POST, TRUE).'</pre>'; 
     $this->email_notice($notice); 
    } 
} 

安全更新:

张贴后,我很快就意识到,我是开自己交给了黑客攻击。该功能必须是公开的,所以任何知道该功能名称的人都可以访问它并发布“模拟”以便立即进行验证。然后他们可以传递他们想要的任何数据。

我改变了函数的名字的东西,是不可能的猜测,而当没有在生产模式,我已禁用的模拟选项。

+0

您是否尝试过记录请求以确保PagSeguro实际上正在请求正确的页面?最好确定一下。 –

+0

我不知道你的意思是如何记录请求,但毫无疑问,他们正在请求正确的页面。我已经多次验证了该网址。 –

+0

我的意思是在Apache日志,谷歌分析,你的PHP应用程序,无论你想要的。使用HTTP_REFERER,请求的URL和GET/POST参数将每个请求写入日志文件,以确保它是正确的。如果你* 100%肯定*他们正在请求正确的URL,正确的参数,然后从来没有 - 但我会犯错谨慎的一面,只是确保。 –

回答

0

的问题是,我的CSRF保护导致重定向时使用POST不发送正确的CSRF代码。我的模拟器正在工作,因为我复制了我在该网站上制作的动态模拟器生成的HTML。然后,我粘贴HTML创建一个静态模拟器,并将其放在不同的URL下。除了HTML之外,我还无意中粘贴了CSRF代码。静态模拟器工作正常,直到代码过期。几次之后,我放弃了使用它,所以直到今天我才发现它不再有效。

我知道这个确切的情况可能不会再在接下来的500年内陆续发生,但如果不是因为函数接收POST禁用之类的东西CSRF安全性可能会导致类似的东西支付网关的问题。