Skip to content

Conversation

@akashshinde
Copy link
Contributor

@akashshinde akashshinde commented Jul 21, 2020

This PR provides a way to delete unwated headers from proxy response.

Proxy.Config already has a field(HeaderBlacklist) to blacklist/filter headers, but It is not currently used anywhere. ref:

HeaderBlacklist []string

This PR deletes headers provided in the HeaderBlacklist

  • Added Unit test

Copy link
Member

@jhadvig jhadvig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: akashshinde, jhadvig
To complete the pull request process, please assign spadgett
You can assign the PR to them by writing /assign @spadgett in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 21, 2020
reverseProxy.FlushInterval = time.Millisecond * 100
reverseProxy.Transport = transport
reverseProxy.ModifyResponse = filterHeaders
reverseProxy.ModifyResponse = func(r *http.Response) error {
Copy link
Member

@spadgett spadgett Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HeaderBlacklist is intended to remove request headers, not response headers.

@spadgett
Copy link
Member

/lgtm cancel

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 21, 2020
@spadgett
Copy link
Member

It looks like we have the request headers hard-coded here, so we're not sending anything we shouldn't.

https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/pkg/proxy/proxy.go#L88

Maybe we can remove the HeaderBlacklist in the proxy config?

@spadgett
Copy link
Member

@akashshinde Do you have a need to filter additional response headers or did you just notice it was unused?

@akashshinde
Copy link
Contributor Author

akashshinde commented Jul 21, 2020

@spadgett
We have a use case where proxied url copies all headers along with response which is correct but origin url/proxied url copies Cache-Control header which tells browser to cache the response.
Therefore when UI makes second request to same proxy url, browser uses the cached response instead of the one sent by server.
So we want a way to filter out that header.
If we can't use HeaderBlacklist then we need to find alternative way to tackle this issue.
Let me know what do you suggest.

@akashshinde
Copy link
Contributor Author

It looks like we have the request headers hard-coded here, so we're not sending anything we shouldn't.

https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/pkg/proxy/proxy.go#L88

Maybe we can remove the HeaderBlacklist in the proxy config?

Please check https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/cmd/bridge/main.go#L328
We pass Cookie and X-CSRFToken here in HeaderBlacklist (same headers we've hard coded in https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/pkg/proxy/proxy.go#L88)

So I'm guessing we should remove hard coded headers and keep the field HeaderBlacklist, This way we will have control over response headers.

@spadgett
Copy link
Member

Please check https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/cmd/bridge/main.go#L328
We pass Cookie and X-CSRFToken here in HeaderBlacklist (same headers we've hard coded in https://github.com/spadgett/console/blob/bc9a54150429b081278e2024fb6cb769f5ca3a86/pkg/proxy/proxy.go#L88)

Right these are definitely request headers, not response headers. X-CSRFToken comes from the console client, and Cookie is a request header.

So I'm guessing we should remove hard coded headers and keep the field HeaderBlacklist, This way we will have control over response headers.

But this was intended to filter request headers. I would rather have the hard-coded list to be honest since we should never send these for security reasons. It would be too easy to forget to set that on one of our proxies.

Do you have a specific need to filter a different response header?

@akashshinde
Copy link
Contributor Author

Do you have a specific need to filter a different response header?

this is the reason - #6044 (comment)
Let me know if I am not clear.

@spadgett
Copy link
Member

I'd make this ReponseHeaderDenylist and remove HeaderBlacklist from the config and the references in main.go.

@spadgett
Copy link
Member

The problem though is that removing Cache-Control is not enough. It leaves it up to the browser. You really want to replace it with another value.

@spadgett
Copy link
Member

Any chance of fixing the Cache-Control header in the upstream service if it shouldn't be cached?

@akashshinde
Copy link
Contributor Author

Any chance of fixing the Cache-Control header in the upstream service if it shouldn't be cached?

https://redhat-developer.github.io/redhat-helm-charts/index.yaml this is the URL we are serving through the proxy and it's being served through GitHub pages. I doubt If we could remove/configure http headers in GitHub service @sbose78 wdyt?
Github page adds two headers which are causing this issue.

Cache-Control: 600
Etag: unique-id

The problem though is that removing Cache-Control is not enough. It leaves it up to the browser. You really want to replace it with another value.

Well I was thinking of replacing Cache-Control default value to no-cache, private, this would avoid caching in browser, But to modify the response headers we would need to add ModifyResponse func(r *http.Response) instead of HeaderBlacklist string[] in Config

Config struct would look like

type Config struct {
	ModifyHTTPProxyResponse func(r *http.Response)
	Endpoint        *url.URL
	TLSClientConfig *tls.Config
	Origin          string
}

@spadgett
Copy link
Member

@akashshinde If GitHub pages is setting a valid ETag on the response, why is the Cache-Control header a problem? You should get the cached version only when the ETag hasn't changed.

@akashshinde
Copy link
Contributor Author

akashshinde commented Jul 31, 2020

@spadgett we are no longer using proxy in #5933, therefore we can close this PR unless you have a reason to keep it open.

@sbose78
Copy link

sbose78 commented Jul 31, 2020

Yea, let's close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/backend Related to backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants