cloudflare-bp-go icon indicating copy to clipboard operation
cloudflare-bp-go copied to clipboard

Tests are failing, but works for me

Open apecollector opened this issue 2 years ago • 6 comments

I found this and am using it with success, but I did notice the tests are failing.

apecollector avatar Apr 05 '22 09:04 apecollector

@apecollector Cannot say the same. I just give it a shot, and it's not working :(

hcancelik avatar Sep 23 '23 13:09 hcancelik

I changed the credentials for my VPN accounts a while ago already, but never updated the secrets in all my github projects which caused the tests to fail.

Will check and update the tests if necessary.

DaRealFreak avatar Sep 24 '23 02:09 DaRealFreak

@DaRealFreak, maybe I'm not doing this right but here is my example code.

package main

import (
	"fmt"
	"github.com/DaRealFreak/cloudflare-bp-go"
	"net/http"
)

func main() {
	url := "https://www.lexusofpembrokepines.com/inventory/58ADZ1B12MU096560?type=U"

	client := &http.Client{}
	client.Transport = cloudflarebp.AddCloudFlareByPass(client.Transport)

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error making request:", err)
		return
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.Status)
}

hcancelik avatar Sep 24 '23 12:09 hcancelik

@hcancelik That site enforces a JS/non-interactive challenge for that link regardless of TLS configuration.

This is (at least so far) NOT intended to solve challenges provided by CloudFlare, only to prevent CloudFlare from directly displaying you a challenge on the first request.

The RoundTripper is still working. Try to request this URL https://www.lexusofpembrokepines.com/wp-content/cache/jellyfish-cache/new-vehicles-js.js?mt=1698335265 via the Go Roundtripper and then via curl.

You will see that the roundtripper gives 200 OK, but curl guarantees a 403 response

M41KL-N41TT avatar Oct 26 '23 17:10 M41KL-N41TT

@m41k1n4177 Thanks for the response.

I'm still getting 403 for that url. This is the code I have used.

Additionally, there is also no way for me to find out that javascript URL in advance so I'm not sure how this would help.

type MyRoundTripper struct {
	Transport http.RoundTripper
}

func (rt *MyRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	resp, err := rt.Transport.RoundTrip(req)
	if err != nil {
		return nil, err
	}
	
	fmt.Printf("Status Code: %d\n", resp.StatusCode)

	return resp, nil
}

func main() {
	url := "https://www.lexusofpembrokepines.com/wp-content/cache/jellyfish-cache/new-vehicles-js.js?mt=1698335265"

	client := &http.Client{
		Transport: &MyRoundTripper{Transport: http.DefaultTransport},
	}

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	_, err = client.Do(req)
	if err != nil {
		fmt.Println("Error making request:", err)
		return
	}
}

hcancelik avatar Nov 21 '23 09:11 hcancelik

I don't think you should use that exact link as it seems to have some cache-busting added, I think it may have been suffixed with ?mt=time() or something.

Also not sure this, the original repo supports use with http.DefaultTransport.

Readme:

Using the http.DefaultTransport will currently still fail, nil or empty &http.Transport works. Didn't have the time to check what exactly is different causing the CloudFlare validation to fail though.

M41KL-N41TT avatar Nov 22 '23 14:11 M41KL-N41TT