Skip to content

Commit 8d1179e

Browse files
authored
Apollo Server 2 depends on `subscriptions-transport-ws` for a superficial implementation of GraphQL subscription support. (Apollo Server 3.0.0 will not have built-in subscription support.) This unmaintained package depended on `ws` v5. All releases of v5 `ws` have a server DOS vulnerability: https://www.npmjs.com/advisories/1748 This change: - Removes the direct dependency on `ws` from `apollo-server-core`. This dependency was only used for types, so its imports have been changed to `import type` which pulls from `@types/ws`. - Updates the `subscriptions-transport-ws` dependency in `apollo-server-core` and `apollo-server-express` to the newly-released 0.9.19, which allows for `ws` v6 and v7. This means that via appropriate `npm` installations, you can install one of the non-vulnerable versions (6.2.2+ or 7.4.6+). Note that there are backwards incompatible changes in ws v6 and v7; see https://github.com/websockets/ws/releases/tag/6.0.0 and https://github.com/websockets/ws/releases/tag/7.0.0 for details. - Does some other small upgrades of ws-related packages. Note that the best way to protect yourself from this vulnerability is to avoid using the unmaintained `subscriptions-transport-ws` entirely by passing `subscriptions: false` to `new ApolloServer` and (if you do need to use subscriptions) using a maintained GraphQL subscription server such as `graphql-ws`.
1 parent 3e81b39 commit 8d1179e

File tree

7 files changed

+19
-33
lines changed

7 files changed

+19
-33
lines changed

package-lock.json

+10-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"@types/test-listen": "1.1.0",
9393
"@types/type-is": "1.6.3",
9494
"@types/uuid": "8.3.0",
95-
"@types/ws": "7.4.2",
95+
"@types/ws": "7.4.4",
9696
"apollo-fetch": "0.7.0",
9797
"apollo-link": "1.2.14",
9898
"apollo-link-http": "1.5.17",
@@ -128,7 +128,7 @@
128128
"qs-middleware": "1.0.3",
129129
"request": "2.88.2",
130130
"request-promise": "4.2.6",
131-
"subscriptions-transport-ws": "0.9.18",
131+
"subscriptions-transport-ws": "0.9.19",
132132
"supertest": "6.1.3",
133133
"test-listen": "1.1.0",
134134
"ts-jest": "26.5.6",

packages/apollo-server-core/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@
4848
"loglevel": "^1.6.7",
4949
"lru-cache": "^6.0.0",
5050
"sha.js": "^2.4.11",
51-
"subscriptions-transport-ws": "^0.9.11",
52-
"uuid": "^8.0.0",
53-
"ws": "^6.0.0"
51+
"subscriptions-transport-ws": "^0.9.19",
52+
"uuid": "^8.0.0"
5453
},
5554
"peerDependencies": {
5655
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"

packages/apollo-server-core/src/ApolloServer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import {
3434
} from 'apollo-server-plugin-base';
3535
import runtimeSupportsUploads from './utils/runtimeSupportsUploads';
3636

37-
import {
37+
import type {
3838
SubscriptionServer,
3939
ExecutionParams,
4040
} from 'subscriptions-transport-ws';
4141

42-
import WebSocket from 'ws';
42+
import type WebSocket from 'ws';
4343

4444
import { formatApolloErrors } from 'apollo-server-errors';
4545
import { GraphQLServerOptions, PersistedQueryOptions } from './graphqlOptions';

packages/apollo-server-core/src/types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414
ApolloConfigInput,
1515
} from 'apollo-server-types';
1616
import { ConnectionContext } from 'subscriptions-transport-ws';
17-
// The types for `ws` use `export = WebSocket`, so we'll use the
18-
// matching `import =` to bring in its sole export.
19-
import WebSocket = require('ws');
17+
import type WebSocket from 'ws';
2018
import { GraphQLExtension } from 'graphql-extensions';
2119
export { GraphQLExtension } from 'graphql-extensions';
2220

packages/apollo-server-express/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"graphql-subscriptions": "^1.0.0",
4343
"graphql-tools": "^4.0.8",
4444
"parseurl": "^1.3.2",
45-
"subscriptions-transport-ws": "^0.9.16",
45+
"subscriptions-transport-ws": "^0.9.19",
4646
"type-is": "^1.6.16"
4747
},
4848
"devDependencies": {

packages/apollo-server-express/src/ApolloServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Context,
1616
Config,
1717
} from 'apollo-server-core';
18-
import { ExecutionParams } from 'subscriptions-transport-ws';
18+
import type { ExecutionParams } from 'subscriptions-transport-ws';
1919
import accepts from 'accepts';
2020
import typeis from 'type-is';
2121
import { graphqlExpress } from './expressApollo';

0 commit comments

Comments
 (0)