Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2809245

Browse files
committedMar 7, 2025
Remove long-unused internal plugin system
We are trying to update Express to fix a vulnerability. We would have to update the plugins as well, but since we are no longer using the plugin system, we can just delete it instead.
1 parent 949aed1 commit 2809245

23 files changed

+32
-1032
lines changed
 

‎ci/build/build-release.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ bundle_code_server() {
4444
rsync src/browser/pages/*.css "$RELEASE_PATH/src/browser/pages"
4545
rsync src/browser/robots.txt "$RELEASE_PATH/src/browser"
4646

47-
# Add typings for plugins
48-
mkdir -p "$RELEASE_PATH/typings"
49-
rsync typings/pluginapi.d.ts "$RELEASE_PATH/typings"
50-
5147
# Adds the commit to package.json
5248
jq --slurp '(.[0] | del(.scripts,.jest,.devDependencies)) * .[1]' package.json <(
5349
cat << EOF

‎ci/dev/test-integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ main() {
3333
exit 1
3434
fi
3535

36-
CODE_SERVER_PATH="$path" CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --coverage=false --testRegex "./test/integration" --testPathIgnorePatterns "./test/integration/fixtures"
36+
CODE_SERVER_PATH="$path" ./test/node_modules/.bin/jest "$@" --coverage=false --testRegex "./test/integration" --testPathIgnorePatterns "./test/integration/fixtures"
3737
}
3838

3939
main "$@"

‎ci/dev/test-unit.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ main() {
66

77
source ./ci/lib.sh
88

9-
echo "Building test plugin"
10-
pushd test/unit/node/test-plugin
11-
make -s out/index.js
12-
popd
13-
149
# We must keep jest in a sub-directory. See ../../test/package.json for more
1510
# information. We must also run it from the root otherwise coverage will not
1611
# include our source files.
17-
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --testRegex "./test/unit/.*ts" --testPathIgnorePatterns "./test/unit/node/test-plugin"
12+
./test/node_modules/.bin/jest "$@" --testRegex "./test/unit/.*ts"
1813
}
1914

2015
main "$@"

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"publish:docker": "./ci/steps/docker-buildx-push.sh",
3131
"fmt": "npm run prettier && ./ci/dev/doctoc.sh",
3232
"lint:scripts": "./ci/dev/lint-scripts.sh",
33-
"lint:ts": "eslint --max-warnings=0 --fix $(git ls-files '*.ts' '*.js' | grep -v 'lib/vscode' | grep -v test-plugin)",
33+
"lint:ts": "eslint --max-warnings=0 --fix $(git ls-files '*.ts' '*.js' | grep -v 'lib/vscode')",
3434
"test": "echo 'Run npm run test:unit or npm run test:e2e' && exit 1",
3535
"watch": "VSCODE_DEV=1 VSCODE_IPC_HOOK_CLI= NODE_OPTIONS='--max_old_space_size=32384 --trace-warnings' ts-node ./ci/dev/watch.ts",
3636
"icons": "./ci/dev/gen_icons.sh"

‎src/node/plugin.ts

Lines changed: 0 additions & 302 deletions
This file was deleted.

‎src/node/routes/apps.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/node/routes/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { logger } from "@coder/logger"
22
import express from "express"
33
import { promises as fs } from "fs"
44
import path from "path"
5-
import { WebsocketRequest } from "../../../typings/pluginapi"
65
import { HttpCode } from "../../common/http"
6+
import type { WebsocketRequest } from "../wsRouter"
77
import { rootPath } from "../constants"
88
import { replaceTemplates } from "../http"
99
import { escapeHtml, getMediaMime } from "../util"

‎src/node/routes/index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import * as express from "express"
44
import { promises as fs } from "fs"
55
import * as path from "path"
66
import * as tls from "tls"
7-
import * as pluginapi from "../../../typings/pluginapi"
87
import { Disposable } from "../../common/emitter"
98
import { HttpCode, HttpError } from "../../common/http"
109
import { plural } from "../../common/util"
1110
import { App } from "../app"
1211
import { AuthType, DefaultedArgs } from "../cli"
1312
import { commit, rootPath } from "../constants"
1413
import { Heart } from "../heart"
15-
import { ensureAuthenticated, redirect } from "../http"
16-
import { PluginAPI } from "../plugin"
14+
import { redirect } from "../http"
1715
import { CoderSettings, SettingsProvider } from "../settings"
1816
import { UpdateProvider } from "../update"
17+
import type { WebsocketRequest } from "../wsRouter"
1918
import { getMediaMime, paths } from "../util"
20-
import * as apps from "./apps"
2119
import * as domainProxy from "./domainProxy"
2220
import { errorHandler, wsErrorHandler } from "./errors"
2321
import * as health from "./health"
@@ -113,7 +111,7 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
113111
await pathProxy.proxy(req, res)
114112
})
115113
app.wsRouter.get("/proxy/:port/:path(.*)?", async (req) => {
116-
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest)
114+
await pathProxy.wsProxy(req as WebsocketRequest)
117115
})
118116
// These two routes pass through the path directly.
119117
// So the proxied app must be aware it is running
@@ -125,21 +123,12 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
125123
})
126124
})
127125
app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => {
128-
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, {
126+
await pathProxy.wsProxy(req as WebsocketRequest, {
129127
passthroughPath: true,
130128
proxyBasePath: args["abs-proxy-base-path"],
131129
})
132130
})
133131

134-
let pluginApi: PluginAPI
135-
if (!process.env.CS_DISABLE_PLUGINS) {
136-
const workingDir = args._ && args._.length > 0 ? path.resolve(args._[args._.length - 1]) : undefined
137-
pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir)
138-
await pluginApi.loadPlugins()
139-
pluginApi.mount(app.router, app.wsRouter)
140-
app.router.use("/api/applications", ensureAuthenticated, apps.router(pluginApi))
141-
}
142-
143132
app.router.use(express.json())
144133
app.router.use(express.urlencoded({ extended: true }))
145134

@@ -172,7 +161,9 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
172161

173162
app.router.use("/update", update.router)
174163

175-
// Note that the root route is replaced in Coder Enterprise by the plugin API.
164+
// For historic reasons we also load at /vscode because the root was replaced
165+
// by a plugin in v1 of Coder. The plugin system (which was for internal use
166+
// only) has been removed, but leave the additional route for now.
176167
for (const routePrefix of ["/vscode", "/"]) {
177168
app.router.use(routePrefix, vscode.router)
178169
app.wsRouter.use(routePrefix, vscode.wsRouter.router)
@@ -187,7 +178,6 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
187178

188179
return () => {
189180
heart.dispose()
190-
pluginApi?.dispose()
191181
vscode.dispose()
192182
}
193183
}

‎src/node/routes/pathProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Request, Response } from "express"
22
import * as path from "path"
3-
import * as pluginapi from "../../../typings/pluginapi"
43
import { HttpCode, HttpError } from "../../common/http"
54
import { ensureProxyEnabled, authenticated, ensureAuthenticated, ensureOrigin, redirect, self } from "../http"
65
import { proxy as _proxy } from "../proxy"
6+
import type { WebsocketRequest } from "../wsRouter"
77

88
const getProxyTarget = (
99
req: Request,
@@ -49,7 +49,7 @@ export async function proxy(
4949
}
5050

5151
export async function wsProxy(
52-
req: pluginapi.WebsocketRequest,
52+
req: WebsocketRequest,
5353
opts?: {
5454
passthroughPath?: boolean
5555
proxyBasePath?: string

‎src/node/routes/vscode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import * as http from "http"
66
import * as net from "net"
77
import * as path from "path"
88
import * as os from "os"
9-
import { WebsocketRequest } from "../../../typings/pluginapi"
109
import { logError } from "../../common/util"
1110
import { CodeArgs, toCodeArgs } from "../cli"
1211
import { isDevMode, vsRootPath } from "../constants"
1312
import { authenticated, ensureAuthenticated, ensureOrigin, redirect, replaceTemplates, self } from "../http"
1413
import { SocketProxyProvider } from "../socket"
1514
import { isFile } from "../util"
16-
import { Router as WsRouter } from "../wsRouter"
15+
import { type WebsocketRequest, Router as WsRouter } from "../wsRouter"
1716

1817
export const router = express.Router()
1918

‎src/node/wsRouter.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import * as express from "express"
22
import * as expressCore from "express-serve-static-core"
33
import * as http from "http"
4+
import * as stream from "stream"
45
import Websocket from "ws"
5-
import * as pluginapi from "../../typings/pluginapi"
6+
7+
export interface WebsocketRequest extends express.Request {
8+
ws: stream.Duplex
9+
head: Buffer
10+
}
11+
12+
interface InternalWebsocketRequest extends WebsocketRequest {
13+
_ws_handled: boolean
14+
}
615

716
export const handleUpgrade = (app: express.Express, server: http.Server): void => {
817
server.on("upgrade", (req, socket, head) => {
@@ -22,9 +31,11 @@ export const handleUpgrade = (app: express.Express, server: http.Server): void =
2231
})
2332
}
2433

25-
interface InternalWebsocketRequest extends pluginapi.WebsocketRequest {
26-
_ws_handled: boolean
27-
}
34+
export type WebSocketHandler = (
35+
req: WebsocketRequest,
36+
res: express.Response,
37+
next: express.NextFunction,
38+
) => void | Promise<void>
2839

2940
export class WebsocketRouter {
3041
public readonly router = express.Router()
@@ -36,13 +47,13 @@ export class WebsocketRouter {
3647
* If the origin header exists it must match the host or the connection will
3748
* be prevented.
3849
*/
39-
public ws(route: expressCore.PathParams, ...handlers: pluginapi.WebSocketHandler[]): void {
50+
public ws(route: expressCore.PathParams, ...handlers: WebSocketHandler[]): void {
4051
this.router.get(
4152
route,
4253
...handlers.map((handler) => {
4354
const wrapped: express.Handler = (req, res, next) => {
4455
;(req as InternalWebsocketRequest)._ws_handled = true
45-
return handler(req as pluginapi.WebsocketRequest, res, next)
56+
return handler(req as WebsocketRequest, res, next)
4657
}
4758
return wrapped
4859
}),

‎test/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"extends": "../tsconfig.json",
3-
"include": ["./**/*.ts"],
4-
"exclude": ["./unit/node/test-plugin"]
3+
"include": ["./**/*.ts"]
54
}

‎test/unit/node/plugin.test.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

‎test/unit/node/test-plugin/.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎test/unit/node/test-plugin/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎test/unit/node/test-plugin/Makefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎test/unit/node/test-plugin/package-lock.json

Lines changed: 0 additions & 90 deletions
This file was deleted.

‎test/unit/node/test-plugin/package.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎test/unit/node/test-plugin/public/icon.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎test/unit/node/test-plugin/public/index.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎test/unit/node/test-plugin/src/index.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎test/unit/node/test-plugin/tsconfig.json

Lines changed: 0 additions & 71 deletions
This file was deleted.

‎typings/pluginapi.d.ts

Lines changed: 0 additions & 297 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.