Runtime error: invalid memory address or nil pointer dereference goroutine 953

I am using the docker image Package boringproxy-linux-amd64 · GitHub as boringproxy server and client.

In docker logs I can find the following problem:

Failed to create client. Ensure the server is running. URL: https://test.domain.com/api/clients/?client-name=app

First idea was, that the docker cannot access internet or the server. But when I check the server logs I find this:

2022/12/03 10:47:37 http: panic serving 172.18.0.5:50324: runtime error: invalid memory address or nil pointer dereference
goroutine 925 [running]:
net/http.(*conn).serve.func1()
	/usr/local/go/src/net/http/server.go:1802 +0xb9
panic({0x8a35a0, 0xce68b0})
	/usr/local/go/src/runtime/panic.go:1047 +0x266
github.com/boringproxy/boringproxy.(*Api).handleClients(0xc0003af4a0, {0x9d3380, 0xc00038c380}, 0xc0001d9e00)
	/build/api.go:267 +0x557
net/http.HandlerFunc.ServeHTTP(0xc000408b60, {0x9d3380, 0xc00038c380}, 0x5)
	/usr/local/go/src/net/http/server.go:2047 +0x2f
net/http.StripPrefix.func1({0x9d3380, 0xc00038c380}, 0xc0001d9d00)
	/usr/local/go/src/net/http/server.go:2090 +0x330
net/http.HandlerFunc.ServeHTTP(0x7f00b46d5ed8, {0x9d3380, 0xc00038c380}, 0x7f00b46cc108)
	/usr/local/go/src/net/http/server.go:2047 +0x2f
net/http.(*ServeMux).ServeHTTP(0x40d247, {0x9d3380, 0xc00038c380}, 0xc0001d9d00)
	/usr/local/go/src/net/http/server.go:2425 +0x149
github.com/boringproxy/boringproxy.(*Api).ServeHTTP(0x30, {0x9d3380, 0xc00038c380}, 0x10000c000287be0)
	/build/api.go:37 +0x27
net/http.StripPrefix.func1({0x9d3380, 0xc00038c380}, 0xc0001d9c00)
	/usr/local/go/src/net/http/server.go:2090 +0x330
net/http.HandlerFunc.ServeHTTP(0x91e539, {0x9d3380, 0xc00038c380}, 0xc0003af4a0)
	/usr/local/go/src/net/http/server.go:2047 +0x2f
github.com/boringproxy/boringproxy.Listen.func2({0x9d3380, 0xc00038c380}, 0xc0001d9c00)
	/build/boringproxy.go:290 +0x3df
net/http.HandlerFunc.ServeHTTP(0x0, {0x9d3380, 0xc00038c380}, 0x0)
	/usr/local/go/src/net/http/server.go:2047 +0x2f
net/http.(*ServeMux).ServeHTTP(0xc0003bc492, {0x9d3380, 0xc00038c380}, 0xc0001d9c00)
	/usr/local/go/src/net/http/server.go:2425 +0x149
net/http.serverHandler.ServeHTTP({0xc00024bec0}, {0x9d3380, 0xc00038c380}, 0xc0001d9c00)
	/usr/local/go/src/net/http/server.go:2879 +0x43b
net/http.(*conn).serve(0xc0003a6460, {0x9d56e0, 0xc0003af800})
	/usr/local/go/src/net/http/server.go:1930 +0xb08
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:3034 +0x4e8

I can reproduce it by just calling the url Welcome dragndropbuilder.com - BlueHost.com in browser.
When I change the parameter name “client-name” to something else I get the normal boringproxy respond “Missing client-name parameter”.

Hi @pellenbeck, sorry for the delay.

The docker image you linked to is a forked version of boringproxy, which is using an older version than the current master. Based on the error message, I believe the error is coming from this line:

https://github.com/WGrobler/boringproxy/blob/2b4b74dd76e13624f4cd4e4edf870a577e12ed02/api.go#L267,

which references a nil variable. This bug has been fixed in the master boringproxy builds, which you can access here: https://gemdrive.io/apps/delver/?drive=https://files.apitman.com&path=/public/boringproxy/master.

However, what triggers the bug is an invalid HTTP method (anything other than POST or DELETE). I’m not sure how that can be happening if you’re using the official client. My suspicion is that there is actually another service other than the boringproxy client trying to access /api/clients, using HTTP GET requests, which is triggering the errors you see in the logs. So you might want to double check that the client is able to access the server.

@anders who could update the used version of boringproxy in docker file?
I have no clue to do it, so need help :wink:

However, what triggers the bug is an invalid HTTP method (anything other than POST or DELETE). I’m not sure how that can be happening if you’re using the official client. My suspicion is that there is actually another service other than the boringproxy client trying to access /api/clients, using HTTP GET requests, which is triggering the errors you see in the logs. So you might want to double check that the client is able to access the server.

The same error is logged in case boringproxy client is accessing the target url or if I do it manually by browser. So I think only normal GET requests causing the error.

@anders tried to access the latest build, but the given url does not work:
https://gemdrive.io/apps/delver/?drive=https://files.apitman.com&path=/public/boringproxy/master
Is there a temp problem with your gemdrive?

Sorry about that @pellenbeck. Should be fixed now.

Also, I’ve just released v0.10.0, which includes everything in master up until now and can be downloaded directly from github.

@anders, thank you!

Just tried to build a new docker image based on Dockerfile on github:

root@server:~/docker/boringproxy/image# docker build -t boringproxy-local .
Sending build context to Docker daemon   2.56kB
Step 1/21 : FROM golang:1.17-alpine3.15 as builder
 ---> 675faa0f5534
Step 2/21 : LABEL boringproxy=builder
 ---> Using cache
 ---> 4a2eaeec8fbe
Step 3/21 : ARG VERSION
 ---> Using cache
 ---> bbdf067b23d6
Step 4/21 : ARG GOOS="linux"
 ---> Using cache
 ---> 146d664854cd
Step 5/21 : ARG GOARCH="amd64"
 ---> Using cache
 ---> a0fe5966f5a5
Step 6/21 : ARG BRANCH="master"
 ---> Using cache
 ---> e97db44ab2e8
Step 7/21 : ARG REPO="https://github.com/boringproxy/boringproxy.git"
 ---> Using cache
 ---> fd46093fb63b
Step 8/21 : ARG ORIGIN='local'
 ---> Using cache
 ---> 8b9d5f7571a8
Step 9/21 : WORKDIR /build
 ---> Using cache
 ---> ff54d4107fb2
Step 10/21 : RUN apk add git
 ---> Using cache
 ---> d19ec811ef97
Step 11/21 : RUN if [[ "ORIGIN" == 'remote' ]] ; then git clone --depth 1 --branch "${BRANCH}" ${REPO}; fi
 ---> Using cache
 ---> f5004971fa58
Step 12/21 : COPY go.* ./
COPY failed: no source files were specified

Do you know what the problem could be?

I’m not sure what the problem is. I just tried the following command and it worked for me:

sudo docker build -t boringproxy:latest .

Note that I personally don’t use the Docker image. The Dockerfile was contributed by someone else. So it’s very likely to be out of date or have other issues.