| @@ -14,8 +14,22 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | class SBPS_MAIN { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | + * 各種通知の送信元IP許可リスト(本番環境) | |
| 19 | + * | |
| 20 | + * @var array | |
| 21 | + */ | |
| 22 | + const ACTING_NOTICE_IPADDRS_PUBLIC = array( '61.215.213.20' ); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 各種通知の送信元IP許可リスト(テスト環境・接続支援サイト) | |
| 26 | + * | |
| 27 | + * @var array | |
| 28 | + */ | |
| 29 | + const ACTING_NOTICE_IPADDRS_TEST = array( '61.215.213.47' ); | |
| 30 | + | |
| 31 | + /** | |
| 18 | 32 | * 決済代行会社ID |
| 19 | 33 | * |
| 20 | 34 | * @var string |
| 21 | 35 | */ |
| @@ -528,8 +542,35 @@ | ||
| 528 | 542 | } |
| 529 | 543 | } |
| 530 | 544 | |
| 531 | 545 | /** |
| 546 | + * 各種通知の送信元IPを検証する | |
| 547 | + * | |
| 548 | + * 許可IP以外からのリクエストはエラーログを残して処理を終了する | |
| 549 | + * 入金状態を変更するサーバー間通知でのみ呼び出すこと | |
| 550 | + * | |
| 551 | + * @param array $data Notification data. | |
| 552 | + * @return void | |
| 553 | + */ | |
| 554 | + private function acting_notice_ip_guard( $data ) { | |
| 555 | + $acting_opts = $this->get_acting_settings(); | |
| 556 | + $allowed_ips = ( isset( $acting_opts['ope'] ) && 'public' === $acting_opts['ope'] ) ? self::ACTING_NOTICE_IPADDRS_PUBLIC : self::ACTING_NOTICE_IPADDRS_TEST; | |
| 557 | + $remote_addr = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? wp_unslash( $_SERVER['REMOTE_ADDR'] ) : ''; | |
| 558 | + if ( usces_acting_notice_ip_allowed( $remote_addr, $allowed_ips ) ) { | |
| 559 | + return; | |
| 560 | + } | |
| 561 | + $log = array( | |
| 562 | + 'acting' => $this->paymod_id, | |
| 563 | + 'key' => ( isset( $data['res_tracking_id'] ) ) ? $data['res_tracking_id'] : '', | |
| 564 | + 'result' => 'IP ADDRESS NOT ALLOWED: ' . $remote_addr, | |
| 565 | + 'data' => $data, | |
| 566 | + ); | |
| 567 | + usces_save_order_acting_error( $log ); | |
| 568 | + usces_log( $this->acting_name . ' notice denied ip : ' . $remote_addr, 'acting_transaction.log' ); | |
| 569 | + die( 'NG,ip address error' ); | |
| 570 | + } | |
| 571 | + | |
| 572 | + /** | |
| 532 | 573 | * 結果通知処理 |
| 533 | 574 | * usces_after_cart_instant |
| 534 | 575 | */ |
| 535 | 576 | public function acting_transaction() { |
| @@ -556,8 +597,9 @@ | ||
| 556 | 597 | $acting = substr( $acting_flg, 7 ); |
| 557 | 598 | $_GET['acting'] = $acting; |
| 558 | 599 | switch ( $data['res_result'] ) { |
| 559 | 600 | case 'OK': /* 決済処理OK */ |
| 601 | + $this->acting_notice_ip_guard( $data ); | |
| 560 | 602 | $order_id = $this->get_order_id( $data['res_tracking_id'] ); |
| 561 | 603 | if ( ! $order_id ) { |
| 562 | 604 | $res = $usces->order_processing( $data ); |
| 563 | 605 | if ( 'ordercompletion' === $res ) { |
| @@ -571,8 +613,9 @@ | ||
| 571 | 613 | die( 'OK,' ); |
| 572 | 614 | break; |
| 573 | 615 | |
| 574 | 616 | case 'PY': /* 入金結果通知 */ |
| 617 | + $this->acting_notice_ip_guard( $data ); | |
| 575 | 618 | $order_id = $this->get_order_id( $data['res_tracking_id'] ); |
| 576 | 619 | if ( ! $order_id ) { |
| 577 | 620 | // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error1 : ' . print_r( $data, true ), 'acting_transaction.log' ); |
| 578 | 621 | die( 'NG,order_id error' ); |
| @@ -603,8 +646,9 @@ | ||
| 603 | 646 | die( 'OK,' ); |
| 604 | 647 | break; |
| 605 | 648 | |
| 606 | 649 | case 'CN': /* 期限切通知 */ |
| 650 | + $this->acting_notice_ip_guard( $data ); | |
| 607 | 651 | $order_id = $this->get_order_id( $data['res_tracking_id'] ); |
| 608 | 652 | if ( ! $order_id ) { |
| 609 | 653 | // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error1 : ' . print_r( $data, true ), 'acting_transaction.log' ); |
| 610 | 654 | die( 'NG,order_id error' ); |