fix(xb): reject shared and multicast cashier addresses
This commit is contained in:
1 parent
ae65f9bd00
commit
6f8c513a3e
3 files changed
+12
-1
No files matched your search
@@ -33,7 +33,8 @@ class HttpsTransport
|
||||
$records=$this->records($host);$ips=[];
|
||||
foreach($records?:[] as $r){$ip=$r['ip']??$r['ipv6']??null;if(!$ip)continue;
|
||||
if(str_starts_with(strtolower($ip),'::ffff:'))throw new RuntimeException('nonpublic_dns');
|
||||
if(!filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_NO_PRIV_RANGE|FILTER_FLAG_NO_RES_RANGE))throw new RuntimeException('nonpublic_dns');$ips[]=$ip;}
|
||||
$packed=@inet_pton($ip);$multicast=$packed!==false&&((strlen($packed)===4&&ord($packed[0])>=224)||(strlen($packed)===16&&ord($packed[0])===255));
|
||||
if(!filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_GLOBAL_RANGE)||$multicast)throw new RuntimeException('nonpublic_dns');$ips[]=$ip;}
|
||||
if(!$ips)throw new RuntimeException('dns_unavailable');
|
||||
return $ips[0];
|
||||
}
|
||||
|
||||
@@ -57,3 +57,5 @@ TeleHub已分别建立最小权限调用方:DPL xb-dpl-payment-health-prod(I
|
||||
用户指出支付商收银地址动态分配,并明确要求“调整,落实”。本次共用修改仅涉及HttpsTransport、EpayProbe、Monitor的策略指纹及payment_health配置;应用到HN/DPL,默认允许可信网关链上的动态HTTPS收银域名,不扩大为任意初始入口或内网访问,不改商户参数、订单、模型钩子和回调验签。先隔离测试动态表单/重定向、入口名单、HTTPS/私网限制、同槽不重复及下一槽解锁,再Git发布。回退设置PAYMENT_HEALTH_DYNAMIC_HANDOFFS=false并原子刷新缓存,保留原账本;回退代码同样不删除claim。真实检测沿既定6小时槽运行,不额外补单或实际付款。
|
||||
|
||||
本次功能提交XB/DPL 108fbfa79838c0e2259eb401eaafd05ea8ceac49、HN 741467eb1e5c9503a3b8c8ad0667cac8ae778811,主分支合并ad0f04b1d47ba8c99bd5dfcf5bf3ebcbbb2ffb88,均已推送并在sitejp02分别Git快进部署。共用29测试137断言、HN含品牌/管理员套餐49测试186断言通过。两站配置enabled/auto_toggle/dynamic_handoffs均true,原子配置缓存与定向OPcache更新完成;主页HTTP200,用户/订单/商户等业务元数据前后一致。同轮复跑均already_checked_or_review,每站每日预算仍2,未新增检测单或实际付款。下次原调度为北京时间2026-10-30 18:00,届时旧名单阻断状态可重新检测;本次不冒充新策略真实收银已通过。备份及applied.json在原私有备份根目录的dynamic-handoff/{hn,dpl}/,包含原配置缓存及原state副本;不覆盖当前账本。已完成服务器侧验收,未做线上页面验收。
|
||||
|
||||
动态下游最终公网校验补充:PHP ^8.2原NO_PRIV_RANGE/NO_RES_RANGE会放过CGNAT共享网段及多播;现使用GLOBAL_RANGE并明确拒绝IPv4/IPv6多播及IPv4映射IPv6,隔离测试覆盖100.64.0.1、224.0.0.1、169.254.169.254、ff02::1、::ffff:127.0.0.1,以及正常公网地址。不发真实网络请求来测试这些内部目标。
|
||||
@@ -117,6 +117,14 @@ class PaymentHealthTest extends TestCase
|
||||
$t=new class extends HttpsTransport {public function check(string $url):array{return $this->endpoint($url,true);}protected function records(string $host):array{return [['ip'=>'127.0.0.1']];}};
|
||||
try{$t->check('https://cashier.example.invalid/pay');$this->fail('Private DNS allowed');}catch(\RuntimeException $e){$this->assertSame('nonpublic_dns',$e->getMessage());}
|
||||
}
|
||||
public function test_dns_shared_and_multicast_ranges_are_not_public_cashiers():void
|
||||
{
|
||||
$t=new class extends HttpsTransport {public array $answers=[];public function check():array{return $this->endpoint('https://cashier.example.invalid/pay',true);}protected function records(string $host):array{return $this->answers;}};
|
||||
foreach(['100.64.0.1','224.0.0.1','169.254.169.254','ff02::1','::ffff:127.0.0.1'] as $ip){
|
||||
$t->answers=[[str_contains($ip,':')?'ipv6':'ip'=>$ip]];try{$t->check();$this->fail('Nonpublic destination allowed');}catch(\RuntimeException $e){$this->assertSame('nonpublic_dns',$e->getMessage());}
|
||||
}
|
||||
$t->answers=[['ip'=>'93.184.216.34']];$this->assertSame(['cashier.example.invalid','93.184.216.34'],$t->check());
|
||||
}
|
||||
public function test_policy_upgrade_unlocks_next_slot_without_duplicate_same_slot_probe():void
|
||||
{
|
||||
$this->probe->outcomes=[['status'=>'review_required','reason'=>'unapproved_host']];$this->runMonitor();$s=$this->state();$s['channels']['channel1']['policy']=hash('sha256',json_encode(config('payment_health.allowed_hosts')));file_put_contents($this->dir.'/state.json',json_encode($s));
|
||||
|
||||
Reference in new issue
Block a user