Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Do not include access token in cache key when fetching zip archives #363

Merged
merged 4 commits into from
Apr 5, 2019

Conversation

chrismwendt
Copy link
Contributor

Prior to this change, the cache key was the full URL, including whatever username:password was set (e.g. the Sourcegraph access token).

After this change, the cache key will be the URL but with empty username:password.

This will increase the probability of a cache hit because each repo@revision will be fetched once and used by any user.

A HEAD request is still made for each user x repo@revision pair to make sure the user has access to the repository contents.

cc @beyang just FYI, no action necessary

@chrismwendt
Copy link
Contributor Author

@slimsag I added you as a reviewer to help expedite the review of this change since it got bumped in priority today https://sourcegraph.slack.com/archives/C0C324C91/p1554427053097800?thread_ts=1554425326.073300&cid=C0C324C91

vfsutil/zip.go Outdated
@@ -22,24 +23,24 @@ import (

// NewZipVFS downloads a zip archive from a URL (or fetches from the local cache
// on disk) and returns a new VFS backed by that zip archive.
func NewZipVFS(ctx context.Context, url string, onFetchStart, onFetchFailed func(), evictOnClose bool) (*ArchiveFS, error) {
request, err := http.NewRequest("HEAD", url, nil)
func NewZipVFS(ctx context.Context, urlString string, onFetchStart, onFetchFailed func(), evictOnClose bool) (*ArchiveFS, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It's kind of weird to use urlString and urlStruct naming. I would leave url as-is and rename urlStruct to just u

Copy link
Contributor Author

@chrismwendt chrismwendt Apr 5, 2019

Choose a reason for hiding this comment

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

What do you suggest for naming now that the the url package name from "net/url" conflicts with the local variable url?

Copy link
Member

Choose a reason for hiding this comment

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

it won't conflict if you do my withoutAuth refactor suggested below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this?

func withoutAuth(urlString string) (string, error) {
	u, err := url.Parse(urlString)
...

Copy link
Member

@emidoots emidoots left a comment

Choose a reason for hiding this comment

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

some requests inline

@chrismwendt
Copy link
Contributor Author

Thanks, @slimsag. I left urlString because both u and url are used for other variables.

@felixfbecker
Copy link

If the cache key does not include the user/auth info, is there a way as user A I can possibly get data returned that was cached for user B, without being authorised to see that data?

@chrismwendt
Copy link
Contributor Author

If the cache key does not include the user/auth info, is there a way as user A I can possibly get data returned that was cached for user B, without being authorised to see that data?

go-langserver checks for permission before reading from the cache:

request, err := http.NewRequest("HEAD", url, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to construct a new request with URL %s", url)
}
setAuthFromNetrc(request)
response, err := ctxhttp.Do(ctx, nil, request)
if err != nil {
return nil, err
}
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch zip from %s (expected HTTP response code 200, but got %d)", url, response.StatusCode)
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants