Authenticate plugin routes (#2720)

This commit is contained in:
Asher 2021-02-12 14:56:39 -06:00 committed by GitHub
parent 97c1399401
commit 619934dc29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -6,7 +6,7 @@ import * as semver from "semver"
import * as pluginapi from "../../typings/pluginapi" import * as pluginapi from "../../typings/pluginapi"
import { HttpCode, HttpError } from "../common/http" import { HttpCode, HttpError } from "../common/http"
import { version } from "./constants" import { version } from "./constants"
import { replaceTemplates } from "./http" import { ensureAuthenticated, replaceTemplates } from "./http"
import { proxy } from "./proxy" import { proxy } from "./proxy"
import * as util from "./util" import * as util from "./util"
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter" import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
@ -122,10 +122,10 @@ export class PluginAPI {
public mount(r: express.Router, wr: express.Router): void { public mount(r: express.Router, wr: express.Router): void {
for (const [, p] of this.plugins) { for (const [, p] of this.plugins) {
if (p.router) { if (p.router) {
r.use(`${p.routerPath}`, p.router()) r.use(`${p.routerPath}`, ensureAuthenticated, p.router())
} }
if (p.wsRouter) { if (p.wsRouter) {
wr.use(`${p.routerPath}`, (p.wsRouter() as WebsocketRouter).router) wr.use(`${p.routerPath}`, ensureAuthenticated, (p.wsRouter() as WebsocketRouter).router)
} }
} }
} }

View File

@ -12,7 +12,7 @@ import { plural } from "../../common/util"
import { AuthType, DefaultedArgs } from "../cli" import { AuthType, DefaultedArgs } from "../cli"
import { rootPath } from "../constants" import { rootPath } from "../constants"
import { Heart } from "../heart" import { Heart } from "../heart"
import { redirect, replaceTemplates } from "../http" import { ensureAuthenticated, redirect, replaceTemplates } from "../http"
import { PluginAPI } from "../plugin" import { PluginAPI } from "../plugin"
import { getMediaMime, paths } from "../util" import { getMediaMime, paths } from "../util"
import { wrapper } from "../wrapper" import { wrapper } from "../wrapper"
@ -119,7 +119,7 @@ export const register = async (
const pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir) const pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir)
await pluginApi.loadPlugins() await pluginApi.loadPlugins()
pluginApi.mount(app, wsApp) pluginApi.mount(app, wsApp)
app.use("/api/applications", apps.router(pluginApi)) app.use("/api/applications", ensureAuthenticated, apps.router(pluginApi))
wrapper.onDispose(() => pluginApi.dispose()) wrapper.onDispose(() => pluginApi.dispose())
} }