ActivityPub-federated video streaming platform using P2P directly in your web browser
Expire session and remove unsecure plugin
Chocobozzz0205bad3e733
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.tsindex d6f974ff56..d372d77738 100644--- a/server/core/initializers/constants.ts+++ b/server/core/initializers/constants.ts@@ -60,7 +60,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'// ----------------------------------------------------------------------------export const LAST_MIGRATION_VERSION = 1000+export const LAST_MIGRATION_VERSION = 1001// ---------------------------------------------------------------------------diff --git a/server/core/initializers/migrations/1001-invalidate-non-expired-oauth-tokens.ts b/server/core/initializers/migrations/1001-invalidate-non-expired-oauth-tokens.tsnew file mode 100644index 0000000000..5db2db1496--- /dev/null+++ b/server/core/initializers/migrations/1001-invalidate-non-expired-oauth-tokens.ts@@ -0,0 +1,29 @@+import * as Sequelize from 'sequelize'++async function up (utils: {+ transaction: Sequelize.Transaction+ queryInterface: Sequelize.QueryInterface+ sequelize: Sequelize.Sequelize+}): Promise<void> {+ const { transaction } = utils++ await utils.sequelize.query(+ `+ UPDATE "oAuthToken"+ SET+ "accessTokenExpiresAt" = NOW(),+ "refreshTokenExpiresAt" = NOW()+ WHERE "accessTokenExpiresAt" > NOW() OR "refreshTokenExpiresAt" > NOW()+ `,+ { transaction }+ )+}++function down (options) {+ throw new Error('Not implemented.')+}++export {+ down,+ up+}diff --git a/server/core/lib/plugins/plugin-manager.ts b/server/core/lib/plugins/plugin-manager.tsindex 2d2a21f3b0..1c4cf3d347 100644--- a/server/core/lib/plugins/plugin-manager.ts+++ b/server/core/lib/plugins/plugin-manager.ts@@ -1,9 +1,3 @@-import express from 'express'-import { createReadStream, createWriteStream } from 'fs'-import { ensureDir, outputFile, readJSON } from 'fs-extra/esm'-import { Server } from 'http'-import { createRequire } from 'module'-import { basename, join } from 'path'import { getCompleteLocale, getHookType, internalRunHook } from '@peertube/peertube-core-utils'import {ClientScriptJSON,@@ -19,6 +13,12 @@ import {import { decachePlugin } from '@server/helpers/decache.js'import { ApplicationModel } from '@server/models/application/application.js'import { MOAuthTokenUser, MUser } from '@server/types/models/index.js'+import express from 'express'+import { createReadStream, createWriteStream } from 'fs'+import { ensureDir, outputFile, readJSON } from 'fs-extra/esm'+import { Server } from 'http'+import { createRequire } from 'module'+import { basename, join } from 'path'import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins.js'import { logger } from '../../helpers/logger.js'import { CONFIG } from '../../initializers/config.js'@@ -31,8 +31,8 @@ import {RegisterServerOptions} from '../../types/plugins/index.js'import { ClientHtml } from '../html/client-html.js'-import { RegisterHelpers } from './register-helpers.js'import { installNpmPlugin, installNpmPluginFromDisk, rebuildNativePlugins, removeNpmPlugin } from './package-manager.js'+import { RegisterHelpers } from './register-helpers.js'const require = createRequire(import.meta.url)@@ -68,6 +68,10 @@ type PluginLocalesTranslations = {[locale: string]: PluginTranslation}+const UNSECURE_PLUGINS_TO_REMOVE = [+ 'peertube-plugin-google-analytics-js'+]+export class PluginManager implements ServerHook {private static instance: PluginManager@@ -300,6 +304,15 @@ export class PluginManager implements ServerHook {this.sortHooksByPriority()}+ async removeUnsecurePluginsIfNeeded () {+ for (const npmName of UNSECURE_PLUGINS_TO_REMOVE) {+ const plugin = await PluginModel.loadByNpmName(npmName)+ if (!plugin || plugin.uninstalled === true) continue++ await this.uninstall({ npmName })+ }+ }+// Don't need the plugin type since themes cannot register server codeasync unregister (npmName: string) {logger.info('Unregister plugin %s.', npmName)