-
Notifications
You must be signed in to change notification settings - Fork 89
Do not include access token in cache key when fetching zip archives #363
Conversation
@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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some requests inline
Thanks, @slimsag. I left |
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: Lines 27 to 38 in 8e668e2
|
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.fix
https://github.com/sourcegraph/sourcegraph/issues/1940cc @beyang just FYI, no action necessary