gpt4 book ai didi

php - 无法模拟 HTTP 302 响应

转载 作者:可可西里 更新时间:2023-11-01 16:44:13 26 4
gpt4 key购买 nike

我正在尝试将 PagSeguro(一种支付网关 - 巴西版的 PayPal)整合到我的网站中。客户完成 PagSeguro 后,他们将数据(通过 POST)发送到我指定的函数。但是,我没有收到 POST。在完成我能想到的所有故障排除后,我联系了 PagSeguro。他们说他们的日志表明 POST 正常发送,但他们收到 HTTP 302 响应。

为了找出发生这种情况的原因,我创建了一个带有隐藏值的表单来模拟向我的函数发送 POST。我将此表单放在不同的域下,以防万一它与此有关。每次我从我的模拟表单发送 POST 时,我都会收到 HTTP 200 响应,并且我的日志表明已收到 POST。

PagSeguro 怎么可能收到与我的模拟不同的响应?它可能与服务器有关还是与我的脚本有关?

这是应该接收 POST 的函数(使用 CodeIgniter):

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);
}
}

安全更新:

发帖后,我很快意识到我正在对黑客尝试敞开心扉。该函数必须是公开的,因此任何知道该函数名称的人都可以访问它并发布“模拟”以获得即时验证。然后他们可以传递他们想要的任何数据。

我将函数的名称更改为无法猜测的名称,并且在不处于生产模式时,我禁用了模拟选项。

最佳答案

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

我知道这种情况在未来 500 年内可能不会再次发生,但如果不禁用接收 POST 的功能,诸如 CSRF 安全之类的东西可能会导致支付网关等问题。

关于php - 无法模拟 HTTP 302 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13529750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com