Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

feat: support running extensions on private code without a private Sourcegraph instance #249

Merged
merged 5 commits into from
Oct 18, 2018

Conversation

chrismwendt
Copy link

Motivation This adds support for running extensions (e.g. Codecov) on private code even when the repository does not exist on the Sourcegraph instance. Doing so will resolve this issue: https://github.com/sourcegraph/browser-extensions/issues/234#issuecomment-430429015

Problem The browser extension must not let arbitrary GraphQL requests through to the Sourcegraph instance (which could be Sourcegraph.com) because they might contain private info (such as repo names), but some GraphQL requests are necessary to run extensions at all (e.g. fetching the extension manifests).

Implementation I've marked some GraphQL requests as safe by passing in requestMightContainPrivateInfo: false (defaults to true to keep old behavior for unmarked requests). The browser extension will allow those requests to be sent to the Sourcegraph instance. I also blocked queryLSP when sent from a private repo to Sourcegraph.com.

Reviewers The main file to review is src/shared/backend/extensions.ts. If you want to review the rest, I'd recommend reviewing commit-by-commit.

  • @ijsnow I'd like your 👀 on "refactor: avoid a network request while resolving the revision"
  • @sqs I'd like your input on the interaction between e-c-c and the browser extension in "feat: allow GraphQL requests that are known to not contain private info" and "feat: block queryLSP from a private repo to Sourcegraph.com" and whether or not this approach makes sense

Testing

  • git checkout allow-known-safe-gql-requests
  • yarn ; yarn run dev
  • Make sure one language extension (e.g. Go) and one other extension (e.g. token-highlights) have the following behavior in these scenarios:
    • Private repository that doesn't exist on a private Sourcegraph instance: token-highlights should work, Go should not (also, Go should not spam you with 404s in the hover tooltips)
    • Private repository that exists on a private Sourcegraph instance: both should work
    • Private repository that doesn't exist on Sourcegraph.com: token-highlights should work, Go should not (also, Go should not send ANY requests to Sourcegraph.com - you must check the background script's Network tab to confirm)
  • Public repos should work as usual (check both the content script and background script for errors you haven't seen before)

Depends on sourcegraph/sourcegraph-langserver-http#8
Depends on sourcegraph/extensions-client-common#57

Copy link
Member

@sqs sqs left a comment

Choose a reason for hiding this comment

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

@sqs I'd like your input on the interaction between e-c-c and the browser extension in "feat: allow GraphQL requests that are known to not contain private info" and "feat: block queryLSP from a private repo to Sourcegraph.com" and whether or not this approach makes sense

Makes sense to me. 👍

src/shared/util/dom.tsx Outdated Show resolved Hide resolved
src/shared/util/dom.tsx Outdated Show resolved Hide resolved
src/shared/util/dom.tsx Outdated Show resolved Hide resolved
src/shared/util/dom.tsx Outdated Show resolved Hide resolved
src/shared/util/dom.tsx Outdated Show resolved Hide resolved
Copy link

@ijsnow ijsnow left a comment

Choose a reason for hiding this comment

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

Overall nice work. I've got some suggestions/requests in the commit you asked me to review. The changes to request logic will conflict with changes I've made in my auth token PR. The changes look nice but unnecessary for the changes intended in this PR. Could we break that out separately so we can easily merge our PRs and then get those changes in afterwards?

src/libs/github/file_info.ts Outdated Show resolved Hide resolved
)
)
)
}
const commitID = commitIDFromPermalink({
Copy link

Choose a reason for hiding this comment

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

I purposefully kept DOM stuff outside of this file. Could you move this into scrape? Why is this needed if we get the rev from getFilePageInfo anyways?

Copy link
Author

Choose a reason for hiding this comment

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

Moved to scrape. getFilePageInfo doesn't resolve to a commit ID, does it? It looks like it only gives you the revision (i.e. it could be a ref like master rather than a commit ID).

src/libs/gitlab/file_info.ts Outdated Show resolved Hide resolved
src/libs/gitlab/file_info.ts Outdated Show resolved Hide resolved
src/libs/github/file_info.ts Outdated Show resolved Hide resolved
src/libs/gitlab/file_info.ts Outdated Show resolved Hide resolved
src/shared/backend/graphql.tsx Outdated Show resolved Hide resolved
@chrismwendt
Copy link
Author

chrismwendt commented Oct 18, 2018

Thanks, @ijsnow, I accepted all of your suggestions except the .href one ✨

The changes look nice but unnecessary for the changes intended in this PR. Could we break that out separately so we can easily merge our PRs and then get those changes in afterwards?

Mind if I try resolving the conflicts? No conflict is too difficult to resolve when equipped with the almighty diffme 🔨

@chrismwendt
Copy link
Author

I resolved the conflicts in src/shared/backend/graphql.tsx and src/shared/backend/server.ts (there didn't appear to be any fundamental conflicts, just some code shuffling).

Copy link

@ijsnow ijsnow left a comment

Choose a reason for hiding this comment

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

👍

@chrismwendt chrismwendt merged commit 022124a into master Oct 18, 2018
@chrismwendt chrismwendt deleted the allow-known-safe-gql-requests branch October 18, 2018 18:51
@sourcegraph-bot
Copy link

🎉 This PR is included in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

None yet

4 participants