douya1855 2016-02-10 16:42
浏览 56
已采纳

url在wp_safe_remote_get上无效

I develop an application using the woocommerce v3 API.

I want push an image by remote_url.

my url : http://tshirt-previewer.internal.teezily.com/media/W1siZiIsIjIwMTUvMTAvMjgvMTQvNTAvMzMvNGQ0NmVhYzAtYmVlNC00Y2IzLTlkN2QtZDM5ZmJlNzFmMWM5L0dJNjQwMDBfZnJvbnQucG5nIl0sWyJwIiwicHJldmlld3MiLDIwLCJyb3lhbCBibHVlIix7InBvc2l0aW9uX3giOjM2LCJwb3NpdGlvbl95IjoxLCJ3aWR0aCI6NjIsImhlaWdodCI6NjIsImRlc2lnbl91cmwiOiJodHRwczovL3RlZXppbHktcGx1cy5zMy5hbWF6b25hd3MuY29tL3VwbG9hZHMvZGVzaWduL3BpY3R1cmUvMzM3Ny9pbWFnZS0xMjAweDE2MDAuanBnIn1dXQ/GI64000_front.png?sha=989266d5133de145

But I can't upload it to Woocommerce by the Product API update

I found in the code the issue the image is downloaded by wp_safe_remote_get from Wordpress. But this methode think my URL is not safe.

Why is not safe ? Can i add some whitlist system to avoid considere this URL like unsafe ?

  • 写回答

3条回答 默认 最新

  • dousha7645 2016-03-16 13:08
    关注

    The Wordpress code seems to do a same-host check on urls that are fetched using wp_safe_remote_get().

    Here's the source: https://github.com/WordPress/WordPress/blob/c73a812109e1a64ecf21b6a198f949c58d1f2674/wp-includes/http.php

    The significant part is the wp_http_validate_url function, and in particular lines 524-530, which are here:

    $parsed_home = @parse_url( get_option( 'home' ) );
    if ( isset( $parsed_home['host'] ) ) { 
        $same_host = ( strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ) || 'localhost' === strtolower( $parsed_url['host'] ) );
    } else {
        $same_host = false;
    }
    

    If $same_host is false, the method treats the url as not safe.

    There's no whitelist that I can see. You'd probably need to edit the code to use wp_remote_get() if you want to avoid the problem.

    UPDATE: the preceding argument is wrong. The code returns the url even if the host is not the same as long as the port is normal.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi