Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
feat: mark safe GraphQL requests (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismwendt committed Oct 18, 2018
1 parent 2e70392 commit 01b5a49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/client/clientCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export function registerBuiltinClientCommands<S extends ConfigurationSubject, C
controller.registries.commands.registerCommand({
command: 'queryGraphQL',
run: (query: string, variables: { [name: string]: any }): Promise<any> =>
from(context.queryGraphQL(query, variables)).toPromise(),
// 🚨 SECURITY: The request might contain private info (such as
// repository names), so the `mightContainPrivateInfo` parameter
// is set to `true`. It is up to the client (e.g. browser
// extension) to check that parameter and prevent the request
// from being sent to Sourcegraph.com.
from(context.queryGraphQL(query, variables, true)).toPromise(),
})
)

Expand Down
5 changes: 4 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export interface Context<S extends ConfigurationSubject, C extends Settings> {
*
* @param request The GraphQL request (query or mutation)
* @param variables An object whose properties are GraphQL query name-value variable pairs
* @param mightContainPrivateInfo 🚨 SECURITY: Whether or not sending the GraphQL request to Sourcegraph.com
* could leak private information such as repository names.
* @return Observable that emits the result or an error if the HTTP request failed
*/
queryGraphQL(
request: string,
variables?: { [name: string]: any }
variables?: { [name: string]: any },
mightContainPrivateInfo?: boolean
): Subscribable<QueryResult<Pick<GQL.IQuery, 'extensionRegistry'>>>

/**
Expand Down
6 changes: 4 additions & 2 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class Controller<S extends ConfigurationSubject, C extends Settings> {
}
${registryExtensionFragment}
`[graphQLContent],
{ extensionID }
{ extensionID },
false
)
)
.pipe(
Expand Down Expand Up @@ -104,7 +105,8 @@ export class Controller<S extends ConfigurationSubject, C extends Settings> {
{
first: extensionIDs.length,
prioritizeExtensionIDs: extensionIDs,
}
},
false
)
).pipe(
map(({ data, errors }) => {
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/manager/ExtensionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ export class ExtensionsList<S extends ConfigurationSubject, C extends Settings>
{
...args,
prioritizeExtensionIDs: viewerExtensions.map(({ id }) => id),
} as GQL.IExtensionsOnExtensionRegistryArguments
} as GQL.IExtensionsOnExtensionRegistryArguments,
false
)
).pipe(
map(({ data, errors }) => {
Expand Down

0 comments on commit 01b5a49

Please sign in to comment.