google / google/inverting-proxy

agent: Error out if an agent request to the proxy results in a redirect that changes the request method

Open
#20 1 comment 0 reactions 0 assignees View on GitHub
agent
Dominant language
Go
Stars
276
Forks
85
PR merge metrics
No merged PRs in 30d

Description

Currently, if the agent is created with proxy URL that results in redirects, then the requests to list and read pending requests will work, but any attempts to post back the response will fail.

This is because the response is sent to the proxy with a POST request, but the redirect will cause the request method to change from POST to GET.

This is especially problematic because it is silently done. The agent thinks it is sending a POST but the proxy thinks it is getting a GET, and neither side logs anything about this change.

Ideally, we would not change the method on a redirect, but at the very least we should detect if the method has changed and report an error if that happens.

It looks like we can implement the detect-and-error approach by defining a non-nil CheckRedirect field in our [http.Client struct](https://golang.org/pkg/net/http/#Client). We can define one that compares the method of the new request against the method of the old request(s), and return an error if they do not match.

We would need to define that field on the client used for sending requests to the proxy, which is defined [here](https://github.com/google/inverting-proxy/blob/c0dd3055c65c537e6a1c8c3c8fa587338e42b90e/agent/agent.go#L226)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.